LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Why am I getting the twos compliment of my serial data when I do a ComRd in CVI?

For some reason, when I do a ComRd in Labwindow/CVI it's interpreting the most significant bit of each byte as an indicator of that byte's sign (positive or negative). So instead of getting 128 for 0x10...I'm getting -128. Is there a way to tell Labwindow/CVI not to do this or do I have to manipulate (twos compliment + 1) each byte so I get the correct value.
0 Kudos
Message 1 of 3
(2,721 Views)
ComRd returns a char[] buffer, so it's not converting anything to two's compliment. What are you doing with the data after you receive it? If you take the char one byte at a time and cast it as an int, it will be two's compliment. If you cast the char as an unsigned char, you won't get two's compliment.
For example:

#include
main()
{
char c;
char s[256];

c = 255;
printf("%d %d", (int) c, (unsigned char) c);
gets(s);
}

Output:
-1 255
0 Kudos
Message 2 of 3
(2,721 Views)
doh!...thanks.

I was declaring it a char not unsigned char.
0 Kudos
Message 3 of 3
(2,721 Views)