Variables

SECS variable types.

class secsgem.secs.variables.F4(value=None, count=-1)[source]

Secs type for 4 byte float data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.F8(value=None, count=-1)[source]

Secs type for 8 byte float data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.I1(value=None, count=-1)[source]

Secs type for 1 byte signed data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.I2(value=None, count=-1)[source]

Secs type for 2 byte signed data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.I4(value=None, count=-1)[source]

Secs type for 4 byte signed data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.I8(value=None, count=-1)[source]

Secs type for 8 byte signed data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.JIS8(value='', count=-1)[source]

Secs type for string data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.U1(value=None, count=-1)[source]

Secs type for 1 byte unsigned data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.U2(value=None, count=-1)[source]

Secs type for 2 byte unsigned data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.U4(value=None, count=-1)[source]

Secs type for 4 byte unsigned data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.U8(value=None, count=-1)[source]

Secs type for 8 byte unsigned data.

Parameters:
  • value – initial value

  • count – number of items this value

class secsgem.secs.variables.Array(data_format, value=None, count=-1)[source]

List variable type. List with items of same type.

static get_format(data_format, showname=False)[source]

Get the format of the variable.

Parameters:
  • data_format – internal data definition/sample

  • showname – show the name of the variable

Returns:

string representation of the function

append(data)[source]

Append data to the internal list.

Parameters:

data – list item to add

set(value)[source]

Set the internal value to the provided value.

Parameters:

value – new value

get()[source]

Return the internal value.

Returns:

internal value

encode()[source]

Encode the value to secs data.

Return type:

bytes

Returns:

encoded data bytes

decode(data, start=0)[source]

Decode the secs byte data to the value.

Parameters:
  • data – encoded data bytes

  • start – start position of value the data

Returns:

new start position

class secsgem.secs.variables.Base(value=None)[source]

Base class for SECS variables.

Due to the python types, wrapper classes for variables are required. If constructor is called with Base or subclass only the value is copied.

set(value)[source]

Set the internal value to the provided value.

Parameters:

value – new value

encode_item_header(length)[source]

Encode item header depending on the number of length bytes required.

Parameters:

length – number of bytes in data

Returns:

encoded item header bytes

decode_item_header(data, text_pos=0)[source]

Encode item header depending on the number of length bytes required.

Parameters:
  • data – encoded data

  • text_pos – start of item header in data

Return type:

tuple[int, int, int]

Returns:

start position for next item, format code, length item of data

property is_dynamic: bool

Check if this instance is Dynamic or derived.

property preferred_type

Get the preferred type for this variable.

class secsgem.secs.variables.Binary(value=None, count=-1)[source]

Secs type for binary data.

supports_value(value)[source]

Check if the current instance supports the provided value.

Parameters:

value – value to test

Return type:

bool

Returns:

True if the value is supported, False otherwise

set(value)[source]

Set the internal value to the provided value.

Parameters:

value – new value

get()[source]

Return the internal value.

Returns:

internal value

encode()[source]

Encode the value to secs data.

Return type:

bytes

Returns:

encoded data bytes

decode(data, start=0)[source]

Decode the secs byte data to the value.

Parameters:
  • data – encoded data bytes

  • start – start position of value the data

Returns:

new start position

class secsgem.secs.variables.Boolean(value=None, count=-1)[source]

Secs type for boolean data.

supports_value(value)[source]

Check if the current instance supports the provided value.

Parameters:

value – value to test

Return type:

bool

Returns:

True if the value is supported, False otherwise

set(value)[source]

Set the internal value to the provided value.

Parameters:

value – new value

get()[source]

Return the internal value.

Returns:

internal value

encode()[source]

Encode the value to secs data.

Return type:

bytes

Returns:

encoded data bytes

decode(data, start=0)[source]

Decode the secs byte data to the value.

Parameters:
  • data – encoded data bytes

  • start – start position of value the data

Returns:

new start position

class secsgem.secs.variables.Dynamic(types, value=None, count=-1)[source]

Variable with interchangable type.

property preferred_type

Get the preferred type.

set(value)[source]

Set the internal value to the provided value.

In doubt provide the variable wrapped in the matching secsgem.secs.variables.Base class, to avoid confusion.

Parameters:

value – new value

Example

>>> import secsgem.secs
>>>
>>> var = secsgem.secs.variables.Dynamic([secsgem.secs.variables.String,
...                                       secsgem.secs.variables.U1])
>>> var.set(secsgem.secs.variables.U1(10))
>>> var
<U1 10 >

If no type is provided the default type is used which might not be the expected type.

get()[source]

Return the internal value.

Returns:

internal value

encode()[source]

Encode the value to secs data.

Return type:

bytes

Returns:

encoded data bytes

decode(data, start=0)[source]

Decode the secs byte data to the value.

Parameters:
  • data – encoded data bytes

  • start – start position of value the data

Returns:

new start position

property is_dynamic: bool

Check if this instance is Dynamic or derived.

class secsgem.secs.variables.List(data_format, value=None)[source]

List variable type. List with items of different types.

static get_format(data_format, showname=False)[source]

Get the format of the variable.

Returns:

string representation of the function

static get_name_from_format(data_format)[source]

Generate a name for the passed data_format.

Parameters:

data_format – data_format to get name for

Returns:

name for data_format

set(value)[source]

Set the internal value to the provided value.

Parameters:

value – new value

get()[source]

Return the internal value.

Returns:

internal value

encode()[source]

Encode the value to secs data.

Return type:

bytes

Returns:

encoded data bytes

decode(data, start=0)[source]

Decode the secs byte data to the value.

Parameters:
  • data – encoded data bytes

  • start – start position of value the data

Returns:

new start position

class secsgem.secs.variables.String(value='', count=-1)[source]

Secs type for string data.

Parameters:
  • value – initial value

  • count – number of items this value