10-31-2018 07:19 AM
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.
11-01-2018 11:50 AM
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.
11-01-2018 01:51 PM
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]); }