QSerialPort, communicating through RS485
-
Hi @Corpse0327, and welcome to the Qt Dev Net!
QSerialPort was designed for RS-232. Unfortunately, RS-232 and RS-485 are not compatible.
You need to find a different way to talk to your fuel pump, as Qt does not provide the features you need.EDIT: They are hardware-incompatible, but might be software-compatibleGood luck
-
Ohh... :(
Can you give me a link at least to start for programming with RS485
-
Sorry, I got mixed up: RS-232 and RS-485 are electrically incompatible, but if I'm not mistaken the software protocol might be ok. (I'm not 100% sure though)
See http://doc.qt.io/qt-5/qtserialport-examples.html for examples
Questions:
- Do you have an RS-485 port on your PC?
- Is there anyone in your company with experience that you can ask?
- How did you find out about QSerialPort?
-
- There is a converter which converts RS485 to a usb
- No :(
- I read articles more than 50, don't know when i came across it. PS. i was already planning to use Qt even without knowing QSerialPort class.
-
Ok, the first thing to do is check if Qt can see your USB to RS-485 converter.
- Plug in your converter
- Make sure it can be see in Device Manager (I assume you're using Windows)
- If #2 is ok, then run the following code:
#include <QSerialPortInfo> #include <QDebug> // ... auto ports = QSerialPortInfo::availablePorts(); for (const QSerialPortInfo& info : ports) qDebug() << info.portName();
See http://doc.qt.io/qt-5/qserialportinfo.html for other functions you can check, other than
portName()
-
Ok, thanks
-
Hi, RS485 does only specify the electrical interface but not any protocol. So first of all you need to know the protocol that the fuel pump speaks.
-
Having done this myself, MANY times here is my advice:
Yes the data is unique to every device. There is no standard format, speed, or serial port data format. All devices pick and choose so you cannot assume code from device A would have any hope of working with device B from a different manufacturer.
As was mentioned RS-485 defines the electrical communication. Provided you have a good 485 to 232 adapter it will look like RS-232 data to you both for send and receive. You mentioned you have an adapter from 485 to USB. This adapter will need to represent itself as a COM port for QSerialPort to access it. Ask JKSH says above, plug it in, then look for a new COM port using the available functions.
The first place to start is to gather as much data as you can gather. Find the manual, search for the part number, somewhere hope that you can find some info about what to expect.
Failing that you just have to do some trial and error:
-
Try common baud rates: 4800, 9600, 19200, 38400 and within those baud rates you'll need to try different data sizes 7 and 8 and different parities. When you have it wrong the data from the pump will be gibberish. When you get it right it may still not look like much but it should become more recognizable.
-
Once you think you are onto the right speed and other settings see if you can actually figure out where the desired data is in the number. It could be ACSII so you could easily view it or it could be binary where having the manual will be a big help. But even if you can't find the manual if you can get the device to start sending you data then you can examine the input bytes for a change as your pump changes. Sometimes you can use that to figure out what kind of data you are getting and how to convert it.
The simple fact is that if you have the manual about the protocol most of this can be done in a couple of hours. If you don't then it is a bunch of trial and error and it could take you days or weeks to try enough combinations to end up with some data and then you've got to interpret it.
-
-
Thank you so much guys.
I really appreciate the help. It really helped me a lot.
-
For stuff like this I made up some hardware to allow me to monitor the communications. If you have an existing working system and you do not have information about the protocol this is the best way to figure out what you need to send and expect for a response. Likely the communication would include some sort of target device address or identification as a minimum.
RS-232 is not compatible on the electrical side. It might appear as a serial port through software in which case QSerialPort should work.
-
Rondog is right. I've done this before as well.
You can purchase expensive RS-232 sniffers and monitors but frankly you can generally do what you need using a spare computer with two serial ports and some software.
It takes a bit of work but you write software that reads all incoming data off one port and after logging it some how writes it out to the other port.
If your device uses hardware signals like CTS, RTS, etc you will need to have your software read those changes and translate them over to the output port.
Of course most serial stuff is bi-directional so you'd need to have a similar process going the other way.
As Rondog says if you are into building hardware you can build something that does all of this and perhaps sends the logged output to a serial port on your computer or over USB.
-
@SysTech said in QSerialPort, communicating through RS485:
Having done this myself, MANY times here is my advice:
Yes the data is unique to every device. There is no standard format, speed, or serial port data format. All devices pick and choose so you cannot assume code from device A would have any hope of working with device B from a different manufacturer.
As was mentioned RS-485 defines the electrical communication. Provided you have a good 485 to 232 adapter it will look like RS-232 data to you both for send and receive. You mentioned you have an adapter from 485 to USB. This adapter will need to represent itself as a COM port for QSerialPort to access it. Ask JKSH says above, plug it in, then look for a new COM port using the available functions.
The first place to start is to gather as much data as you can gather. Find the manual, search for the part number, somewhere hope that you can find some info about what to expect.
Failing that you just have to do some trial and error:
-
Try common baud rates: 4800, 9600, 19200, 38400 and within those baud rates you'll need to try different data sizes 7 and 8 and different parities. When you have it wrong the data from the pump will be gibberish. When you get it right it may still not look like much but it should become more recognizable.
-
Once you think you are onto the right speed and other settings see if you can actually figure out where the desired data is in the number. It could be ACSII so you could easily view it or it could be binary where having the manual will be a big help. But even if you can't find the manual if you can get the device to start sending you data then you can examine the input bytes for a change as your pump changes. Sometimes you can use that to figure out what kind of data you are getting and how to convert it.
The simple fact is that if you have the manual about the protocol most of this can be done in a couple of hours. If you don't then it is a bunch of trial and error and it could take you days or weeks to try enough combinations to end up with some data and then you've got to interpret it.
As far as I understand, RS 232 and RS 485 are electrically different, but from the Qt's point of view, QSerialPort can handle both of these serial ports right ? QSerialPort is sufficient for RS 485 ?
Thank you.
-
-
Hi friend how are you ?
See my project using Qt QSerialPort with RS485
https://github.com/JoaoPagotto/Net485
Estou usando o conversor RS485 com chip CH340, isso funciona bem, outros conversores causam muitos erros.
I hope I have helped.
-
@joaopagotto said in QSerialPort, communicating through RS485:
Hi friend how are you ?
See my project using Qt QSerialPort with RS485
https://github.com/JoaoPagotto/Net485
Estou usando o conversor RS485 com chip CH340, isso funciona bem, outros conversores causam muitos erros.
I hope I have helped.
Thank you. I will check your repository.
Can you confirm that QtSerialPort can handle both Rs 232 and Rs 485 ? -
@seltra2 said in QSerialPort, communicating through RS485:
Can you confirm that QtSerialPort can handle both Rs 232 and Rs 485
I confirm QSerialPort works on both RS232 and RS485, I use this normally. Take a look at my source, and see how things work.
I've put more examples, these examples I use with RS485. I hope I have helped and good luck. But remembering that I recommend the use of the converters with the CH340 chip, the FTDI are too problematic.
-
@joaopagotto http://www.simcore.com.br/downloads/QtForum/53877/ this link is not available