LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Arrays of Hex numbers to a serial port

I was wondering if anyone could give some help as to how I could send an Array of hex numbers to a Serial Port. I have the array data type as unsigned char, which is correct in this instance.

 

However using the ComWrt( function, the buffer is required to be data type char.

 

How is it possible to change from an unsigned char data type to char? and ultimately will this solve my problem and allow me to send packets to the serial port?

 

Thank in advance.

 

0 Kudos
Message 1 of 3
(2,919 Views)

just to add to my previous post.

 

I am basically trying to re-create what I can do on RealTerm, which is send the string shown in green in the image attached and receive the one in yellow.

 

0 Kudos
Message 2 of 3
(2,886 Views)

First of all, what you see in RealTerm is simply a representation of what's going on in the serial channel. You can represent a value in different ways: 117, 0x75, o165 or b01110101 are the very same value represented respectively in decimal, hexadecimal, octal or binary notation. In this respect, you are not "sending an array of hex values" to the serial port, you are representing in hex notation a message sent to that port.

 

Second, ComWrt can accept an unsigned char string as well without complaining. Your characters will assume different values if interpreted as signed or unsigned, but this is exactly a problem of interpreting an aseptic bit pattern. Just as an example, try pasting this code in the Interactive window and see the result in the Debug Output window:

#include <utility.h>
static char	chr[32];
static unsigned char	uchr[32];
static int		i, idx;

for (i = 0, idx = 0; i < 256; i += 8, idx++) {
	chr[idx]  = i;
	uchr[idx] = i;
	DebugPrintf ("Value  0x%02x:    char = %3d    unsigned char = %4d\n", i, i, chr[idx], i, uchr[idx]);
}

 



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 3 of 3
(2,882 Views)