
Page 22
Copyright © 2017 Matrix Technology Solutions Limited
www.matrixtsl.com
Controlling the MIAC
Using Python
MIAC AllCode
Instructional Guide
Python is a widely-used computer programming language that is
available on many systems. It is free, easy to learn and fun to use.
This section will show you how to set up Python for use with MIAC
AllCode. It is assumed you have a basic working knowledge of Python
itself. If not, there are many good resources on the internet if you wish
to learn this language.
Set-up
The first thing you need is to make sure Python is installed on your computer. It is usually
installed by default on a Raspberry Pi, but for Windows and other devices you will probably need
to download and install it from
http://www.python.org.
There are two versions of Python, 2 and 3, and either can be used to control the MIAC AllCode, but
you may wish to ensure you have the latest version installed.
In addition to Python itself, you will also need to install the PySerial library. This can be
found on GitHub:
https://github.com/pyserial/pyserial
or can be downloaded on a Linuxbased
device using the following command in a terminal window:
sudo apt-get install python-serial
Now that Python and the PySerial library are installed, you should download the MIAC AllCode
Python library from here:
https://www.matrixtsl.com/allcode/resources/
You will find examples and other resources on this page that will help you control the MIAC
in Python and many other languages.
My first Python program
import
MA
ma = MA.Create()
ma.ComOpen(3)
ma.WriteRelay(1,1)
ma.ComClose()
# Import the MIAC AllCode library
# Create an instance of the API
# Open the COM port
# Switch On Relay 1
# Close the COM port
Содержание MI3932 MIAC AllCode
Страница 1: ......