smartchem_ion3 package

class smartchem_ion3.ChannelData(value, unit)

Bases: tuple

A namedtuple containing a single reading from a single channel, consiting of a value and its units.

unit

Unit associated with the data reading, as a Unit object.

value

Value for the data reading.

class smartchem_ion3.Data(ch1, ch2, ch3, cht, timestamp, n)

Bases: tuple

A namedtuple containing a single reading from the device, consisting of three channels plus temperature data. Each of the channel entries is an instance of ChannelData.

ch1

Probe channel 1 data as a ChannelData object.

ch2

Probe channel 2 data as a ChannelData object.

ch3

Probe channel 3 data as a ChannelData object.

cht

Temperature channel data as a ChannelData object.

n

Index of data reading.

timestamp

Timestamp of data reading as a python datetime object.

class smartchem_ion3.Ion3(serial_port=None, baudrate=38400, data_callback=None, **kwargs)[source]

Bases: object

Initialise and open serial device for the SmartChem-Ion3 ion-selective electrode interface.

The serial_port parameter may be a system-specific string (eg. "/dev/ttyUSB0", "COM12") or a ListPortInfo instance. If the serial_port parameter is None (default), then an attempt to detect a serial device will be performed. The first device found will be initialised. If multiple serial devices are present on the system, then the use of the the additional keyword arguments can be used to select a specific device. The keyword arguments the same as those used for find_device().

The communication baud rate should match that configured on the device. Options for the baudrate parameter are 1200, 9600, 19200, or 38400 (default).

The device may send data back spontaneously (with out a specific request from the host) when configured to use its “Instant Send” or “Print” functions. The function specified by the data_callback parameter will be called and passed the data for each received data record. The callback function can be also configured after initialisation by setting the data_callback property.

Parameters
  • serial_port – Serial port device the device is connected to.

  • baudrate – Serial port baud rate to use.

  • data_callback – Function to call on receipt of spontaneous data.

  • vid – Numerical USB vendor ID to match.

  • pid – Numerical USB product ID to match.

  • manufacturer – Regular expression to match to a device manufacturer string.

  • product – Regular expression to match to a device product string.

  • serial_number – Regular expression to match to a device serial number.

  • location – Regular expression to match to a device physical location (eg. USB port).

close() None[source]

Close the connection to the device.

current_data()[source]

Get the current data readings from the device.

Returns

A single reading from the device as a Data instance.

erase_log() None[source]

Erase any logged data records stored on the device.

glp() str[source]

Get the “Good Laboratory Practices” table containing the device’s calibration information.

The table is returned as raw ASCII as specified in the device documentation (no attempt is made to parse the individual fields).

Returns

Good Laboratory Practices table as a string.

logged_data() list[source]

Get the set of logged data readings from the device.

Returns

A list of readings from the device as Data instances.

property data_callback: Callable

Function to call on receipt of spontaneous data from the device.

property firmware_version: str

Firmware version on the device, as a string.

property n_readings: int

Number of logged readings in the device memory.

property serial_number: str

Serial number of the device, as a string.

class smartchem_ion3.Unit(value)[source]

Bases: enum.Enum

An Enum to assist with matching and displaying the unit types used by the device.

C = 'oC'
CM = 'oCm'
EXP = ''
MV = 'mV'
MVR = 'mVR'
PERCENT = '%'
PH = 'pH'
PPK = 'ppK'
PPM = 'ppM'
UNCAL = 'UnCal'
property description

Return a string describing the type of unit.

property suffix

Return a string format of the unit’s suffix to append to a value.

smartchem_ion3.find_device(vid=None, pid=None, manufacturer=None, product=None, serial_number=None, location=None)[source]

Search attached serial ports for a specific device.

The first device found matching the criteria will be returned. Because there is no consistent way to identify serial devices, the default parameters do not specify any selection criteria, and thus the first serial port will be returned. A specific device should be selected using a unique combination of the parameters.

The USB vendor (vid) and product (pid) IDs are exact matches to the numerical values, for example vid=0x067b or vid=0x2303. The remaining parameters are strings specifying a regular expression match to the corresponding field. For example serial_number="83" would match devices with serial numbers starting with 83, while serial_number=".*83$" would match devices ending in 83. A value of None means that the parameter should not be considered, however an empty string value ("") is subtly different, requiring the field to be present, but then matching any value.

Be aware that different operating systems may return different data for the various fields, which can complicate matching when attempting to write cross-platform code.

To see a list of serial ports and the relevant data fields:

Parameters
  • vid – Numerical USB vendor ID to match.

  • pid – Numerical USB product ID to match.

  • manufacturer – Regular expression to match to a device manufacturer string.

  • product – Regular expression to match to a device product string.

  • serial_number – Regular expression to match to a device serial number.

  • location – Regular expression to match to a device physical location (eg. USB port).

Returns

First ListPortInfo device which matches given criteria.

smartchem_ion3.list_devices()[source]

Return a string listing all detected serial devices and any associated identifying properties.

The manufacturer, product, vendor ID (vid), product ID (pid), serial number, and physical device location are provided. These can be used as parameters to find_device() or the constructor of a device class to identify and select a specific serial device.

Returns

String listing all serial devices and their details.