LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read in serial data with VISA and store in array

Hello,


I am very new to LabView, and I am trying to read in 12 bytes of serial data using the VISA resource and VISA read.  I would like to display the 12 bytes in an output array, where I can then also plot a specific portion of the 12 byte frame.  Could anyone point me to a good example like this?

 

I have attached what I have so far, but I am unsure how to display the 12 bytes in an array. Also, is my case statement correctly saying to read the data if 12 bytes are currently at the port?

Thanks for any assistance.

0 Kudos
Message 1 of 12
(2,039 Views)

@LKcire wrote:

Hello,

is my case statement correctly saying to read the data if 12 bytes are currently at the port?

Thanks for any assistance.


You forgot to attach your code, but in general if you are using "Bytes At Port", you are doing it wrong.

 

VI Week 2020/Proper way to communicate over serial

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 12
(2,036 Views)

OK so I was using Bytes At Port, so that is part of my problem... I guess I am still unsure how to add this data into an array so that I can manipulates specific bytes of the data once received.  I think my original code is now attached. 

0 Kudos
Message 3 of 12
(2,023 Views)

I'm glad to see my presentation is making the rounds...

 

Ok, the big issue here is how do you know you are properly aligned to your 12 bytes.  Do you have a definition of the message frame?  Based on the very limited information, I would assume you are dealing with raw/binary/hex message format.  With that being the case, the message frame should include a start byte and end with a checksum of some sort.  You use these to make sure you are properly aligned to a message frame.  Yes, please go watch my presentation to understand better.


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 12
(2,021 Views)

My message has a start byte 0x24 and ends with a 2 bytes CRC.  Thanks for the presentation.

0 Kudos
Message 5 of 12
(2,017 Views)

Hello,
I am trying to read in a serial data stream that is 12 bytes long, find the start byte (0x24) and once the start byte is found I would like to place the data into an array.  The attached code is what I have so far, but I am unsure how to continue reading the data and add it to the array once the start byte is found.  Any help would be appreciated.
Thanks

0 Kudos
Message 6 of 12
(2,007 Views)

Wire the VISA refnum and error cluster through the case structure and in the TRUE case make another read for the rest of the bytes, concatenate with the start byte and append to the array. Be aware that you will continuously allocate memory in that way - maybe you can give more info about your goal so we can propose a better method. You should also wire an empty array to the left shift register to initialize it so you will start with an empty array every time the VI is executed.

Lucian
CLA
0 Kudos
Message 7 of 12
(1,981 Views)

@LucianM wrote:

Wire the VISA refnum and error cluster through the case structure and in the TRUE case make another read for the rest of the bytes, concatenate with the start byte and append to the array. Be aware that you will continuously allocate memory in that way - maybe you can give more info about your goal so we can propose a better method. You should also wire an empty array to the left shift register to initialize it so you will start with an empty array every time the VI is executed.


You can look for the start byte and then read 11 more bytes (I'm assuming that 12 bytes included the start byte) since you know how long the message is.

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 8 of 12
(1,960 Views)

Yes, this is what I would like to do.  I just don't know what to use in order to accomplish this.  I have updated my code where I added another read after the start byte read and tried to include a counter but I'm not sure I'm doing that right.  Attached is the latest, but I am not correctly reading my packet.

0 Kudos
Message 9 of 12
(1,919 Views)

@LKcire wrote:

Yes, this is what I would like to do.  I just don't know what to use in order to accomplish this.  I have updated my code where I added another read after the start byte read and tried to include a counter but I'm not sure I'm doing that right.  Attached is the latest, but I am not correctly reading my packet.


When you read your start byte, then read the rest of your message (11 bytes) and do whatever verification you need to.


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 10 of 12
(1,917 Views)