Home/Support/Support Forum/RS485 DRIVER on Packet.lib
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

RS485 DRIVER on Packet.lib

+1 vote

I use Packet.lib to send and receive RS485 messages. It’s working fine.
But the receive cof_pktDreceive will block until a char is receipt. How can I known if a char is present before using cof_pktDreceive function ?
asked Sep 25, 2019 in Rabbit by markko67 New to the Community (1 point)

Please log in or register to answer this question.

1 Answer

0 votes
Hmm. The point of cof_pktDreceive() is for a costate to yield until a character arrives. If you're using costates in your program, you'd typically have one dedicated to receiving messages so it's not a problem if it blocks until a packet arrives.

You can call pktDreceive() instead if you need non-blocking reads. it will return 0 if there aren't any characters available to read.

Note that Digi provides source to all of its libraries so you can see how each function works. Here's the source to cof_pktDreceive():
nodebug scofunc int cof_pktDreceive(void *buffer, int buffer_size) { auto int length; while((length = pktDreceive(buffer, buffer_size)) == 0) { yield; } return length; }
answered Sep 26, 2019 by TomCollins Veteran of the Digi Community (2,303 points)