0

I am trying to figure out if I should use blocking or non blocking communication with RxTx. I have to communicate with a device that accepts commands and reply.

  1. There are over 20+ commands
  2. Reply pakcets dont contain any information about which command was executed.
  3. I have to send for each packet ENQ/ACK and checksum checks.

So blocking seems the easiest solution.But isnt bad practice ? How could it be done without blocking ?

GorillaApe
  • 3,611
  • 10
  • 63
  • 106

1 Answers1

0

Write a little server. Have a queue for commands to send. Mark the top one as in progress, send it, wait for a response asynchronously, and then process it and remove from the queue.

NB assumes you have exclusive access to the device.

You client then sends commands to your "server", you can easily do blocking and non-blocking calls to your server.

Basically hide behind a nicely crafted abstraction.

Tony Hopkinson
  • 20,172
  • 3
  • 31
  • 39
  • and how about timeouts ? I mean if i send ENQ and dont get ACK back then its timeout. – GorillaApe Dec 31 '13 at 12:29
  • When you send kick off a timer. if you receive in time, kill it. If it triggers you have a timeout. Take the current message out of the queue, raise an exception in blocking call, return some useful error structure on non blocking. If RxTx has something built in e.g a Timeout event, add a handler for that and you don't need to mess wit h a timer. – Tony Hopkinson Dec 31 '13 at 12:37
  • It's that sort of thing that made me suggest writing a little server, it's the only thing talking to the device and can do all the comms, otherwise everything that needs to talk to it has to deal with all of it, which would be the waking nightmare you've been struggling with. – Tony Hopkinson Dec 31 '13 at 12:39