Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerialPort, communicating through RS485
QtWS25 Last Chance

QSerialPort, communicating through RS485

Scheduled Pinned Locked Moved General and Desktop
rs485qserialport
17 Posts 8 Posters 18.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Corpse0327
    wrote on last edited by
    #1

    Hi everyone

    I am tasked with writing a simple program for communicating with a fuel-pump. I need to get information from it.

    I never communicated with a device before. This is my first time writing a program for communication with a device. I have read lots of articles about RS485 communication but people mostly writes about how it works not much detail about how to communicate with the device using it. So i am having lots of confusions.

    I have a few questions regarding RS485 communication.

    1. How do i tell device to give me the information i want
    2. How do i read info sent from device(probably using ReadData, but want to be sure)
    3. The data that is given to me contains what? Is it unique for each device or there is a standard for this

    Can you give a little example also. :)

    Thanks in advance.

    S 1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      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-compatible

      Good luck

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Corpse0327
        wrote on last edited by Corpse0327
        #3

        Ohh... :(

        Can you give me a link at least to start for programming with RS485

        JKSHJ 1 Reply Last reply
        0
        • C Corpse0327

          Ohh... :(

          Can you give me a link at least to start for programming with RS485

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          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:

          1. Do you have an RS-485 port on your PC?
          2. Is there anyone in your company with experience that you can ask?
          3. How did you find out about QSerialPort?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Corpse0327
            wrote on last edited by
            #5
            1. There is a converter which converts RS485 to a usb
            2. No :(
            3. 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.
            JKSHJ 1 Reply Last reply
            0
            • C Corpse0327
              1. There is a converter which converts RS485 to a usb
              2. No :(
              3. 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.
              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              Ok, the first thing to do is check if Qt can see your USB to RS-485 converter.

              1. Plug in your converter
              2. Make sure it can be see in Device Manager (I assume you're using Windows)
              3. 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()

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              1
              • C Offline
                C Offline
                Corpse0327
                wrote on last edited by
                #7

                Ok, thanks

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  1
                  • C Corpse0327

                    Hi everyone

                    I am tasked with writing a simple program for communicating with a fuel-pump. I need to get information from it.

                    I never communicated with a device before. This is my first time writing a program for communication with a device. I have read lots of articles about RS485 communication but people mostly writes about how it works not much detail about how to communicate with the device using it. So i am having lots of confusions.

                    I have a few questions regarding RS485 communication.

                    1. How do i tell device to give me the information i want
                    2. How do i read info sent from device(probably using ReadData, but want to be sure)
                    3. The data that is given to me contains what? Is it unique for each device or there is a standard for this

                    Can you give a little example also. :)

                    Thanks in advance.

                    S Offline
                    S Offline
                    SysTech
                    wrote on last edited by SysTech
                    #9

                    @Corpse0327

                    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:

                    1. 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.

                    2. 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.

                    S 1 Reply Last reply
                    3
                    • C Offline
                      C Offline
                      Corpse0327
                      wrote on last edited by
                      #10

                      Thank you so much guys.

                      I really appreciate the help. It really helped me a lot.

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Rondog
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        1
                        • S Offline
                          S Offline
                          SysTech
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          1
                          • S SysTech

                            @Corpse0327

                            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:

                            1. 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.

                            2. 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.

                            S Offline
                            S Offline
                            seltra2
                            wrote on last edited by
                            #13

                            @SysTech said in QSerialPort, communicating through RS485:

                            @Corpse0327

                            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:

                            1. 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.

                            2. 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.

                            1 Reply Last reply
                            0
                            • joaopagottoJ Offline
                              joaopagottoJ Offline
                              joaopagotto
                              wrote on last edited by
                              #14

                              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.

                              http://www.ebay.com/itm/CH340-USB-To-RS485-USB-485-Converter-Adapter-Module-Support-Win7-XP-Vista-Linux-/263050607176

                              I hope I have helped.

                              S 1 Reply Last reply
                              1
                              • joaopagottoJ joaopagotto

                                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.

                                http://www.ebay.com/itm/CH340-USB-To-RS485-USB-485-Converter-Adapter-Module-Support-Win7-XP-Vista-Linux-/263050607176

                                I hope I have helped.

                                S Offline
                                S Offline
                                seltra2
                                wrote on last edited by
                                #15

                                @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.

                                http://www.ebay.com/itm/CH340-USB-To-RS485-USB-485-Converter-Adapter-Module-Support-Win7-XP-Vista-Linux-/263050607176

                                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 ?

                                1 Reply Last reply
                                0
                                • joaopagottoJ Offline
                                  joaopagottoJ Offline
                                  joaopagotto
                                  wrote on last edited by
                                  #16

                                  @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.

                                  http://www.simcore.com.br/downloads/QtForum/53877/

                                  1 Reply Last reply
                                  0
                                  • E Offline
                                    E Offline
                                    ekiz_osman
                                    wrote on last edited by
                                    #17

                                    @joaopagotto http://www.simcore.com.br/downloads/QtForum/53877/ this link is not available

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved