mFi - Scripting with mPort Serial

Overview


Readers will learn about serial scripting with the Serial mPort device. Several example scripts are listed later in the article.

"Scripts" can be configured to be sent out the mPort Serial port. The scripts are "1-way", meaning the specified script is simply transmitted out the serial port and data is not received and interpreted (it does not behave like "Expect" scripting).

Multiple commands are separated by new-lines, and a 10 millisecond delay is inserted between multiple messages.

The default data format is ASCII. If the script begins with the string "MODBUSRTU " (MODBUS in all capitals plus a single space character), then the data is treated as a Modbus RTU message and the appropriate Modbus CRC is appended to the message before transmitting.

Scripts are sent from the mFi Controller to the mPort Serial using Telnet, so the mFi Controller should be inside the firewall (or if external to the firewall, the appropriate ports must be opened).

Examples


 

Some simple examples follow; please see your connected device's documentation for further information.

Advantech ADAM-4021

The ADAM-4021 takes ASCII commands and outputs the specified voltage.

Message Format

#AA(data)<cr>
AA = address = 01
(data) = 000 to FFF 

Example Messages

MessageVoltage Output
#01800 5 volts
#01F00 10 volts


Testequity Heat Chamber

The Testequity heat chamber has a serial port that can receive ASCII commands, such as commands to set the target temperature.

Example Messages

Message (including CRC)Target Temperature
0106012C00E2C9B6 22.6
0106012C01F449E8 50.0
0106012C03E84941 100.0

Temco T3-4A0

The Temco T3-4A0 is a Modbus device with 4 analog outputs (0-10v) and 8 relays. Commands can be sent from the mPort Serial to set analog voltage levels or to turn relays on or off.

http://www.temcocontrols.com/ftp/pdf/T3_Technical.pdf

Message Format

byte1: address (254 is default)
byte2: command (06 = write register)
byte3-4: address (AO1 = 108 => 0x006C, … , AO4 = 111)
bytes5-6: value (5v = 2048 => 0x0800)
bytes7-8: CRC

Example Messages

Message (CRC added by mPort)Voltage
FE06006C0200 1.25V
FE06006C0800 5V

 

5V Output

Dynamic Dimming

Multiple messages can be specified in a single script. In this example, the analog output of the T3-4A0 was tied to the input of a 0-10v dimmable fluorescent ballast. A time delay is added by the mPort Serial between each message, causing the light to gradually move to the target brightness.