ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

extended ASCII Characters

I receive a message via the serial port containing Characters from the Extended ASCII Character set. I am wondering how I can convert them to a hex value. When I double click the variable in the variable viewer I can change the format to hex and it is exactly what I am looking for. But I cannot figure out how to modify the value. Note: I am not trying to display it just use it's hex value.

Thanks for the help,
Wade
0 Kudos
Message 1 of 5
(3,860 Views)
I think you can do this.

char buffer[256] = {0};

sprintf(buffer, "%x", hex_value_from_port);

buffer should display value in hex now.

Sheetal
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 2 of 5
(3,852 Views)
That method works perfect for the normal ASCII Character Set (under decimal 127), but when I have a character in the extended character set it gives funny results.

Example:

Hex: 0xF1
Decimal: 241

Result of Output: 12fde8

Thanks for the help
0 Kudos
Message 3 of 5
(3,845 Views)
Try receiving the messages in a buffer of type unsigned char[]: a char ranges from -127 to 128 while an unsigned char is 0 to 255. The same bit patter in the two cases represents different numeric values.

Try executing these lines in the interactive window:

unsigned char b[10];
char a[10];

strcpy (a, "Hello!"); a[3] = 241;
strcpy (b, a);

DebugPrintf ("String A: %s - a[3] = %x (%d)\n", a, a[3], a[3]);
DebugPrintf ("String B: %s - b[3] = %x (%d)\n", b, b[3], b[3]);

Output will be:
String A: Helño! - a[3] = fffffff1 (-15)
String B: Helño! - b[3] = f1 (241)

Hope this helps
Roberto

Message Edited by Roberto Bozzolo on 05-20-2005 06:53 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,838 Views)
Thank you very much, that is what my problem was. I figured I had to be doing something dumb.
0 Kudos
Message 5 of 5
(3,833 Views)