PDA

View Full Version : Modbus, QextSerialPort and QTimer



^NyAw^
9th January 2008, 13:08
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,

calhal
9th January 2008, 15:21
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.

^NyAw^
9th January 2008, 16:22
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,

ericklg
6th February 2009, 22:14
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

photovoltaico
14th August 2009, 19:10
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! :o

cia.michele
27th October 2009, 09:47
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

^NyAw^
27th October 2009, 16:14
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