From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
09-23-2015 09:11 AM - edited 09-23-2015 09:23 AM
Hi everybody!
I have to read a set of data provided by sensors that communicate via RS232 serial protocol. I've implemented a VI that reads continuosly the string output of the serial port, but I also have to process and analyze data to do other tasks with it. I thinked to use a consumer/producer structure because the reading process is faster than the analysis process.
In reading everything is OK, but I've the following problems:
1. There are three types of data I've to manage, each one with different length in bytes. I also need to convert them from ASCII to HEX. I do this with the Type Cast tool, but the converted characthers are followed by a big number of zeros before the next valid character.
By example, the valid set of data are:
- 24 04 C1 XX (first length)
- 24 09 CB XX XX XX XX XX XX (2nd length)
- 24 12 C9 XX XX XX XX XX XX XX XX XX (3rd length)
Instead, I read in the file that is created by the producer loop:
- 2404C1XX00000000000000002404C1XX00000000000000000000000000000000000000000000000...00000002409CBXXXXXXXXXXXX000000
2. First three bytes of each type are respectively the START of FRAME, LENGTH of FRAME, TYPE of DATA HEX codes. The VI has to be able to recognize the first one to split the whole set of data in small parts for being processed
in the right way.
Does someone have any idea?
I've attached a screenshot of my first attemp to to this.
09-23-2015 01:24 PM
What I would do is have a WHILE loop inside the Producer loop.
The WHILE loop would keep reading bytes until I get 24 since I know that is the start of a message.
Then read another 2 bytes. Based on those 3 bytes determine how many more bytes to read.
Then when that message is complete send it off to the Consumer Loop.
09-23-2015 01:54 PM
09-24-2015 06:48 AM - edited 09-24-2015 06:49 AM
So, you are telling me to pass the whole output string of the serial read to WHILE loop, and then check byte by byte if I receive the START of FRAME, go to next character and read the length of string to get the total substring I need to process the message and finally pass it to consumer loop. Right?
The device send me messages in HEX, but I think it's the same thing, I should be able to process data also in binary mode.
09-24-2015 08:36 AM
@Jader wrote:
So, you are telling me to pass the whole output string of the serial read to WHILE loop, and then check byte by byte if I receive the START of FRAME, go to next character and read the length of string to get the total substring I need to process the message and finally pass it to consumer loop. Right?
The device send me messages in HEX, but I think it's the same thing, I should be able to process data also in binary mode.
No, you want to read one serial byte at a time.
09-30-2015 06:18 AM
I think I found the right way! Thanks for your advice! For now everything works good. Take a look to my application...
Thank you again!