- Main
- Tutorials
- Library
- Samples

- File List
- Globals

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