05-03-2013 02:43 AM
Hello,
I would like to read some values form a microcontroller using VISA function in LabView.
The problem is that my microcontroller send 2 bytes of characters to Labview. These characters are in binary form.
I would like to read them as a single 16 bits character. Coukd you please help me.
Thak you
05-03-2013 02:58 AM
Please post some sample data that you receive and your expected data and we will be able to help.
05-03-2013 03:08 AM
Ok, I explain more...
My problem is that I send 2 bytes through the serial port to my LabView program.
for. ex. the first byte is 11111111 (or 255 in decimal) and the second byte is 00000001 (or 1 in decimal).
I can read them one by one via VISA.
However, if I want to read these 2 byte as a single 16 bits character, I cant. In other words, I want to have the value 100000000 (or 256 in decimal) instead of these 2 byte.
Many thanks,
Joobin
05-03-2013 03:36 AM
05-03-2013 03:59 AM
Are you sure you example is correct? Your final result is simply the sum of the two received bytes, not the 16 bit value you get joining them.
If you need to read a 16 bit value, you normally wire 2 to the byte count input of the VISA Read function, then type cast the string to a U16 (or I16) integer.
You may need to swap the two bytes, though.
05-03-2013 05:19 AM
Thank you very much for your replies.
Yes I am sure that the example is correct. becasue I want to read values between 0 to 1024 with VISA function.
So I need more than one byte.
I changed my program as Paolo told me. Now I read only 2 bytes every time. then I use Type cast fucntion.
But still does not work.
All I want is to read for.ex a value like 654 from the port.
I attach my program below.
Thanks for your help.
05-03-2013 05:26 AM
You have wired a string constant instead of a numeric constant to the type def type terminal.
05-03-2013 05:37 AM - edited 05-03-2013 05:39 AM
Quite a big loop structure for a small code, don't you think?
There are a few remarks to do about your code.
1) you are typecasting a string to a string: this code does nothing at all; you should wire a U16 constant to the typecast's upper input
2) you open the serial port and start reading from the microcontroller in a loop; how do you know that the first byte you read is really the first byte and not the second of the previous value? is there no synchronization character?
3) you should do some error managing in case you don't get the two bytes you need
05-03-2013 08:53 AM
Thank you.
In fact I am not too professional in Labview 🙂
Unfortunaltely, none of the methods worked. However, I tryed to use another method...
I will first read a single byte as a low byte, then I read a second byte as a hi byte.
Once I have low and hi byte I can perform some operation to get the total value on 16 bits.
In c I use something like that:
TOT_VALUE=( ( (unsigned int) hi-byte) <<8) | (low_byte)
However, here it is difficult...
By the way thanks a lot.
05-03-2013 08:59 AM
The method will work if you implement it properly. So instead of going down another path than what was given, and claiming that is too difficult, try to make what you were given work. At least explain how it is not working and attach the latest VI showing your attempt.
Here is your previous VI with the changes made.