Linux Serial Read throws Error

后端 未结 3 1510
感动是毒
感动是毒 2021-01-22 01:27

I\'m attempting to read from my serial port using the following C code. I can successfully write to a listening computer (yay!) but the read throws Error (Code 11 - Resource tem

3条回答
  •  余生分开走
    2021-01-22 02:06

    You have a buffer overflow here:

    sprintf(message,"Test%d\r",running);
    

    since message is declared as:

    char message[6];
    

    message needs to be at least 7 characters in size if it's going to hold a 6 character string, due to the need for a '\0' terminator.

    There may well be other problems too, but you should fix this and see if it makes any difference.

提交回复
热议问题