How to build python sample codes

Tutorial to execute python sample code and introduction to python package installation.

Install python package and sample code

1.Copy sample.tar.gz and library.tar.gz contained in the programing guide from your PC to ioThinx: For example, if the IP address of the ioThinx is "192.168.127.254", use the following command:

user@Linux:~$ scp sample.tar.gz moxa@192.168.127.254:~
user@Linux:~$ scp library.tar.gz moxa@192.168.127.254:~

2.Extract the sample code and library

moxa@Moxa:~$ tar zxvf sample.tar.gz
moxa@Moxa:~$ tar zxvf library.tar.gz

3.Install ioThinx-4530 Python API

moxa@Moxa:~$ cd library/iothinx/python
moxa@Moxa:~/library/iothinx/python$ ./install.sh
...
[ OK ] Install finished

4.Install serial plug-in in python (Note: Internet connection is required)

moxa@Moxa:~$ sudo pip install pyserial

5.The module will be installed to the standard location. For example

/usr/local/lib/python3.9/dist-packages

Tutorial

Python Interactive Mode

1.open python interactive windwos

moxa@Moxa:~$ sudo python3
[sudo] password for moxa:
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

2.Then in the Python Interactive Mode.

>>> from ioThinx_4530 import ioThinx_4530_API
>>> device = ioThinx_4530_API.ioThinx_4530_API()
>>> slot_num = device.ioThinx_Misc_GetModuleCount()
>>> print("slot_num = {}".format(slot_num))
slot_num = 12
>>> for slot in range(1,slot_num):
... print(device.ioThinx_Misc_GetModuleInfo(slot))
...
{'fwr_version': '0x1100', 'product_id': '0x8000a024', 'model_name': '45MR-1600', 'serial_number': 'TAHGB1014465', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
{'fwr_version': '0x1100', 'product_id': '0x8000a032', 'model_name': '45MR-1601-T', 'serial_number': 'TAHGB1021495', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
{'fwr_version': '0x1100', 'product_id': '0x8000a026', 'model_name': '45MR-2600', 'serial_number': 'TAHGB1019637', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
{'fwr_version': '0x1100', 'product_id': '0x8000a027', 'model_name': '45MR-2601', 'serial_number': 'TAHGB1017574', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
{'fwr_version': '0x1100', 'product_id': '0x8000a028', 'model_name': '45MR-2606', 'serial_number': 'TAHGB1016527', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
{'fwr_version': '0x1100', 'product_id': '0x8000a036', 'model_name': '45MR-2404-T', 'serial_number': 'TAHGB1014483', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
{'fwr_version': '0x1100', 'product_id': '0x8000a02e', 'model_name': '45MR-6810', 'serial_number': 'TAHIB1035236', 'fwr_build_date': datetime.datetime(2018, 12, 21, 17, 0)}
{'fwr_version': '0x1100', 'product_id': '0x8000a023', 'model_name': '45MR-6600', 'serial_number': 'TAHIB1035385', 'fwr_build_date': datetime.datetime(2018, 12, 21, 17, 0)}
{'fwr_version': '0x1008', 'product_id': '0x8000a02a', 'model_name': '45MR-3800', 'serial_number': 'TAHIB1035470', 'fwr_build_date': datetime.datetime(2018, 10, 31, 3, 0)}
{'fwr_version': '0x1008', 'product_id': '0x8000a02b', 'model_name': '45MR-3810', 'serial_number': 'TAHIB1034735', 'fwr_build_date': datetime.datetime(2018, 10, 31, 3, 0)}
{'fwr_version': '0x1002', 'product_id': '0x8000a02c', 'model_name': '45MR-7210', 'serial_number': 'MOXA89191230', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
>>>

API Example

Example misc.py

moxa@Moxa:~$ cd sample/iothinx/python
moxa@Moxa:~/sample/iothinx/python$ sudo python3 misc/misc.py
[sudo] password for moxa:

Result:

Module count = 12
Module slot = 1
Slot 1 Module Information:
Model Name: 45MR-1600
Serial Number: TAHGB1014465
Slot 1: Locating...
Press enter to stop locate.
Rotary switch state = 2
Push button state = 0
Set LED U1 to GREEN
Set LED U2 to RED
Press enter to clear.
Set process priority to 2
Press enter to continue.