12-08-2009 08:16 PM
I have a question regarding my serial data acquisition application. In my application, I am using visa read to acquire serial data sent by an inertial measurement unit. When I first power up the sensor, it sends data in the following format only once:
header 1:0x8011 followed by 1 data word for checksum, 1 data word (each data word 16bits).
and then the sensor starts sending data in the following format:
header 2:0x7FFF followed by 1 data word for checksum, 9 data word (each data word 16bits).
(Note: Checksum is defined as a 2s-complement of the 16-bit sum of the rest of the entire message)
In my application, to keep the problem simple, I am using a wait function to make sure that the initial data tagged header 1 is sent. Then I start reading 20 bytes using VISA Read (header 2 plus the associated data words are 20 bytes), as I am mostly interested in the the data words tagged with header 2.
However, when I do that, the data that I am getting does not start with 7FFF character and, as a result, my 20 byte data can not be parsed properly. My question is how can I make the "VISA read" block read serial port only when the data is preceded by "7FFF". Once I solve this part, my strategy will be reading 20 byte (including the 4 byte header) data assembly and parse it accordingly.
Another question, I am wondering if you can tell me how to use the checksum given it is defined as "a 2s-complement of the 16-bit sum of the rest of the entire message". Note the data tagged with header 1 is 1 message.
I would really appreciate if you responded my request.
Thank you!
Serdar
Solved! Go to Solution.
12-09-2009 01:21 AM
How I did this in the past:
Collect the data from the serial port into a shift register string and use the match pattern ... here is a blind try (5min)
12-09-2009 01:37 AM
Thank you very much for the response. I'll try as soon as I get back to my lab. Before doing that, I have one more question;I don't think I can use the match pattern because I don't know what the characters are in the serial data except for the header?
Regards
12-09-2009 07:39 AM
The dot in the match pattern is a wildcard for exact one character (read the help for match pattern and follow the 'special characters' for match pattern' link ((I put this to my help-favorits)))
You can use the match regular expression vi to do an even more specific search at the cost of process load. Here the expression would be something like:
\x7F\xFF.{20} assuming that the 7FFF means a two byte hex value. Instead of the dot you can be more specific \x7F\xFF[0-9]{20} would accept only 20 ASCII numbers 0 to 9 after the header.
Regular expression are very powerful here's a website only on this
12-09-2009 06:54 PM
Hi Henrik;
Thank you so much for the code. Now, I am able to get the data assembly to work on. However, now I have a different problem. When I try to convert A hexadecimal string, say FF (it may not be a hexadecimal string but this is my best shot as to what it could be) into a number using "hexadecimal to number" block, I keep getting only zero whereas I am expecting to get 255. Do you have any idea how I can convert this into a number? Note that this value could be any number between -32750 and +32750.
Also, when I checked the lenght of the FF character with the "string lenght" function I am getting 1 whereas I am expecting 2. Do you have any idea what is going on here?
Thank you so much. I really appreciated your answers.
PS:I attached the file to the post.
Regards,
Serdar
12-09-2009 07:40 PM
12-09-2009 08:05 PM
Thank you very much for the response. Actually the hexadecimal string that I would like to read is "FF7F" 16 bit data word. When I typecast it to U16 I am getting 127 while expecting 65407. (By the way, according to the manuel of the device, this could be a value between -32750 and +32750; almost the half of the 65407. I don't know if this has sometiong to do with signed , unsigned thing? Do you have any idea)
Also, could you please let me know how I can read it as 65407?
Thank you.
Serdar
12-09-2009 09:22 PM
12-10-2009 12:51 AM
12-10-2009 01:52 AM
here are some conversions, note the numeric Display, that need no code and work directly in the frontpanel (this will work only for the 'binary' representations , [UI][64,32,16,8])