RS485 DRIVER on Packet.lib

HI,

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 ?

1 Like

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;
}