Results 1 to 7 of 7

Thread: Modbus, QextSerialPort and QTimer

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Unhappy Modbus, QextSerialPort and QTimer

    Hi,
    I'm developing an application that uses "QextSerialPort".
    I have implemented the RTU Modbus protocol.

    What I do is like:
    -Start a timer(interval 500ms) that when the SLOT is called, send a request to a Modbus Slave, start another timer to wait for a response

    -When the second timer triggers I read from Serial Port. Here always is there data because this timer is long enough. I don't really know why setting the time-out of the RS-232 i.e. 50 milliseconds and then calling directly "read" from it don't get me data(it has no data yet).

    -Then I package the data(char*) to a "CModbusResponse" and I emit this response throught a signal because this is the RTU Transport Layer and RTUModbusMaster will be the reciver of the response to do something with the response.

    Also I have 2 threads that capture images and process images. The timers are started by the main thread.

    If I execute the program without debuggin it, it seems to not work properly: it sends the requests but the second timer that will call the slot to read from RS-232 is not working(or it seems to not).

    If I insert debug points, It seems to work well. I'm sure that is working because I'm a Modbus MASTER that sends requsests to a Modbus SLAVE that have some LEDs showing the Digital Outs status(those are what I'm changing with the Modbus request).

    I know that is a bit complicated what I'm explaining but your help will be wellcome.

    I'm using Qt 4.3.0, QextSerialPort, Visual Studio 2003 .NET, Windows XP SP2



    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Modbus, QextSerialPort and QTimer

    I't would be better if you use one QTimer for example with 100ms period (it's quite enough to read data without taking much system resources), and do both transmit and receive with this timer. Use QTime to count elapsed time. You can check if there is some data in rs232's buffer using QextSerialPort::bytesAvailable() method because unfortunately QextSerialPort::readReady() signal doesn't work.
    Last edited by calhal; 9th January 2008 at 15:23. Reason: my poor english ;)
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Modbus, QextSerialPort and QTimer

    Hi,

    I've found what is happening.
    Taking a look at Modbus Master protocol I found that Master can only send one request at a time. So, if I send a request and another request before the Slave device sends a response, the Slave device don't know what is happening.

    So, what I'm gona do is to make CModbusRTUMaster as a QThread with a QMutex. Doing this I will block the CModbusRTUMaster to send another request until a response is arrived(timeout).

    Any ideas would be well recived, and if someone have developed the Modbus protocol in Qt it will be wonderfull to take a look at it. Maybe if my classes work well I will let you download to test and modify them to make them better(first of all I will have to translate it from spanish to english).

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Feb 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Modbus, QextSerialPort and QTimer

    Hi Oscar, i am trying to develop Mobus with Qextserialport too and i am starting now, i would like to help you developing your clases, i speak spanish, if you are interest you can email me to gmail, my user is erick.lglez
    I hope we can help ich other.
    Si puedes mandame lo que has hecho es para no comenzar desde zero...
    Muchas gracias de antemano
    Erick

  5. #5
    Join Date
    Aug 2009
    Posts
    2
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Re: Modbus, QextSerialPort and QTimer

    Dear Nyaw,
    about serial modbus comunication, I must to develop a simple program, similar ad datalogger, that every xx second send a request to slave, and capture response.

    I'm newbie from C++ and Qt, so what are the first steps to write this application?

    For example:
    1. create serial connection (what are the classes about that, or there is a documentation for that)
    2. send request to modbus format (modbus frame)
    3. read request and save data readed.
    4. is necessary to use thread or is more efficiently insert the applicatin as crontab.

    So, about modbus-serial connection - datalogging what are classes about?
    Where I can found manual about that.
    Or did you have some similar example from which I can view what is the procedure to create that application?

    All advice ore source code example will be appreciate!

  6. #6
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Modbus, QextSerialPort and QTimer

    Dear NyAw
    I'm a newbie of c++ and qt, and I need to create a modbus (rtu) communication and rs422 communication by serial and qt. I've seen the qextserialport library and i've tryed to run the example and activate an rs232 comunication successfully.

    Now can you give me some giude-lines or example to realize modbus rtu protocol and rs422 comunication?

    Thanks for your reply

    Michele

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Modbus, QextSerialPort and QTimer

    Hi,

    As I said, I can't share the libs because there is code that is not Modbus related mixed in the classes. Also it is full programmed in Catalan(language from Catalonia, a region of Spain). And finally, I have no time to rewrite them as many people wants.

    Take a look at:
    http://www.modbus.org/specs.php
    Here you can download the Modbus RTU and TCP specification.

    Also download and take a look at "jamod" source code. It is a JAVA Modbus implementation that I have used to develop my own classes.
    http://jamod.sourceforge.net/

    Hope this help you
    Òscar Llarch i Galán

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.