Sending hex values using a serial port

Hi !

Does someone know the best way to send just HEX values with a serial port. Thre is a lot of functions to send strings but what about just numbers
i guess we could use serXwrite for that i’m i wrong. tks AC

What do you mean you want to send the hex values?
Do you mean that for the hex value 0xA3, you want to send the ascii characters ‘A’ then ‘3’?
If so then perhaps:

char buffer[3];
char hex;

hex = 0xA3;
sprintf(buffer,“%x”,hex);
serXputs(buffer);

Hi !
Thanks for a reply, i use serXwrite function and it works. Because all
serial functions except serXwrite take a char or string of char as input argument.

No they dont, serXwrite is exactly the same as serXputs, except serXputs writes until it encounters a NULL terminator, serXwrite writes the amount of characters you specify to it.

Remember serXwrite(pointer,amount) is its format.

Besides you can write serXputc(0x12), which doesn’t take as argument a character, but a hex value.

I still don’t understand what you want to achieve.

Se puede hacer de otra manera.

Esta funcion envia una cadena de valores hexadecimales compuesta por 6 datos.

SendCommand(0xA3, 0x00, 0xAA, 0x10, 0x00, 0xFF);

void SendCommand(int Hex1, int Hex2, int Hex3, int Hex4, int Hex5, int Hex6)
{
char Command[6];
Command[0] = Hex1;
Command[1] = Hex2;
Command[2] = Hex3;
Command[3] = Hex4;
Command[4] = Hex5;
Command[5] = Hex6;
serXwrite(Command, 6);
}