LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

create a function in CVI

Solved!
Go to solution

i'm sorry this is the error  and i don't undrestand so well how to check ComRd can you give an example please Capture.PNG

0 Kudos
Message 31 of 32
(470 Views)

See the help on ComRd:

 

Return Value

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.

  • If you receive an error, you must handle it; at least inform the user and do not proceed as if all was good!
  • If you don't receive the expected result, you must handle this situation: you may need to change something in your code, or cabling, or who knows what

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 32 of 32
(468 Views)