03-23-2015 01:09 PM
Hello guys,
am a newbie to labview and currently working on my student final project, but I have encountered a problem extracting both the voltage and current values from hexadecimal string read at VISA read buffer. Also I want to discard the header string each time so I can only process only the voltage and current hexadecimal string. My string of data read is as attached. AA55 0023 0034 AA55 0045 0132 AA55 ..... Where AA55 is header I want to discard. The next 2 bytes after the header represent the voltage, while the next 2 bytes represent the current. After 6 bytes, the header(AA55) appears again.
So far I read the data at VISA read as in VI attached, and I would appreciate all the help in successfully extracting only the voltage and current values each time the header(AA55) is read at raw data. I have read various forums regading this topic but none seems to click yet. Thank you once again!
The VI am working on is attached and some failed attempts in print screens.
Solved! Go to Solution.
03-23-2015 01:22 PM
Read 6 bytes. Search the returned string for AA55. If they are at the beginning of the string, go ahead and convert bytes 3 4 5 and 6 to your values.
If not, determine where it is, (For example, if it is in bytes 4 and 5, discard bytes 1 through 3 and read 3 more bytes, then parse into your values.)
03-23-2015 01:22 PM
What is the datatype of the current and voltage? (I16, U16, little/big endian, etc.). Given the string "AA55 0023 0034", what values would you expect?
Since you have the raw data indicator set to hex display, I assume this is a binary string and not a hexadecimally formatted string.
03-24-2015 04:18 AM
Hello RavensFan,
I appreciate your feedback. I have tried to modify as per your suggestion (power_demo.vi) to look as attached. But I get framingerror1(-1073807252) after about 1 minutes of reading the data rececived in "result". Framingerror2 am able to still read the data every time excluding the "AA55". I do not know how to discard if AA55 appears in maybe byte 4 to 5.
It looks like the offset for search and replace is working okay, each time returning only 4 bytes to be processed. But during the framing error, sometimes 3 6 bytes are all received if the AA55 doesnot appear in the input string. I am not sure where am going wrong, perhaps you could have a look at my VI and advice or correct accordingly!
Apology, I was at skul so couldn't respond immediately.
03-24-2015 04:21 AM
Attached is the serial data read from my microcontroller using HDX hex reader for your reference.
Thanks
Gavin.
03-24-2015 04:24 AM
Hello Altenbach,
yes, my raw data is a binary string, I only formated to hexadecimal so i can easily extract the values. The string received is as attached in the picture below. I appreciate all the help rendered regarding this challenge.
Thanks
Gavin.
03-24-2015 07:12 AM
A framing error means something is wrong with your actual string of bits, 1's and 0's, coming from your device. The start and stop bits aren't where they are expected to be. Double check all of your serial configuration parameters to make sure they match the device. Baud rate (230,400 seems rather high), stop bits, data bits, parity. Something is probably wrong in there. That or you have bad cables or electrical noise interfering with the transmission.
Why are you flushing the receive buffer? That is almost never necessary and could actually cause you to lose data or throw the synchronization of your data off once you get it established.
I have no idea what you are trying to do in that inner while loop. That looks nothing like what I was describing.
See the attached VI. I haven't completely tested it (after all, I don't have hardware sending me data). But it should give you the idea.
03-30-2015 01:56 AM
Thanks guys for the tips. Apologies for late reply, but been busy with exams lately. Otherwise the idea of separating the bits seems to be working. But now that I have separated into voltage/ current hex values, am trying to convert to binary or decimal number in the range of 0 ~ 1023, and plot it on a graph with the same scale. I have tried typecast, hex to binary conveter vi, but none appears to be working until now. I am confused, and don't know what to do next. When I convert manually using a calculator forexample "01C3" in hex to binary its "0000000111000011" and in decimal its "451" in the range 0 ~ 1023 as expected.
The hex values (2 bytes each for volt, and current) keep on being read as I continue to receive the hex data from the serial port, but the cinversion either returns a zero or wrong value. I kindly need your help regarding this issue. Attached is a print screen of what is happening as well as the vi and hex values received(read using serial port software). Maybe I should do the conversion outside the case structure, I tried too, but also not working!
I need to successfully plot this data and then do further signal anaysis as find the phase and frequency of the incoming signal.
Thanks,
Gavin.
03-30-2015 07:17 AM
The Type Cast to a U16 should work. Alternatively you could use String To Byte Array followed by Index Array and Join Number to build up your 16 bit number. Or you could use Unflatten From String and make sure the endianness is set to Big Endian.
Your values are stored in the binary representation, not the ASCII representation. Therefore the Hexidecimal String To Number will not work here.
03-30-2015 08:55 AM
Thanks for the clarification. Having re-checked my vi again, typecast finally worked this time. Also I wasn't so sure of my data format.
Gavin.