2014年7月2日 星期三

Modbus/TCP in Android with Python, using modbus_tk

in last case, we use a TCP socket to send Modbus/TCP commnad
and then print out the result to test Modbus/TCP in android

now, we will use a good library for Modbus ==> modbus_tk
you may can find three modbus solutions:
1. pymodbus: it's a good library for python with huge structure...
  it support Modbus/RTU and Modbus/TCP, but I don't use it here.
  because it always need pySerial library. If you can't put the pySerial library into your system, the pymodbus don't work...

2. MinimalModbus: a minimal modbus library. it just support Modbus/RTU.

3. modbus_tk: it's a nice modbus library!! it support Modbus/RTU and Modbus/TCP
  if you don't use Modbus/RTU, you have no need to install pySerial library! (good!)

so finally, I choose modbus_tk to develop modbus program

the step to demonstrate:
1. download modbus-tk here, and then unzip modbus-tk-0.4.2.zip into modbus_tk folder.
2. download mbTcpTest2.py here.
3. the screenshot as below:
in modbus_tk
4. put all the file into your android phone with SL4A, and the execute it!!

enjoy it!!~~





2014年7月1日 星期二

Modbus/TCP with Android and Python

here I had write a Python program with SL4A to demonstrate Modbus/TCP.
there is no any Modbus library used in this case, because I just want show a simple case for Modbus/TCP.
of course, I will use Modbus library later. it will be more easy~

some about this program:
1. data = pack('<BBBBBB', 1, 2, 0, 0, 0, 6)
it's the Modbus/TCP header
2. data = data + pack('<BBBBBB', 1, 4, 0, 0, 0, 4)
it's the Function code 4, and to read 4 registers

here to download