/      日本語

mwings module

mwings

This is a top-level module that is often used directly.

src/mwings/__init__.py

Twelite

Interface for TWELITE

Inherits: threading.Thread

Twelite()

Twelite(port=None, rx_buffer_size=1024, timeout=100, tz=None, debugging=False)

Constructor. If a serial port is specified, it will be opened.

Parameters

NameTypeDescription
portoptional strSerial port name: disabled if None
rx_buffer_sizeintSize of the receive buffer in bytes
timeoutintTimeout between receiving packets (ms)
tzoptional tzinfoTimezone applied to received data: UTC if None
debuggingboolDebug output: enabled if True

Exceptions

  • IOError Serial port does not exist or is busy

close()

v1.0.10+

close()

Closes the serial port if it is open.

Parameters

None

Return value

None

add_listener()

@overload
add_listener(event, handler)
add_listener(event, handler)

Registers a receive handler.

Parameters

NameTypeDescription
eventcommon.PacketTypeIdentifier for the receive event
handlerCallable[[common.BarePacket], None]Handler for the receive event (raw data)
Callable[[common.SomeCallable], None]Handler for the receive event (parsed data)

Return value

None

on()

on(event)

Registers a receive handler (decorator version).

Parameters

NameTypeDescription
eventcommon.PacketTypeIdentifier for the receive event

Return value

TypeValueDescription
Callable[[common.SomeCallable], common.SomeCallable]-Decorated function

remove_all_listeners()

v1.0.9+

remove_all_listeners()

Removes all registered receive handlers.

Parameters

None

Return value

None

parse()

@overload
parse(character, use_lf=False)
parse(character, use_lf=False)
parse(character, use_lf=False)

Parses the given received data.

Parameters

NameTypeDescription
characterstrReceived data character: string of length 1
bytesReceived data character: bytes of length 1
intReceived data character: ASCII code
use_lfboolType of newline character: LF if True

Return value

TypeValueDescription
optional common.PacketTypecommon.PacketTypeParsed packet type
NoneNo parsed packet

Exceptions

  • RuntimeError Serial port is specified
  • ValueError Invalid character data detected

parse_line()

parse_line(line, use_lf=True)

Parses received data expressed as a single line string.

Parameters

NameTypeDescription
linestrReceived data string: a single line
use_lfboolType of newline character: LF if True

Return value

TypeValueDescription
optional common.PacketTypecommon.PacketTypeParsed packet type
NoneNo parsed packet

Exceptions

  • RuntimeError Serial port is specified

receive()

receive()

Parses data received on the serial port. Waits until the interpretation of one packet is complete.

Parameters

None

Return value

TypeValueDescription
common.PacketType-Parsed packet type

Exceptions

  • RuntimeError Serial port is not specified

run()

run()

Runs a subthread that performs reception. Overrides threading.Thread.run().

Parameters

None

Return value

None

send()

@overload
send(data)
send(data)

Sends commands from the serial port.

Parameters

NameTypeDescription
datacommon.SomeCommandVarious command data
common.BarePacketRaw command data

Return value

TypeValueDescription
boolTrueSuccess
FalseFailure

Exceptions

  • RuntimeError Serial port is not specified

set_timezone()

set_timezone(tz)

Sets the timezone applied to received data.

Parameters

NameTypeDescription
tztzinfoAny timezone: ZoneInfo
NoneUTC

Return value

None

start()

start()

Starts a subthread that performs reception. Overrides threading.Thread.start().

Parameters

None

Return value

None

Exceptions

  • RuntimeError Serial port is not specified

stop()

stop()

Stops the subthread that performs reception. Waits until handler calls for remaining received data are finished. This may take several seconds.

Parameters

None

Return value

None

Exceptions

  • RuntimeError Serial port is not specified

update()

update()

Parses data received on the serial port. Processes all data in the receive buffer and then immediately returns.

Parameters

None

Return value

TypeValueDescription
optional common.PacketTypecommon.PacketTypeParsed packet type
NoneNo parsed packet

Exceptions

  • RuntimeError Serial port is not specified

timezone

@property
update()

Return value

TypeValueDescription
tzinfo-Timezone applied to received data

mwings.common Module

Stores data and procedures used throughout the library.

mwings.parsers Module

Parsers for interpreting packets and handling their data.

mwings.serializers Module

Serializers to generate commands and data structures to handle them.

mwings.utils Module

mwings.utils