LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

decode strange character when recieved data from RS232 port

Hi:

I have question regarding to decode strange character when received data from RS232 port.

Here is a sample of what I received when using the sample program serial.cws provide by NI:
" ÿÿÿÿOBÂh(,2.578 ,2.675 ,2.383 ,1.605 ,1.800 ,1.261 ,1.353 ,1.415 ,1.946 ,1.702 ,1.946 ,1.246 ,1.556 ,F3

The data format, suppose come in with a Header of the equipmnent that are connected to the RS232 Port which include, MOdel number, SN number time, Date, Frequency, Correction Factor, Measurement Unit and a sets of recording values. The Last two bit is a checksum of the completed data in HEX.

The Recording value is and chechsum is readable. However I would like to know how to deode the first part with all those funny character.

Also the above sample is received by using the sample program "serial.cws", provide by NI and I seting the read_cnt into 1 and repeat to execute the "Read" until I see the checksum is showing. If I set the read_cnt to 2000 I received "" all the data has been packed into two character and cannot decode.

I greatly appreicate your help to solve this problem.

Thank You

Vicky Lai
0 Kudos
Message 1 of 11
(7,575 Views)
What kind of format is your header portion of the file in? Are they extended ASCII characters? Do they contain foreign characters? I would check the hex value of those funny characters you received and compare them with the HEX valuses of the desired characters and see if they match. You can check the HEX value of those characters by using different display mode.
0 Kudos
Message 2 of 11
(7,559 Views)
Hi TongY

Thanks for your reply. Can you give me a example that any function I can use to display the funny character. E.g.
if my first byte received as" read_data = "" is there a function in LabviewCVI or Labview C++ that would allow me to see the hex of its value? e.g. HEX (read_data) ?

Looking forward to your prompt reply.

Thank You
0 Kudos
Message 3 of 11
(7,552 Views)
Hello Vicky,

You can print the hex value of a character with the printf statement (or the DebugPrintf statement if you want to view it in the CVI debug window).

For example, you could do:

DebugPrintf("%x", read_data);

This will print the hex value of read_data to the CVI debug output window.

Hope that helps.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 4 of 11
(7,548 Views)
If read_data is a string, you can print it one character at a time in a loop:
for (i=0; i printf(" %X", read_data[i]);
// or to see the character and hex ASCII value,
for (i=0; i printf(" '%c'=%X", read_data[i], read_data[i]);

Another temporary way to view the string is in the debugger.
Put a breakpoint after the string is read.
Run the code.
When the debugger hits the breakpoint and opens the editor window, right-click on the varible name and click on View Variable Value.
In String display window, click on Format and select Hexadecimal.
0 Kudos
Message 5 of 11
(7,547 Views)
Hi:

Thanks for your reply. I have another question regarding to the example serial.cws.

I download the labview run time engine CVI71.zip and run it on the another windows 2000 platform without the full version Labview CVI installed, everythings works fine, the equipment that being connected to the RS232 port is getting response and taking action. I install the CVI71.zip in the labtop that run under windows XP and it seems that that they can detect the right port number, but somehow the program cannot control the equipment that is being connected to the RS232 terminal. Any hint for that?

Best Regards
Vicky
0 Kudos
Message 6 of 11
(7,536 Views)
It looks like the forum's automatic interpretation of the less-than symbol < as html messed up my earlier response.
The statements should read:

for (i=0; i < strlen(read_data); i++)
printf(" %X", read_data[i]);
// or to see the character and hex ASCII value,
for (i=0; i < strlen(read_data); i++)
printf(" '%c'=%X", read_data[i], read_data[i]);
0 Kudos
Message 7 of 11
(7,532 Views)
Hi:

Thank You for your suggestion to my decoding strange character problem. I open the watch windows on the variable and I can display it in HEX.

I would like to know How can I save the HEX code that display inside debug watch window to a variable in my problem. For example if my variable recieved as: read_data = W"43, debug windown in hexdecimal mode given " 12 57 13 02 22 04 05 37 00 " which implyies to sec, mim, Hour, Date, month , year and check sum of the resonse. Is there any fucntion in labview I can save this hex value into the variable of my program.

Also, If I have a value "54" which is know as in hex form, Is there a fucntion inside Labwindows CVI which can transfer this in to ASCII (T, in this case).

Thank You and Looking forward to your prompt reply.

Best Regards
Vicky Lai
0 Kudos
Message 8 of 11
(7,497 Views)
The printf() and sprintf() functions can be used to convert byte values to ASCII characters. See this code snippet. Review the help for printf and sprintf and see an ANSI C text for the % format specifiers.

#include < ansi_c.h > // remove spaces between < >
char read_data[]="W\"43";
char my_time[80];
char my_byte[5];
int i;

my_time[0] = '\0';
for (i=0; i < strlen(read_data); i++)
{
sprintf(my_byte, "%x ", read_data[i]);
strcat(my_time, my_byte);
}

i = 0x54;
printf("My time = %s\n", my_time);
printf("ASCII %#x = \"%c\"\n", i, i);
0 Kudos
Message 9 of 11
(7,489 Views)
Hi:

Thanks for your advice. I try out the code;

i=0x54
sprintf (my_byte, "%c", i);

the result of my_byte shows as "T".

If I retrieve the value from an array e.g. arr[1] = 54 which is already known as in hex mode, how can I indicated is already in hex? I try out:

i = 0x(arr[1]);
sprintf (my_byte, "%c",i);

and I got an compling error.

Thanks
Vicky Lai
0 Kudos
Message 10 of 11
(7,485 Views)