pygmc.connection package
Submodules
pygmc.connection.connection module
- class pygmc.connection.connection.Connection(timeout=5)[source]
Bases:
objectConnection to a GMC device. Either user provided parameters or a best-guess auto-connect.
Effectively a wrapper for pyserial for GMC specific tasks.
- connect(port=None, baudrate=None, vid=None, pid=None, description=None, hardware_id=None) None[source]
Connect to device. If all parameters are None, _auto_connect() flow is used which attempts to connect to all available ports. If ANY parameter is given; it’s used to refine the search, any matches are considered. Parameters are used as an OR search.
- Parameters:
port (str | None, optional) – Exact port (device dev path / com port) e.g. ‘/dev/ttyUSB0’ If port is specified, the following kwargs are ignored: vid, pid, description, hardware_id.
baudrate (int | None) – Device baudrate. Leave None to auto-detect baudrate. Only applicable when port is specified.
vid (str | None, optional) – Device vendor ID as hex, by default None
pid (str | None, optional) – Device product ID as hex, by default None
description (str | None, optional) – Device description, by default None
hardware_id (str | None, optional) – Device hwid, by default None e.g. ‘USB VID:PID=1A86:7523 LOCATION=2-1’ Use hex for vid:pid input
- Raises:
ConnectionError – _description_
- connect_exact(port, baudrate) None[source]
Connect with exact user provided parameters. No searching port, no searching baudrate. i.e. fast.
- Parameters:
port (str) – Port. e.g. linux /dev/ttyUSB0 or windows COM3
baudrate (int) – Baudrate e.g. 115200
- connect_user_provided(connection) None[source]
User does their own thing and gives a serial.Serial like class.
- Parameters:
connection (serial.Serial) – A serial.Serial like class (pyserial)
- get(cmd, wait_sleep=0.3) bytes[source]
Write command to device and get response. Only use in development/learning environment. May give incomplete/empty response if device is busy.
- Parameters:
cmd (bytes) – Write command e.g. <GETVER>>
wait_sleep (float, optional) – Time to sleep to give device time to write, by default 0.3
- Returns:
Device response
- Return type:
bytes
- get_exact(cmd, expected=b'', size=None) bytes[source]
Write command to device, provide expected LF or size (bytes), wait until either LF, size, or timeout is reached, then return device response.
- Parameters:
cmd (bytes) – Write command e.g. <GETVER>>
expected (bytes, optional) – Expected end char, by default b’’
size (int | None, optional) – Expected response size, by default None
- Returns:
Device response
- Return type:
bytes
- read(wait_sleep=0.3) bytes[source]
Read all available data… which may be incomplete. (noob/newbie method)
- Parameters:
wait_sleep (float, optional) – Time to sleep to give device time to write, by default 0.3
- Returns:
Device response
- Return type:
bytes
- read_until(expected=b'', size=None) bytes[source]
Read device data until expected LF is reached or expected result size is reached. Waits until conditions met or timeout. Some data has
which causes reading to stop. default changed from b’
‘ to b’’
- expectedbytes, optional
Expected end character, by default b’’
- sizeNone | int, optional
Length of expected bytes, by default None
- bytes
Device response