Stream
DUELink Scripting language is built to be ASCII human-friendly. This works great; however, there are instances where speed or raw binary data is required. For example, when writing or reading a buffer. Through the stream feature, provided libraries such as Python, allows the user to have direct access to the scripts internals.
Usage
This is an example to send a byte array buffer to the device.
- Python
- JavaScript
- .NET
- Arduino
Start by setting up for Python or MicroPython.
# add example here
duelink.Stream.WriteBytes("b1", byte_array, 64) # write first 64 byte elements from byte_array to b1
duelink.Stream.WriteFloats("a1", float_array, 64) # write first 64 float elements from float_array to a1
Start by setting up for JavaScript.
// add example here
duelink.Stream.WriteBytes("b1", byte_array, 64) // write first 64 byte elements from byte_array to b1
duelink.Stream.WriteFloats("a1", float_array, 64) // write first 64 float elements from float_array to a1
Start by setting up for .NET.
// add example here
duelink.Stream.WriteBytes("b1", byte_array, 64) // write first 64 byte elements from byte_array to b1
duelink.Stream.WriteFloats("a1", float_array, 64) // write first 64 float elements from float_array to a1
Similarly, you can also read a buffer from the device. In this example, we are using a float arrays instead of a byte array.
- Python
- JavaScript
- .NET
- Arduino
Start by setting up for Python or MicroPython.
# add example here
duelink.Stream.ReadBytes("b1", byte_array, 64) # read 64 byte elements from b1 to byte_array
duelink.Stream.ReadFloats("a1", float_array, 64) # read 64 byte elements from a1 to float_array
Start by setting up for JavaScript.
// add example here
duelink.Stream.ReadBytes("b1", byte_array, 64) // read 64 byte elements from b1 to byte_array
duelink.Stream.ReadFloats("a1", float_array, 64) // read 64 byte elements from a1 to float_array
Start by setting up for .NET.
// add example here
duelink.Stream.ReadBytes("b1", byte_array, 64) // read 64 byte elements from b1 to byte_array
duelink.Stream.ReadFloats("a1", float_array, 64) // read 64 byte elements from a1 to float_array
Stream can't be used directly by typing in ASCII commands, like when using the Console.
Mechanism
Understanding and utilizing Stream mechanism is only needed by advanced users. See the source code of one of the provided libraries for reference.
A Stream command initiates the request, such as DisplayStream()
. Once this command is received and accepted by the device, the &
symbol will be returned indicating readiness. The host can now send the entire data, exactly to the required byte count.