Do
{
Memset (buff, 0, BUFFER_SIZE);
If (nread=read (fd, buff, BUFFER_SIZE) & gt; 0)
{
Printf (" The received words are: % s \ n ", buff);
}
sleep(1);
Write (fd, buff, strlen (buff));
} while (STRNCMP (buff, "quit", 4));
CodePudding user response:
Printf (" The received words are: % s \ n ", buff); This line only type 0 x31, with a loop to play X %CodePudding user response:
If send 31 00 32, all can print it outCodePudding user response:
If a serial port initialization which Settings are not set?CodePudding user response:
Strlen function '\ 0' (equal to the number 0) to determine whether to to the end of the string, the length of the strlen calculated is 1, in fact you only read a byteCodePudding user response:
Sorry, the write one byteCodePudding user response:
I also encountered this problem,An array of strings inside 00 is annulled,
CodePudding user response:
Strlen function to '\ 0' (equal to the number 0) determine whether to to the end of the string; Try to use when sending and receiving dataCodePudding user response:
Write (fd, buff, strlen (buff));//method error, the length of the string functions should not be used to calculate, should be used to read data length,
Modified to
Write (fd, buff, nread);
The rest of the logic judgment should be modified according to the situation,,
CodePudding user response:
This should be 0 x00 as string terminatorCodePudding user response:
Do not use the length of the strlen is used directly