|
CASP Python Libraries
This documentation primarily focuses on the usage of functions from 'casp', 'casp_be', 'casp_gpio' and 'casp_udio' namespaces.
|
This module defines functions to communicate with target hardware (i.e micro-controller board, SBC etc.) that is programmed with either: More...
Functions | |
| Init () | |
| Initializes CASP UDIO subprocess. | |
| HelpPython () | |
| Opens CASP Python Libraries documentation. | |
| Close () | |
| Terminates CASP UDIO subprocess and releases the resources. | |
| bool | ConnectSerial (str serial_port="COM3", int udi_bytes=16, int udo_bytes=16, bool enable_dtr=True, int send_recv_delay=1, int baud=115200) |
| Initializes CASP UDIO connection process with the target over serial port. | |
| bool | ConnectEth (str ip, int port=42001, int udi_bytes=16, int udo_bytes=16, bool tcp=False, int send_recv_delay=1) |
| Initializes CASP UDIO connection process with the target over ethernet. | |
| SerialPorts () | |
| Displays available serial ports on the host. | |
| int | ReadI (int udi_idx) |
| Reads User Data Input (UDI) value of type 32-bit integer from the target and returns the value as an integer. | |
| float | ReadF (int udi_idx) |
| Reads User Data Input (UDI) value of type 32-bit float from the target and returns the value as an float. | |
| bool | WriteI (int udo_idx, int value) |
| Writes User Data Output (UDO) value of type 32-bit integer to the target and returns the status of the write operation. | |
| bool | WriteF (int udo_idx, float value) |
| Writes User Data Output (UDO) value of type 32-bit float to the target and returns the status of the write operation. | |
This module defines functions to communicate with target hardware (i.e micro-controller board, SBC etc.) that is programmed with either:
All functions in this module uses global object _casp_process.casp_gpio_proc from _casp_process.py module.
About CASP UDIO:
CASP UDIO (User Data Input Output) is a simple communication protocol to exchange data with remote device or computer. The data exchange format is basically divided into header and payload. The format of header (4 Byte long) is as follows:
The payload bytes in general can be anything that is understandable between sender and receiver. However, the payload bytes are accessed (read and write) as 4 byte (or 32-bit) integers or floats. As such payload length should be in multiples of 4. This protocol is used mostly to transfer data as a contiguous sequence of 32-bit integers and floats irrespective of whether the underlying data is 32-bit integer or float. i.e. the actual data can of two 16-bit integers or a 64-bit integer or float split into two 32-bit integers at raw byte level.
This protocol is generally used within CASP domain to communicate between host and targets with minimum overheard.
In Python UDI and UDO is always accessed as 32-bit integer or 32-bit float. Even UDI and UDO indexes that are specified in functions such as ReadI(), ReadF(), WriteI() and WriteF() indicate UDI/UDO index and not byte index.
| casp_udio.Init | ( | ) |
Initializes CASP UDIO subprocess.
This is the first function to be called before using any other function in this module.
Definition at line 28 of file casp_udio.py.
| casp_udio.HelpPython | ( | ) |
Opens CASP Python Libraries documentation.
Definition at line 33 of file casp_udio.py.
| casp_udio.Close | ( | ) |
Terminates CASP UDIO subprocess and releases the resources.
Definition at line 38 of file casp_udio.py.
| bool casp_udio.ConnectSerial | ( | str | serial_port = "COM3", |
| int | udi_bytes = 16, | ||
| int | udo_bytes = 16, | ||
| bool | enable_dtr = True, | ||
| int | send_recv_delay = 1, | ||
| int | baud = 115200 ) |
Initializes CASP UDIO connection process with the target over serial port.
Performs initial protocol hand shake and keep things ready for data read/write operations.
User can use SerialPorts() to know available serial ports on the device.
Arguments:
serial_port: Set serial port to which device is connected. udi_bytes: Set 'User Data Input (UDI)' bytes for receiving data from the target. Default value is 16 bytes. udo_bytes: Set 'User Data Output (UDO)' bytes for sending data from the target. Default value is 16 bytes. enable_dtr: Set to True when serial data terminal ready (DTR) control signal is to be used. Default value is True. Set to False if device is not detectable (generally on old hardware). send_recv_delay: Set send receive time delay in milli seconds. Generally set between 1 to 5 msec. Smaller values reduces latency at the cost of increased CPU utilization and vice versa. Default value is 1 msec. baud: Set baud rate in bits per second. Default value is 115200 bps.
Return Value:
Returns True if connection is successful. Else returns False.
Definition at line 43 of file casp_udio.py.
| bool casp_udio.ConnectEth | ( | str | ip, |
| int | port = 42001, | ||
| int | udi_bytes = 16, | ||
| int | udo_bytes = 16, | ||
| bool | tcp = False, | ||
| int | send_recv_delay = 1 ) |
Initializes CASP UDIO connection process with the target over ethernet.
Performs initial protocol hand shake and keep things ready for data read/write operations.
Arguments:
ip: Set IP address of the target device. Both IP4 and IP6 are supported. port: Set port number of the target device. Mostly, better leave it to default. udi_bytes: Set 'User Data Input (UDI)' bytes for receiving data from the target. Default value is 16 bytes. udo_bytes: Set 'User Data Output (UDO)' bytes for sending data from the target. Default value is 16 bytes. tcp: Set to True when TCP protocol is to be used else UDP protocol will be used during communication. send_recv_delay: Set send receive time delay in milli seconds. Generally set between 1 to 5 msec. Smaller values reduces latency at the cost of increased CPU utilization and vice versa. Default value is 1 msec.
Return Value:
Returns True if connection is successful. Else returns False.
Definition at line 77 of file casp_udio.py.
| casp_udio.SerialPorts | ( | ) |
Displays available serial ports on the host.
User can use this function before using the ConnectSerial() function.
Definition at line 109 of file casp_udio.py.
| int casp_udio.ReadI | ( | int | udi_idx | ) |
Reads User Data Input (UDI) value of type 32-bit integer from the target and returns the value as an integer.
Arguments:
udi_idx: UDI index from which the value is to be read. It should be greater than -1 and less than 'udi_bytes' specified in ConnectSerial() or ConnectEth() functions divided by 4.
Return Value:
Returns the UDI value received from the target as an integer.
Definition at line 117 of file casp_udio.py.
| float casp_udio.ReadF | ( | int | udi_idx | ) |
Reads User Data Input (UDI) value of type 32-bit float from the target and returns the value as an float.
Arguments:
udi_idx: UDI index from which the value is to be read. It should be greater than -1 and less than 'udi_bytes' specified in ConnectSerial() or ConnectEth() functions divided by 4.
Return Value:
Returns the UDI value received from the target as an float.
Definition at line 139 of file casp_udio.py.
| bool casp_udio.WriteI | ( | int | udo_idx, |
| int | value ) |
Writes User Data Output (UDO) value of type 32-bit integer to the target and returns the status of the write operation.
Arguments:
udo_idx: UDO index to which the value is to be written. It should be greater than -1 and less than 'udo_bytes' specified in ConnectSerial() or ConnectEth() functions divided by 4. value: Value to write.
Return Value:
Returns True if write operation is successful else returns False.
Definition at line 161 of file casp_udio.py.
| bool casp_udio.WriteF | ( | int | udo_idx, |
| float | value ) |
Writes User Data Output (UDO) value of type 32-bit float to the target and returns the status of the write operation.
Arguments:
udo_idx: UDO index to which the value is to be written. It should be greater than -1 and less than 'udo_bytes' specified in ConnectSerial() or ConnectEth() functions divided by 4. value: Value to write.
Return Value:
Returns True if write operation is successful else returns False.
Definition at line 185 of file casp_udio.py.