06-08-2017 05:46 AM
i'm sorry this is the error and i don't undrestand so well how to check ComRd can you give an example please
06-08-2017 06:05 AM - edited 06-08-2017 06:06 AM
See the help on ComRd:
Name | Type | Description |
BytesRead | int | Number of bytes read from the input queue. If an error occurs, the return value is a negative error code. |
And:
ComRd times out when the input queue remains empty for an entire timeout period. On a timeout, ComRd returns the number of bytes actually written (typo: actually read) and sets rs232err to -99
Try something like this:
result = ComRd (Port_CAN, Reponse, 11); if (result < 0) // Print the value of result
// Terminate function else if (result < 11) // Not enough characters! // Print how many characters received and possibly the message received
// Terminate function else // Interpret the string
This is the very basic of error checking: functions very ofter return a meaningful value that you must check before proceeding.
If you are not familiar with these concepts you should take some time to read and experiment a little on this. It's not that I am fussy: error checking is the basis of I/O code.
You cannot go on assuming all works well, because at some moment something will not. How many times your phone calls are not good? The person is not there, the line is noisy, the phone goes out of battery... the same applies here, and error checking is the way to address these situations.