Skip to main content

Macro listening on a Serial Port

In an earlier post, I mentionned that we can easily create a macro that parse a serial and generate Omnicast event. 

General info on how to install macros

Configure it

The macro must be configured to use the right serial port on the system. The easiest way to uniquely identify a device in Omnicast is through Logical ID. You must now modify the script to use the proper serial port on your system.Using the Omnicast Config Tool

  1. In the Physical View, select the serial port you want to use.
  2. On the identity Tab, locate the field called "Logical ID" and remember its value.
  3. Select the macro again and jump in the code tab

Locate the line following line of code at the top and change the value 1 by the ID of your serial port.
' Serial port to listen to (Logical Number)
Const g_nSerialPortID = 1

How it works?

This macros is design to run until a schedule end or the user stop it.
When the macro starts, it creates its own custom event in the system, see
Sub CreateCustomEvents().

  • Connected to serial port: Raised as soon as we establish connectivity with the encoder
  • Length of received data: Event generated that contains the number of byte received
  • Received data: Event that contains the Bytes

Every time data is received on the serial port the method Sub Serial_OnData(Handle, Data) is called. Currently this generates a 2 custom events (Lenght and Received) and attached the byte receive in the description. The code in Serial_OnData could be easily modified to generate specific events on specific data or simply just call some methode from the Matrix SDK.

I hope it helps!