scorpionserial module

filename:scorpionserial.py
author:roar@tordivel.no
requirements:Scorpion 11.0
copyright:2000-2015 Tordivel AS
license:Tordivel AS’ Scorpion Python Module License

Serial communication module for Scorpion. Contains class for serial communication of TdvCmd protocol inherited from SorpionBaseComm.

Derived classes should override the execute method for profile specific protocols.

1.0.0.2, 21nov2015, RL: fixed import in __main__
1.0.0.1, 16nov2015, RL: created
class scorpionserial.ScorpionSerial(port=1, baudrate=9600, params='N81', pollrate=50, verbose=1)

Bases: scorpionbasecomm.ScorpionBaseComm

Base class for TdvCmd protocol on serial communication over RS232

The default implementation decodes incoming messages as TdvCmd commands end calls ExecuteCmd.

Override the method execute to implement profile specific protocols.

Parameters:
  • port (int, optional) – physical port number 1..n, default 1
  • baudrate (int, optional) – communication baudrate, default 9600
  • params (string, optional) – 3 chars defining port setup, <parity><bytesize><stopbits> <parity> - [‘N’, ‘E’, ‘O’], default ‘N’ <bytesize> - [‘7’, ‘8’], default ‘8’ <stopbits> - [‘1’, ‘2’], default ‘1’
  • pollrate (int, optional) – pollrate of checking for incoming data, defalt 50 ms
  • verbose (int, optional) – debug info level, default 1 - info
serial

serial.Serial

the pySerial object

stx

string

start phrase of protocol, default ‘’ (empty)

etx

string

stop phrase of protocol, default chr(13), carriage return

Example

>>>from scorpionserial import ScorpionSerial >>>serial=ScorpionSerial(4,19200,’N81’)

__repr__()

return formatted name of instance

open()

open serial port

Returns:boolean success
close()

close serial port

Returns:boolean success
send(data)

send data over RS232

Parameters:data (string) – data part of message
Returns:boolean success

Note

stx and etx is automatic added and should not be part of data

read()

read data from serial port

read operation should be none blocking and return immediately if no data. Uncomplete message is accumulated until next read.

Returns:data – complete message if any, else None
Return type:string

Note

returned data is data stripped for stx and etx