How to use python sample codes

Introdution to python package installation and tutorial to execute python sample code.

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:

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

2.Extract the sample code and library

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

3.Install

1 moxa@Moxa:~$ cd library/python_package
2 moxa@Moxa:~$ ./install.sh
3 ...
4 [ OK ] Install finished

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

1 /usr/local/lib/python3.5/dist-packages

Tutorial

Python Interactive Mode

1.open python interactive windwos

1 moxa@Moxa:~$ sudo python3
2 [sudo] password for moxa:
3 
4 Python 3.5.3 (default, Sep 27 2018, 17:25:39)
5 [GCC 6.3.0 20170516] on linux
6 Type "help", "copyright", "credits" or "license" for more information.
7 >>>

2.Then in the Python Interactive Mode.

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

API Example

Example misc.py

1 moxa@Moxa:~$ cd sample/python-sample
2 moxa@Moxa:~/sample/python-sample$ sudo python3 misc/misc.py
3 [sudo] password for moxa:

Result:

1 Module count = 12
2 Module slot = 1
3 Slot 1 Module Information:
4 Model Name: 45MR-1600
5 Serial Number: TAHGB1014465
6 Slot 1: Locating...
7 Press enter to stop locate.
8 Rotary switch state = 2
9 Push button state = 0
10 Set LED U1 to GREEN
11 Set LED U2 to RED
12 Press enter to clear.
13 Set process priority to 2
14 Press enter to continue.