Qt Serial Port Rs485 Interface

 
  1. Rs485 Serial Port Monitor
  2. Rs485 Serial Communication
Serial

Rs485 Serial Port Monitor

I have an Arduino-based device which connects through USB. I'd like to detect it from my Qt 4 application, using QExtSerialPort (or whatever necessary), when it's plugged in. If this weren't possible, I thought I could somehow get a list of the system's port names and just try all of them in search for my Arduino (where I'd implement some kind of handshaking procedure for it to detect it correctly). My concern in this approach is that I'm not sure if a device (for example, printer) would get damaged if I send some kind of handshaking ack at a different baud rate. So, I don't really know where to start for any of them. Which would be the best approach? How would I implement it?

Since your device is USB, your UART port will be emulated by some kind of conversor in his hardware. So first you must understand what driver is being used on your system. The most common SERIAL-USB conversor uses PL2303/PL2301 chip, so it would create a path on /dev, if its the first device, it will appear as '/dev/ttyUSB0', but you may also see the list reading the proc path (like 'cat /proc/bus/usb/devices'). Under Windows it usually creates a virtual 'COM', just go to device manager and check the port. When you are sure about how the HW talks to your system, you may use QExtSerialPort for wrapping the system API and talk to the device. Way too hard and too platform specific, using weird Windows Registry keys or rely on hard wired device nodes on Linux. You are on the right way.

Rs485 Serial Communication

Get QextSerialPort or QSerialDevice (which I preffer in my projects, because it got integrated in Qt5), have a look at the examples and simply use it. In both libraries you get some kind of port enumerator class which returns you a list of all configures serial ports. Only platform/device specific settings you will have to do manually (like getting RS485 in half-duplex mode on my current embedded project), but 'standard' problems are perfectly encapsulated in a QIODevice implementation. You can use both QextSerialPort and QSerialDevice like a file. Open it (instead of a filename you specify the device name ie. 'COM1' on Windows or '/dev/tty0' on Linux, depending on your configuration) and then read or write like you are doing it with an ordinary QFile, QBuffer, Qwhatever-inherits-from-QIODevice.

If you have any problems opening the port and communicating, don't hesitate to ask!:).