Send binary to serial port

To send a serial line character to a serial port. I will need to call WriteFile (handle, "A", strlen ("A"), ...)

However, what if I want to specify and send a hex or binary number? For example, I want to send WriteFile (handle, 0x41, sizeOf (0x41), ...)?

Is there a function that allows me to do this?

0


source to share


2 answers


There are many ways.

The most direct one for you, but would be WriteFile (handle, "\ x41", 1 ...);



The strlen () function is overkill since you know the length.

0


source


If you just want to write one byte, it must still be in the array.

So, you will need:



int buffer[1024];
buffer[0] = 42;

WriteFile(handle, buffer, 1);

      

See this: http://msdn.microsoft.com/en-us/library/aa365747(VS.85).aspx

+1


source







All Articles