04-13-2021 11:53 AM
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.
04-13-2021 12:01 PM
@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
04-13-2021 12:11 PM
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.
04-13-2021 12:12 PM
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.
04-13-2021 12:15 PM
My message has a start byte 0x24 and ends with a 2 bytes CRC. Thanks for the presentation.
04-13-2021 01:10 PM
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
04-13-2021 01:42 PM
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.
04-13-2021 02:13 PM
@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.
04-14-2021 07:52 AM
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.
04-14-2021 08:06 AM
@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.