Class SerialHelper
- java.lang.Object
-
- ptolemy.actor.lib.jjs.HelperBase
-
- ptolemy.actor.lib.jjs.modules.serial.SerialHelper
-
public class SerialHelper extends HelperBase
Helper for the serial module.- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Edward A. Lee. Contributor: Christopher Brooks
- Pt.AcceptedRating:
- red (cxh)
- Pt.ProposedRating:
- red (cxh)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SerialHelper.SerialReader
Read from the serial port and emit data.class
SerialHelper.SerialWriter
Write to the serial port.-
Nested classes/interfaces inherited from class ptolemy.actor.lib.jjs.HelperBase
HelperBase.DATA_TYPE
-
-
Field Summary
-
Fields inherited from class ptolemy.actor.lib.jjs.HelperBase
_actor, _currentObj
-
-
Constructor Summary
Constructors Constructor Description SerialHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping, java.lang.String portName, java.lang.String ownerName, int timeout, java.util.Map<java.lang.String,java.lang.Object> options)
Open a serial port.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_appendToBuffer(java.lang.Object data, HelperBase.DATA_TYPE type, java.lang.String imageType, io.vertx.core.buffer.Buffer buffer)
Append data to be sent to the specified buffer.void
close()
Close the serial port.void
open()
Open the serial port.void
send(java.lang.Object data)
Send data over the serial port.static java.lang.String[]
supportedReceiveTypes()
Return an array of the types supported by the current host for receiveType arguments.static java.lang.String[]
supportedSendTypes()
Return an array of the types supported by the current host for sendType arguments.-
Methods inherited from class ptolemy.actor.lib.jjs.HelperBase
_appendNumericToBuffer, _error, _error, _error, _error, _extractFromBuffer, _issueResponse, _removeDuplicates, _sizeOfType, _toJavaBytes, _toJSArray, getHelping
-
-
-
-
Constructor Detail
-
SerialHelper
public SerialHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping, java.lang.String portName, java.lang.String ownerName, int timeout, java.util.Map<java.lang.String,java.lang.Object> options)
Open a serial port. The argument is an instance of the JavaScript SerialPort object.- Parameters:
actor
- The actor associated with this helper.helping
- The object that this is helping (SerialPort).portName
- The name of the port to open.ownerName
- The name of the owner assigned to this port, if opening is successful.timeout
- Time in milliseconds before failing.options
- Serial port options (FIXME: define).
-
-
Method Detail
-
close
public void close()
Close the serial port.
-
open
public void open() throws IllegalActionException
Open the serial port. If there is already a serial port open, close it first.If the port is not found, then try each available port in turn and open the first as yet unopened port. Port names that include "Bluetooth" and "/dev/cu." are skipped. Different machines may have different port names so port scanning makes it possible to have models that will open the first N serial ports.
- Throws:
IllegalActionException
- If there is no such port, if the port is owned by another user, if the port does not support the specified paramters or if the input or output fails.
-
send
public void send(java.lang.Object data)
Send data over the serial port.- Parameters:
data
- The data to send.
-
supportedReceiveTypes
public static java.lang.String[] supportedReceiveTypes()
Return an array of the types supported by the current host for receiveType arguments.- Returns:
- an array of the types supported by the current host for receiveType arguments.
-
supportedSendTypes
public static java.lang.String[] supportedSendTypes()
Return an array of the types supported by the current host for sendType arguments.- Returns:
- an array of the types supported by the current host for sendType arguments.
-
_appendToBuffer
protected void _appendToBuffer(java.lang.Object data, HelperBase.DATA_TYPE type, java.lang.String imageType, io.vertx.core.buffer.Buffer buffer)
Append data to be sent to the specified buffer. This overrides the base class to append a null byte to terminate string and JSON types.- Overrides:
_appendToBuffer
in classHelperBase
- Parameters:
data
- The data to append.type
- The type of data append.imageType
- If the type is IMAGE, then then the image encoding to use, or null to use the default (JPG).buffer
- The buffer.
-
-