Using modbus-tk on a stand-alone GSM module

248 views
Skip to first unread message

Ren

unread,
Jun 30, 2011, 6:38:23 AM6/30/11
to modbus-tk
HI. I'm trying to run the modbus-tk module on a GSM modem, which is
capable of running Python scripts. Modem's task is to read
measurements from sensors via Modbus protocol and then process/send
them. I successfully read measurements running modbus-tk on PC, but in
case of this GSM modem some code should probably be changed, since
reading and writing data from/to serial port on modem is done through
its special interface with defined methods. What classes/functions
should I rewrite in order to successfully run the modbus-tk on such
modem? In other words, what functions are responsible for sending data
to and reading it from serial port? Thank you.

Ardison Nicolas

unread,
Jun 30, 2011, 7:50:01 AM6/30/11
to modb...@googlegroups.com
Hi, i'm not the responsable of this libraries, i used this one time, if don't remember bad, modbus-tk uses Twisted libraries to send data.
--
Nicolas G. Ardison
nicol...@gmail.com

Antes de imprimir este mensaje, asegúrese de que es necesario. El medio ambiente está en nuestras manos.
Before printing, think about the environment.

Luc JEAN

unread,
Jun 30, 2011, 8:01:09 AM6/30/11
to modb...@googlegroups.com
Hello,
The serial communication is managed by the pyserial lib.
I think that if you create a class that mimick the pyserial.SerialBase public interface (see http://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/serial/serialutil.py?revision=377&view=markup) that should work ok.
There is a few functions to implement (open, read, write, close, isOpen ...) and member variables to provide (interCharTimeout, timeout ...) Check the RtuMaster class in modbus_rtu.py
Then pass an instance of this class as 1st arg of the RtuMaster constructor. I think there is nothing to change in modbus-tk code.
Best
luc

PS: For my information, What kind of GSM modem to you use?
 

2011/6/30 Ren <gan...@gmail.com>

Luc JEAN

unread,
Jun 30, 2011, 8:04:57 AM6/30/11
to modb...@googlegroups.com
Hello Nicolas,
For TCP stuff, modbus-tk doesn't use Twisted but the standard socket lib in order to limit dependencies. I agree that Twisted is more capable and efficient but I think that socket lib is enough in this case.
For RTU, modbus-tk is using pyserial.
Best
luc

2011/6/30 Ardison Nicolas <nicol...@gmail.com>



--
http://www.apidev.fr

Ren

unread,
Jul 6, 2011, 3:23:30 AM7/6/11
to modbus-tk
Thank you for your replies. I was dealing with some other issues last
week and almost forgot about this topic. The modem is Telit GC864 and
operating on starter kit board provided by RoundSolutions. I will post
later after I try to apply your advices. Thank you.

On Jun 30, 3:01 pm, Luc JEAN <luc.j...@gmail.com> wrote:
> Hello,
> The serial communication is managed by the pyserial lib.
> I think that if you create a class that mimick the pyserial.SerialBase public
> interface (seehttp://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/se...)
> that should work ok.
> There is a few functions to implement (open, read, write, close, isOpen ...)
> and member variables to provide (interCharTimeout, timeout ...) Check the
> RtuMaster class in modbus_rtu.py
> Then pass an instance of this class as 1st arg of the RtuMaster constructor.
> I think there is nothing to change in modbus-tk code.
> Best
> luc
>
> PS: For my information, What kind of GSM modem to you use?
>
> 2011/6/30 Ren <gang...@gmail.com>

Ren

unread,
Jul 6, 2011, 4:08:23 AM7/6/11
to modbus-tk
I've just found the following information from the module's Python
documentation.
"Most of Python Library Modules are not supported because they depend
on Operative
System. Basically if a library module imports OS that module is not
supported. Some
library modules do not depend on Operative System and are supported.
An example is
string.py."
Does it mean, that using pyserial is impossible? Or will it be enough
to write only the class you were talking about, similar to SerialBase?

On Jun 30, 3:01 pm, Luc JEAN <luc.j...@gmail.com> wrote:
> Hello,
> The serial communication is managed by the pyserial lib.
> I think that if you create a class that mimick the pyserial.SerialBase public
> interface (seehttp://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/se...)
> that should work ok.
> There is a few functions to implement (open, read, write, close, isOpen ...)
> and member variables to provide (interCharTimeout, timeout ...) Check the
> RtuMaster class in modbus_rtu.py
> Then pass an instance of this class as 1st arg of the RtuMaster constructor.
> I think there is nothing to change in modbus-tk code.
> Best
> luc
>
> PS: For my information, What kind of GSM modem to you use?
>
> 2011/6/30 Ren <gang...@gmail.com>

Ren

unread,
Jul 6, 2011, 4:46:24 AM7/6/11
to modbus-tk
As an update, this module is able to use its serial port, it has so-
called SER interface, which allows sending/reading data to/from serial
port. That's why I think it is possible to rewrite the modbus-tk, so
it will use those SER methods (mainly SER.send() and SER.receive())
instead of pyserial. Does it make sense?

On Jun 30, 3:01 pm, Luc JEAN <luc.j...@gmail.com> wrote:
> Hello,
> The serial communication is managed by the pyserial lib.
> I think that if you create a class that mimick the pyserial.SerialBase public
> interface (seehttp://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/se...)
> that should work ok.
> There is a few functions to implement (open, read, write, close, isOpen ...)
> and member variables to provide (interCharTimeout, timeout ...) Check the
> RtuMaster class in modbus_rtu.py
> Then pass an instance of this class as 1st arg of the RtuMaster constructor.
> I think there is nothing to change in modbus-tk code.
> Best
> luc
>
> PS: For my information, What kind of GSM modem to you use?
>
> 2011/6/30 Ren <gang...@gmail.com>

Ren

unread,
Jul 8, 2011, 6:51:31 AM7/8/11
to modbus-tk
Hi. Still waiting for your reply, which will be highly appreciated.
From my research of this topic I understand the following.
modbus_rtu.RtuMaster uses serial type object. This serial class is
inherited from either Win32Serial, PosixSerial or JavaSerial, which in
their turn inherit from SerialBase class, which I should change.
However those intermediary classes import some other libraries (win32
for example) which will probably not be accessible on the modem. I
should describe in more details, what the module is capable of. It has
Python interpreter with ~2 Mb of flash memory and ~1 Mb RAM. It has 2
serial ports, ASC0 and ASC1 which are controlled from python by SER
and SER2 classes.
Here's the list of methods:
SER.send(string)
SER.receive(timeout)
SER.read()
SER.sendbyte(byte)
SER.receivebyte(timeout)
SER.readbyte()
SER.set_speed(speed, <char format>)
SER.setDCD(DCD_value)
SER.setCTS(CTS_value)
SER.setDSR(DSR_value)
SER.setRI(RI_value)
SER.getRTS()
SER.getDTR()

More detailed info can be found here:
http://www.roundsolutions.com/techdocs/python/Easy_Script_Python_r13.pdf

I really hope you could give me an idea, where should I apply those,
to be able to use modbus-tk on this modem. Thank you.

On Jun 30, 3:01 pm, Luc JEAN <luc.j...@gmail.com> wrote:
> Hello,
> The serial communication is managed by the pyserial lib.
> I think that if you create a class that mimick the pyserial.SerialBase public
> interface (seehttp://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/se...)
> that should work ok.
> There is a few functions to implement (open, read, write, close, isOpen ...)
> and member variables to provide (interCharTimeout, timeout ...) Check the
> RtuMaster class in modbus_rtu.py
> Then pass an instance of this class as 1st arg of the RtuMaster constructor.
> I think there is nothing to change in modbus-tk code.
> Best
> luc
>
> PS: For my information, What kind of GSM modem to you use?
>
> 2011/6/30 Ren <gang...@gmail.com>

Luc JEAN

unread,
Jul 8, 2011, 9:07:55 AM7/8/11
to modb...@googlegroups.com
Hello,
Sorry fot late answer. I didn't catch what you were expecting something and I thought you were trying by yourself.
I looked at this modem and I find it very interesting. Unfortunately I dont have one of this unit in my hands (I may buy it one in future but not yet). So I can't confirm my thoughts.
I think that you only need to create a class with the same interface than the BaseSerial of pyserial. Python is a dynamic language and support duck typing, so there is no need to ihnerit from this class. Providing the required functions is enough. So you shouldn't have to worry about external packages like win32.
I think that the serial API of the modem makes possible to write this class. That shouldn't be too difficult if you know Python.
I can't say more at the moment. I would need to get a modem and spend a little time to look at this issue in details.
Best Regards
luc

2011/7/8 Ren <gan...@gmail.com>



--
http://www.apidev.fr
Reply all
Reply to author
Forward
0 new messages