LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to store string elemts from visa read to array without delimiter

Solved!
Go to solution

Hello,

 

i am using a stm32f407vgt6 discovery board and the virtual comport to transmit 16 bytes of data from my µC to the pc.

The read buffer contains eg. 08EF FFFF 08F4 FFFF 08EA FFFF.

Now i want to seperate them bytewise and save the single bytes to an array, but there is no delimiter i can use. I tried to use spreadsheet to array, but this didn't worked.

 

Maybe you can tell me, how to make it work.

 

Thank you.

 

0 Kudos
Message 1 of 9
(2,956 Views)

@FaDen93 wrote:

Now i want to seperate them bytewise and save the single bytes to an array, but there is no delimiter i can use. I tried to use spreadsheet to array, but this didn't worked.


Of course not.  You are dealing with binary data.  Spreadsheet String implies ASCII formatted data.  So in order to get anything useful out of the data, we need to know the format of the data (ie what bytes mean what).

 

And a shameless plug: VIWeek 2020/Proper way to communicate over serial


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 9
(2,935 Views)

Hello,

 

thanks for your reply. The aim is to calculate the expansion of batterie cells. I use 12 bit ADCs to sample the data. So always 16 bit represent a strain gauges sensor value.

 

A string to byte array seems to work, but then I have to combine the bytes into words. Don't know if this is easier then other ways.

 

0 Kudos
Message 3 of 9
(2,924 Views)

@FaDen93 wrote:

I use 12 bit ADCs to sample the data. So always 16 bit represent a strain gauges sensor value.


So your microcontroller is just spitting out 16-bit data?  How would you know if you are aligned properly on your read?  For example, your microcontroller spits out "00FF 55AA".  These are 2 samples, right?  Now let's say you open up the port on the computer side and the first thing you read is "FF55".  This will happen because the port was opened after the first byte as sent, but before the second was received.  So you will be mixing two samples together and get complete garbage for data.  So you need to define a frame of data to ensure you are reading the data properly.  This frame is typically set up something like the following:

1. A sync byte.  This byte is typically 0x2, but I have seen all kinds of sync byte values.

2. A message ID and/or message length.  This will tell you how much data is in the frame of data and/or how to interpret the data.  Since you are just spitting out a constant 16-bit value, this could probably be omitted.

3. The data

4. A checksum or CRC.  This is a data validity check  If this fails, you either did not sync to the right byte (the sync byte could be in any other field) or there was an error in the transmission.  The simplest checksum is to just perform a U8 addition on the data (Add Array Values).

 

With that said, go watch the video from my shameless plug to see how to use this setup.  There is also a link to the example code in GitHub that you can use.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 9
(2,909 Views)

After re-thinking it, maybe you need to read 32bit chunks and make sure word #2 is FFFF.  If it's not, you're out of sync.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 9
(2,906 Views)

@FaDen93 wrote:

Hello,

 

i am using a stm32f407vgt6 discovery board and the virtual comport to transmit 16 bytes of data from my µC to the pc.

 

 


Who is writing the code running on the Discovery Board?

 

I am guessing it is you, so you should  add a delimiter or at least a Termination Character to the data you are sending.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 9
(2,880 Views)

Hello,

 

sorry for the late reply, i had to fix some bugs in my program first. Yes, i write the code for the µC myself. The problem by using a termination character is, that my readings can occur over the whole data range. The probability that I accidentally hit the termination character is very high then.

I decided to add a start byte (0x20) for sync and use a CRC to check if the recieved packet ist ok.

 

Now some more questions.

How do i implement to scan for the start byte

Is it still ok to use the VISA read function to read the data bytes? I saw some examples using the property node for this.

0 Kudos
Message 7 of 9
(2,814 Views)
Solution
Accepted by FaDen93

@FaDen93 wrote:

Now some more questions.

How do i implement to scan for the start byte

Is it still ok to use the VISA read function to read the data bytes? I saw some examples using the property node for this.


You read 1 byte at a time until you read the start byte.  Then you read the data and CRC and perform the CRC check.  If the check passed, you have valid data.  If it fails, throw it away.  Either way, go back to reading 1 byte until the start byte is read.

 

Here is a guide from my presentation I linked to above.  It is using a command byte as well, so you can remove that part.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 9
(2,793 Views)

Thank you very much. Now it's working perfectly.

0 Kudos
Message 9 of 9
(2,742 Views)