ComManager - fdechaumont/micecraft GitHub Wiki

This object handles the COM port communication of a device.

It handles:

  • Sending / receiving strings or bytes from device
  • COM Port disconnect: if the device gets disconnected, the ComManager will try to reconnect to the device.
  • Alarms: If the COM port is lost or disconnected, this will trigger and alarm that can be displayed on the GUI, and mail will be sent if configured.
  • Auto release COM port on exit.
  • Buffers communication to send complete message to your code.

Tech note:

  • In string mode, your device should send string finished with \n char.
  • A \n char is added to the message you send to your devices.

General use:

The ComManager is instantiated with the com name/number ( on windows that will be "COM20", on linux "/dev/ttyS0" for instance ).

from micecraft.soft.ComManager.ComManager import ComManager

# this is your listener (or your callback)
def comListener( event ):
    # you will receive message (DeviceEvent) from your device here
    print( event )

# create the ComManager
comManager = ComManager( comPort, comListener )

# send a message to your device
comManager.send("This is a message to my device")

# if the device sends you a message, you will receive it in your comListener function.

Adding an alarm

If you want to trigger an alarm if the device gets disconnected.

Note that a device can get lost for the following reasons:

  • The cable has been removed.
  • The usb-hub you may have in your system lost your device.
  • The device has crashed and no longer answers.
  • The operating system has lost your device.

In case of problem, you will receive alarm messages (by email, on the graphical interface) when the device is lost, each n minutes when the device is still lost, and eventually one message to tell you the device is back online (see alarm section for more information about alarms).

comManager = ComManager( "COM20", comListener, alarmName="My device alarm" )

Check if you are connected:

comManager.isConnected()