13
OPERATION MANUAL
5
API
5.1 Com Object (working with generic Command strings)
Namespace: from softcheck.logic import Com
To construct a new Com class - which is used for communication with the device - the
following arguments are needed:
Ethernet: Com("ethernet", TIMEOUT)
ModbusTCP: Com(“modbustcp”, TIMEOUT)
Serial interface: Com("serial", TIMEOUT)
Example: com = Com("serial", 2.1)
As 3rd parameter the verbosity level can be given. "1" means that the program ex-
plains what goes wrong in case of an error. "2" means that the sent and received
strings will be printed and "3" prints the time information for each command also.
4th parameter: When set to True (default), the program throws an exception in case of
an error, otherwise the program goes on.
open:
opens the chosen interface.
Ethernet: The first parameter us the IP address, the second one the port.
Serial interface: The first parameter is the port number (0 for COM1), the second one
the baud rate
Example: com.open("192.169.253.1", 8101) # open Ethernet socket
Example2: com.open(0, 9600) #opens Com1 with 9600 Baud
Example3: com.open('/dev/ttyACM0', 9600) # open ACM driver
send:
Sends a command to the interface. CR and LF have to be noted also
Example: send("TI? /r/n")
send_bytes:
(for ModbusTCP usage)
Sends a bytearray to the interface
Example: send_bytes(bytearray([0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFF, 0x41]))
check():
checks the start of the message received from the interface.
Example: check("TI ")
Example2: check("[S01G")
check_bytes:
(for ModbusTCP usage)
checks if the received bytearray from the interface matches the expected bytearray
Example: check_bytes(bytearray([0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFF, 0x41]))
check_regex():
Checks the answer received from the interface. Regular Expressions can be used here.
For easier work with regular Expressions it is advisable to use an "r" in Front of
the Expression. Attention should be payed also to the notation: When there are char-
acters like '[' in the command (LAI), they must be escaped: "\["
Example: check_regex("TI ")
Example2: check_regex("\[S01G")
close:
The chosen interface is closed.
Example: com.close()
recv:
Receives the answer from the interface.
This command is helpful when the answer from the interface should be processed fur-
ther. No check takes place.
Example: str = com.recv()
recv_bytes:
(for ModbusTCP usage)
pySoftcheck.01.20171002.2
Liability for errors and misprints excluded.
pySoftcheck
Summary of Contents for Pilot ONE
Page 1: ...Operation Manual ...
Page 2: ......