chRead (Function) |
Top Previous Next |
The "chRead()" function will read a message from the specified channel. If there is no message present in the channel, the calling thread will be blocked due to waiting for another thread to write a message by using the chWrite() function. Optionally, a timeout for the read operation can be specified.
Also see chWrite() and the section on Using Multithreading.
Special note on writing strings to a channel: A STRING cannot be written directly to a channel with chWrite() but must be converted into pure memory with the strToMemory() function before being written to a channel. When this message is received by chRead(), it can be converted back to a string again by using the strToMemory() function.
Input: ch : CHANNEL The channel to read the message from.
msg : PTR Pointer to buffer where the message is to be stored.
lenmax : INT Size of the buffer that msg points to. If the size of the message in the channel is larger than lenmax, only lenmax bytes will be read. The remaining part of the message will be lost in this case.
timeout : INT (default: -1) The time, in ms, to wait while trying to read data from the channel. Use -1 to wait forever. This is the default.
Returns: INT
Declaration: FUNCTION chRead : INT;
Example: INCLUDE rtcu.inc |