
Page 23
Copyright © 2017 Matrix Technology Solutions Limited
www.matrixtsl.com
Controlling the MIAC
Using Python
MIAC AllCode
Instructional Guide
This very simple program activates relay Q1 using the API command
WriteRelay
,
but there
are a number of other lines of code before and after that command that may need more
explanation.
The first three lines of code import the library so you can use the API commands, then an
instance of the API is created and a communication channel to it is opened. The number
“3” represents the COM port that was created when the MIAC was paired.
It is important to close the COM port and at the end of the program we should do that
using a call to the
ComClose
API command.
Controlling multiple MIACs
By creating multiple instances of the
API, we can actually control more than
one at the same time. The program on
the right shows how this can be done.
Just like the first program, we start by
importing the MA library (note we are
also importing the “time” library too).
We then create 2 instances of the API
and open their COM ports.
The routine for drawing the square
should be self-explanatory.
Finally, both COM ports are closed.
Theoretically many MIACs can be
controlled simultaneously, but
unfortunately there is a practical limit
due to the capability of the computer’s
Bluetooth device. I have found 3 or 4 is
the realistic maximum.
Going further
We have shown only a few brief examples of how to control the MIAC AllCode using Python. If you
look at the API reference at the end of this document you will find many other commands that can
be used.
# Import the libraries
import
MA
import
time
#Create and open 2 MIACs
ma1 = MA.Create()
ma2 = MA.Create()
ma1.ComOpen(3)
ma2.ComOpen(4)
#control the Relays
ma1.WriteRelay(1,1)
ma2.WriteRelay(1,1)
# Close the COM ports
ma1.ComClose()
ma2.ComClose()
Summary of Contents for MI3932 MIAC AllCode
Page 1: ......