Documentation for dummy_serial (which is a serial port mock)

dummy_serial: A dummy/mock implementation of a serial port for testing purposes.

This Python file was changed (committed) at $Date: 2014-03-23 17:12:58 +0100 (Sun, 23 Mar 2014) $, which was $Revision: 178 $.

dummy_serial.DEFAULT_TIMEOUT = 5

The default timeot value. Used if not set by the constructor.

dummy_serial.DEFAULT_BAUDRATE = 19200

The default baud rate. Used if not set by the constructor.

dummy_serial.VERBOSE = False

Set this to True for printing the communication, and also details on the port initialization.

Might be monkey-patched in the calling test module.

dummy_serial.RESPONSES = {'EXAMPLEMESSAGE': 'EXAMPLERESPONSE'}

A dictionary of respones from the dummy serial port.

The key is the message (string) sent to the dummy serial port, and the item is the response (string) from the dummy serial port.

Intended to be monkey-patched in the calling test module.

dummy_serial.DEFAULT_RESPONSE = ''

Response when no matching message (key) is found in the look-up dictionary.

Might be monkey-patched in the calling test module.

class dummy_serial.Serial(*args, **kwargs)[source]

Dummy (mock) serial port for testing purposes.

Mimics the behavior of a serial port as defined by the pySerial module.

Args:
  • port:
  • timeout:

Note: As the portname argument not is used properly, only one port on dummy_serial can be used simultaneously.

open()[source]

Open a (previously initialized) port on dummy_serial.

close()[source]

Close a port on dummy_serial.

write(inputdata)[source]

Write to a port on dummy_serial.

Args:
inputdata (string/bytes): data for sending to the port on dummy_serial. Will affect the response.

Note that for Python2, the inputdata should be a string. For Python3 it should be of type bytes.

read(numberOfBytes)[source]

Read from a port on dummy_serial.

The response is dependent on what was written last to the port on dummy_serial, and what is defined in the RESPONSES dictionary.

Args:
numberOfBytes (int): For compability with the real function.

Returns a string for Python2 and bytes for Python3.

If the response is shorter than numberOfBytes, it will sleep for timeout. If the response is longer than numberOfBytes, it will return only numberOfBytes bytes.

Previous topic

Developer documentation

Next topic

Internal documentation for MinimalModbus

This Page

Get MinimalModbus at SourceForge.net. Fast, secure and Free Open Source software downloads