tutorial/iothinx/python/python.md
Go to the documentation of this file.
1 How to build python sample codes {#python}
2 ----
3 @brief Tutorial to execute python sample code and introduction to python package installation.
4 
5 
6 
7 # Install python package and sample code
8 
9 1.Copy sample.tar.gz and library.tar.gz contained in the programing guide from your PC to ioThinx:
10 For example, if the IP address of the ioThinx is "192.168.127.254", use the following command:
11 
12 ```
13 user@Linux:~$ scp sample.tar.gz moxa@192.168.127.254:~
14 user@Linux:~$ scp library.tar.gz moxa@192.168.127.254:~
15 ```
16 
17 
18 2.Extract the sample code and library
19 
20 ```
21 moxa@Moxa:~$ tar zxvf sample.tar.gz
22 moxa@Moxa:~$ tar zxvf library.tar.gz
23 ```
24 
25 3.Install ioThinx-4530 Python API
26 
27 ```
28 moxa@Moxa:~$ cd library/iothinx/python
29 moxa@Moxa:~/library/iothinx/python$ ./install.sh
30 
31 ...
32 [ OK ] Install finished
33 ```
34 
35 4.Install serial plug-in in python (Note: Internet connection is required)
36 
37 ```
38 moxa@Moxa:~$ sudo pip install pyserial
39 ```
40 
41 5.The module will be installed to the standard location. For example
42 
43 ```
44 /usr/local/lib/python3.9/dist-packages
45 ```
46 
47 # Tutorial
48 ## Python Interactive Mode
49 
50 1.open python interactive windwos
51 
52 ```
53 moxa@Moxa:~$ sudo python3
54 [sudo] password for moxa:
55 
56 Python 3.9.2 (default, Feb 28 2021, 17:03:44)
57 [GCC 10.2.1 20210110] on linux
58 Type "help", "copyright", "credits" or "license" for more information.
59 >>>
60 
61 ```
62 
63 2.Then in the Python Interactive Mode.
64 
65 ```
66 >>> from ioThinx_4530 import ioThinx_4530_API
67 >>> device = ioThinx_4530_API.ioThinx_4530_API()
68 >>> slot_num = device.ioThinx_Misc_GetModuleCount()
69 >>> print("slot_num = {}".format(slot_num))
70 slot_num = 12
71 
72 >>> for slot in range(1,slot_num):
73 ... print(device.ioThinx_Misc_GetModuleInfo(slot))
74 ...
75 
76 {'fwr_version': '0x1100', 'product_id': '0x8000a024', 'model_name': '45MR-1600', 'serial_number': 'TAHGB1014465', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
77 {'fwr_version': '0x1100', 'product_id': '0x8000a032', 'model_name': '45MR-1601-T', 'serial_number': 'TAHGB1021495', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
78 {'fwr_version': '0x1100', 'product_id': '0x8000a026', 'model_name': '45MR-2600', 'serial_number': 'TAHGB1019637', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
79 {'fwr_version': '0x1100', 'product_id': '0x8000a027', 'model_name': '45MR-2601', 'serial_number': 'TAHGB1017574', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
80 {'fwr_version': '0x1100', 'product_id': '0x8000a028', 'model_name': '45MR-2606', 'serial_number': 'TAHGB1016527', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
81 {'fwr_version': '0x1100', 'product_id': '0x8000a036', 'model_name': '45MR-2404-T', 'serial_number': 'TAHGB1014483', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
82 {'fwr_version': '0x1100', 'product_id': '0x8000a02e', 'model_name': '45MR-6810', 'serial_number': 'TAHIB1035236', 'fwr_build_date': datetime.datetime(2018, 12, 21, 17, 0)}
83 {'fwr_version': '0x1100', 'product_id': '0x8000a023', 'model_name': '45MR-6600', 'serial_number': 'TAHIB1035385', 'fwr_build_date': datetime.datetime(2018, 12, 21, 17, 0)}
84 {'fwr_version': '0x1008', 'product_id': '0x8000a02a', 'model_name': '45MR-3800', 'serial_number': 'TAHIB1035470', 'fwr_build_date': datetime.datetime(2018, 10, 31, 3, 0)}
85 {'fwr_version': '0x1008', 'product_id': '0x8000a02b', 'model_name': '45MR-3810', 'serial_number': 'TAHIB1034735', 'fwr_build_date': datetime.datetime(2018, 10, 31, 3, 0)}
86 {'fwr_version': '0x1002', 'product_id': '0x8000a02c', 'model_name': '45MR-7210', 'serial_number': 'MOXA89191230', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
87 >>>
88 
89 ```
90 
91 ## API Example
92 
93 Example misc.py
94 
95 ```
96 moxa@Moxa:~$ cd sample/iothinx/python
97 moxa@Moxa:~/sample/iothinx/python$ sudo python3 misc/misc.py
98 [sudo] password for moxa:
99 ```
100 
101 Result:
102 
103 ```
104 Module count = 12
105 Module slot = 1
106 Slot 1 Module Information:
107 Model Name: 45MR-1600
108 Serial Number: TAHGB1014465
109 Slot 1: Locating...
110 Press enter to stop locate.
111 Rotary switch state = 2
112 Push button state = 0
113 Set LED U1 to GREEN
114 Set LED U2 to RED
115 Press enter to clear.
116 Set process priority to 2
117 Press enter to continue.
118 ```
119