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
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 
36 4.Install serial plug-in in python (Note: Internet connection is required)
37 
38 ```
39 moxa@Moxa:~$ pip3 install pyserial
40 ```
41 
42 
43 5.The module will be installed to the standard location. For example
44 
45 ```
46 /usr/local/lib/python3.5/dist-packages
47 ```
48 
49 # Tutorial
50 ## Python Interactive Mode
51 
52 1.open python interactive windwos
53 
54 ```
55 moxa@Moxa:~$ sudo python3
56 [sudo] password for moxa:
57 
58 Python 3.5.3 (default, Sep 27 2018, 17:25:39)
59 [GCC 6.3.0 20170516] on linux
60 Type "help", "copyright", "credits" or "license" for more information.
61 >>>
62 
63 ```
64 
65 2.Then in the Python Interactive Mode.
66 
67 ```
68 >>> from ioThinx_4530 import ioThinx_4530_API
69 >>> device = ioThinx_4530_API.ioThinx_4530_API()
70 >>> slot_num = device.ioThinx_Misc_GetModuleCount()
71 >>> print("slot_num = {}".format(slot_num))
72 slot_num = 12
73 
74 >>> for slot in range(1,slot_num):
75 ... print(device.ioThinx_Misc_GetModuleInfo(slot))
76 ...
77 
78 {'fwr_version': '0x1100', 'product_id': '0x8000a024', 'model_name': '45MR-1600', 'serial_number': 'TAHGB1014465', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
79 {'fwr_version': '0x1100', 'product_id': '0x8000a032', 'model_name': '45MR-1601-T', 'serial_number': 'TAHGB1021495', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
80 {'fwr_version': '0x1100', 'product_id': '0x8000a026', 'model_name': '45MR-2600', 'serial_number': 'TAHGB1019637', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
81 {'fwr_version': '0x1100', 'product_id': '0x8000a027', 'model_name': '45MR-2601', 'serial_number': 'TAHGB1017574', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
82 {'fwr_version': '0x1100', 'product_id': '0x8000a028', 'model_name': '45MR-2606', 'serial_number': 'TAHGB1016527', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
83 {'fwr_version': '0x1100', 'product_id': '0x8000a036', 'model_name': '45MR-2404-T', 'serial_number': 'TAHGB1014483', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
84 {'fwr_version': '0x1100', 'product_id': '0x8000a02e', 'model_name': '45MR-6810', 'serial_number': 'TAHIB1035236', 'fwr_build_date': datetime.datetime(2018, 12, 21, 17, 0)}
85 {'fwr_version': '0x1100', 'product_id': '0x8000a023', 'model_name': '45MR-6600', 'serial_number': 'TAHIB1035385', 'fwr_build_date': datetime.datetime(2018, 12, 21, 17, 0)}
86 {'fwr_version': '0x1008', 'product_id': '0x8000a02a', 'model_name': '45MR-3800', 'serial_number': 'TAHIB1035470', 'fwr_build_date': datetime.datetime(2018, 10, 31, 3, 0)}
87 {'fwr_version': '0x1008', 'product_id': '0x8000a02b', 'model_name': '45MR-3810', 'serial_number': 'TAHIB1034735', 'fwr_build_date': datetime.datetime(2018, 10, 31, 3, 0)}
88 {'fwr_version': '0x1002', 'product_id': '0x8000a02c', 'model_name': '45MR-7210', 'serial_number': 'MOXA89191230', 'fwr_build_date': datetime.datetime(2018, 12, 19, 15, 0)}
89 >>>
90 
91 ```
92 
93 ## API Example
94 
95 Example misc.py
96 
97 ```
98 moxa@Moxa:~$ cd sample/iothinx/python
99 moxa@Moxa:~/sample/iothinx/python$ sudo python3 misc/misc.py
100 [sudo] password for moxa:
101 ```
102 
103 Result:
104 
105 ```
106 Module count = 12
107 Module slot = 1
108 Slot 1 Module Information:
109 Model Name: 45MR-1600
110 Serial Number: TAHGB1014465
111 Slot 1: Locating...
112 Press enter to stop locate.
113 Rotary switch state = 2
114 Push button state = 0
115 Set LED U1 to GREEN
116 Set LED U2 to RED
117 Press enter to clear.
118 Set process priority to 2
119 Press enter to continue.
120 ```
121