6 years, 6 months ago.

how can we send 0x00 to uart port ??

Hi,

I want to send following command into serial port :

const char Send[] = {0xBA,0x0A,0x02,0x00,0xAA,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x18};

When I sent this command using serial.printf(Send); It send only first two bytes because 0x00 is consider as a terminator character so how can I send this command ?? please give me some solution or suggestion about this problem.

Thanks Dinesh

2 Answers

6 years, 6 months ago.

pretty sure member function putc(0x00) will work so you could replace printf with the following lines of code.....

for (int i=0 ; i<sizeof(Send)/sizeof(char) ; i++)
{
      serial.putc(Send[i]);
}

I tried this but I want sent complete command at a time other wise if send one by one char then response coming from serial device is not valid. Serial device accept complete command only it not accept char by char.

posted by dinesh thanth 18 May 2018

Thanks it is working now

posted by dinesh thanth 18 May 2018

just a note. printf uses putc to output to putchar which then writes to stdout printf 'parses' the string which uses a NULL character 0x00 to terminate the string hence the issue you saw in the first instance printf will also 'parse' for data types e.g. %d %f and format e.g. /n /r /t but uses putc to send on so printf will send one character at a time anyway.

posted by Martin Simpson 18 May 2018
6 years, 6 months ago.

Hi,

This may not be a beautiful way, but how about

        printf("%c%c%c%c%c%c%c%c%c%c%c%c",
            0xBA,0x0A,0x02,0x00,0xAA,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x18) ;


moto