communication
Module¶
This module is used to communicate with the shield.
Requirement: Make objects from binary stuff.
-
class
AYABInterface.communication.
Communication
(file, get_needle_positions, machine, on_message_received=(), left_end_needle=None, right_end_needle=None)[source]¶ Bases:
object
This class comunicates with the AYAB shield.
-
__init__
(file, get_needle_positions, machine, on_message_received=(), left_end_needle=None, right_end_needle=None)[source]¶ Create a new Communication object.
Parameters: - file¶ – a file-like object with read and write methods for the
communication with the Arduino. This could be a
serial.Serial
or asocket.socket.makefile()
. - get_needle_positions¶ – a callable that takes an
index
and returnsNone
or an iterable over needle positions. - machine¶ (AYABInterface.machines.Machine) – the machine to use for knitting
- on_message_received¶ (list) – an iterable over callables that takes
a received
message
whenever it comes in. Sincestate
changes only take place when a message is received, this can be used as an state observer. - left_end_needle¶ – A needle number on the machine. Other needles that are on the left side of this needle are not used for knitting. Their needle positions are not be set.
- right_end_needle¶ – A needle number on the machine. Other needles that are on the right side of this needle are not used for knitting. Their needle positions are not be set.
- file¶ – a file-like object with read and write methods for the
communication with the Arduino. This could be a
-
__weakref__
¶ list of weak references to the object (if defined)
-
api_version_is_supported
(api_version)[source]¶ Return whether an api version is supported by this class.
Return type: bool Returns: if the api version
is supportedParameters: api_version¶ (int) – the api version Currently supported api versions:
4
-
can_receive_messages
()[source]¶ Whether tihs communication is ready to receive messages.]
Return type: bool assert not communication.can_receive_messages() communication.start() assert communication.can_receive_messages() communication.stop() assert not communication.can_receive_messages()
-
controller
¶ Information about the controller.
If no information about the controller is received, the return value is
None
.If information about the controller is known after The cnfInfo Message was received, you can access these values:
>>> communication.controller.firmware_version (5, 2) >>> communication.controller.firmware_version.major 5 >>> communication.controller.firmware_version.minor 2 >>> communication.controller.api_version 4
-
last_requested_line_number
¶ The number of the last line that was requested.
Return type: int Returns: the last requested line number or 0
-
left_end_needle
¶ The left end needle of the needle positions.
Return type: int Returns: the left end needle of the machine
-
lock
¶ The lock of the communication.
In case you
parallelize()
the communication, you may want to use thislock
to make shure the parallelization does not break your code.
-
needle_positions
¶ A cache for the needle positions.
Return type: AYABInterface.communication.cache.NeedlePositionCache
-
on_message
(callable)[source]¶ Add an observer to received messages.
Parameters: callable¶ – a callable that is called every time a AYABInterface.communication.host_messages.Message
is sent or aAYABInterface.communication.controller_messages.Message
is received
-
parallelize
(seconds_to_wait=2)[source]¶ Start a parallel thread for receiving messages.
If
start()
was no called before, start will be called in the thread. The thread callsreceive_message()
until thestate
is_connection_closed()
.Parameters: seconds_to_wait¶ (float) – A time in seconds to wait with the parallel execution. This is useful to allow the controller time to initialize. See also
-
right_end_needle
¶ The left end needle of the needle positions.
Return type: int Returns: the right end needle of the machine
-
runs_in_parallel
()[source]¶ Whether the communication runs in parallel.
Return type: bool Returns: whether parallelize()
was called and the communication still receives messages and is not stopped
-
start
()[source]¶ Start the communication about a content.
Parameters: content¶ (Content) – the content of the communication.
-
state
¶ The state this object is in.
Returns: the state this communication object is in. Return type: AYABInterface.communication.states.State Note
When calling
parallelize()
the state can change while you check it.
-