1

I am currently creating an HMI, using Qt 5.6.0; MSVC 2013, 32-bit, to communicate with external devices via serial port using the Modbus RTU protocol. I have three such devices. Call them A, B, and C. My code, which sends a customized string and then waits (~100 milliseconds) and checks for a reply: Simple tool to send custom strings and receive a reply

My code successfully communicates with A and B. But, when I attempt to communicate with device C, I 'see' no reply when I read from the input buffer. However: 1. There are LEDs which indicate data flowing on Rx as well as Tx lines. Both light up, indicating that traffic has gone both ways 2. The Windmill software known as ComDebug is successfully communicating with A, B, AND C.

I have recently modified my code to poll the serial port every 20 milliseconds for 5000 milliseconds but it has made no difference. I have no idea where to even begin looking for the source of this bug. Any suggestions are welcome!

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
Numi
  • 65
  • 6
  • Is there maybe a protokoll specific handshake or data sequence expected to start communication and Devices A and B are just less strict about the protocoll? – exilit Jun 15 '16 at 09:06
  • It might be worth trying something like this: http://www.serial-port-monitor.com/ to monitor what you are sending and what you are receiving (if anything) rather then relying on the lights. This sort of tool (like wire-shark I guess) is invaluable. Alternatively you can try to "snoop" by T'ing off a separate bit of serial cable (rx/tx/gnd lines) but this probably requires a bit of wire cutting and soldering... – code_fodder Jun 15 '16 at 09:18
  • You're polling? What for? Serial ports are asynchronous, your code will be notified exactly when data is available. There's no way to answer this question without you showing a complete example with code. My hunch is that you have a bunch of spaghetti that doesn't quite do what you think, but then I'm partial to explicit design/spec using statecharts. See [this answer](http://stackoverflow.com/a/32595398/1329652) for inspiration, for example. If you insist, I can tweak it to be an RTU client and either use a real server or emulate a server just to tickle your senses :) Qt 5.6 implements RTU! – Kuba hasn't forgotten Monica Jun 15 '16 at 15:49
  • @code_fodder I'm going to the R&D lab in a few days (it's in a different city) and will check out whats happening on an oscilloscope. Will post the pictures as soon as I get them, and will use the tool you recommended tommorow and report the result – Numi Jun 18 '16 at 10:13
  • @KubaOber Yeah, I'm currently working on disentangling the spaghetti, at this point that's my second-best best guess (first if the oscilloscope examination yields no results) – Numi Jun 18 '16 at 10:15
  • @exilit Modbus RTU is a master-slave protocol; I send my stuff, end it with a CRC (checksum-type thing); a brief silence lasting a minimum of 3.5 character times (ie. 3.5x the time taken to send one byte, which varies according to baudrate) lets the other device know it's time to check the transmission, and formulate and send a reply – Numi Jun 18 '16 at 10:17
  • @KubaOber thanks for the link! I'm a novice programmer (this is in fact my second programming project ever and first in a professional capacity) so it is taking me a while to wrap my head around that answer but I'm working on it, as I sense that I will learn a lot if I can comprehend all of it! – Numi Jun 18 '16 at 10:38

0 Answers0