Class 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)
    • 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 class HelperBase
        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.