java.lang.Object
com.inductiveautomation.ignition.common.script.builtin.SerialUtilities

public class SerialUtilities extends Object
  • Field Details

  • Method Details

    • configureSerialPort

      public static SerialUtilities.SerialConfigurator configureSerialPort(org.python.core.PyObject[] pyArgs, String[] keywords)
      Configure a serial port for later use.
      Returns:
      A SerialUtilities.SerialConfigurator that can be used to configure the serial port instead of or in addition to the given keyword arguments.
    • port

      public static SerialUtilities.PortManager port(org.python.core.PyObject[] pyArgs, String[] keywords) throws IOException
      Throws:
      IOException
    • openSerialPort

      public static void openSerialPort(String port) throws IOException
      Throws:
      IOException
    • closeSerialPort

      public static void closeSerialPort(String port) throws IOException
      Throws:
      IOException
    • sendBreak

      public static void sendBreak(String port, int millis) throws IOException, InterruptedException
      Send a sendBreak break signal to a serial port.
      Parameters:
      port - The previously configured serial port to use.
      millis - Approximate length of break signal, in milliseconds.
      Throws:
      IOException
      InterruptedException
    • readBytes

      public static byte[] readBytes(String port, int numberOfBytes) throws IOException
      Throws:
      IOException
    • readBytes

      public static byte[] readBytes(String port, int numberOfBytes, int timeout) throws IOException
      Read numberOfBytes bytes from a serial port.
      Parameters:
      port - The previously configured serial port to use.
      numberOfBytes - The number of bytes to read.
      timeout - Maximum amount of time, in milliseconds, to block before returning.
      Returns:
      A byte[] containing numberOfBytes bytes read from the serial port.
      Throws:
      IOException
    • readBytesAsString

      public static String readBytesAsString(String port, int numberOfBytes) throws IOException
      Throws:
      IOException
    • readBytesAsString

      public static String readBytesAsString(String port, int numberOfBytes, int timeout) throws IOException
      Read numberOfBytes from a serial port and convert them to a String.
      Parameters:
      port - The previously configured serial port to use.
      numberOfBytes - The number of bytes to read.
      timeout - Maximum amount of time, in milliseconds, to block before returning.
      Returns:
      A String created from the bytes read, using String(byte[]).
      Throws:
      IOException
    • readBytesAsString

      public static String readBytesAsString(String port, int numberOfBytes, int timeout, String encoding) throws IOException
      Read bytes from a serial port and convert them to a String.
      Parameters:
      port - The previously configured serial port to use.
      numberOfBytes - The number of bytes to read.
      timeout - Maximum amount of time, in milliseconds, to block before returning.
      encoding - Charset to use to decode the string. If null, uses platform default charset.
      Returns:
      A String created from the bytes read, using String(byte[]).
      Throws:
      IOException
    • readLine

      public static String readLine(String port) throws IOException
      Throws:
      IOException
    • readLine

      public static String readLine(String port, int timeout) throws IOException
      Throws:
      IOException
    • readLine

      public static String readLine(String port, int timeout, String encoding) throws IOException
      Throws:
      IOException
    • readLine

      public static String readLine(String port, int timeout, String encoding, boolean crlfRequired) throws IOException
      Read one line from a serial port.
      Parameters:
      port - The previously configured serial port to use.
      timeout - Maximum amount of time, in milliseconds, to block before returning.
      encoding - The String encoding to use.
      crlfRequired - true if both CR and LF are required to delimit a line.
      Returns:
      A line of text. A line is considered either a line feed ('\n') or carriage return ('\r') or both if crlfRequired.
      Throws:
      IOException
    • readUntil

      public static String readUntil(String port, char delimiter, boolean includeDelimiter) throws IOException
      Read from a serial port until a delimiter character is encountered.
      Parameters:
      port - The previously configured serial port to use.
      delimiter - The delimiter to read until.
      includeDelimiter - If includeDelimiter is true, the delimiter will be included in the return value. Otherwise it will be discarded.
      Returns:
      Returns a String containing all characters read until the delimiter was reached, and including the delimiter if includeDelimiter is true.
      Throws:
      IOException
    • readUntil

      public static String readUntil(String port, char delimiter, boolean includeDelimiter, int timeout) throws IOException
      Read from a serial port until a delimiter character is encountered.
      Parameters:
      port - The previously configured serial port to use.
      delimiter - The delimiter to read until.
      includeDelimiter - If includeDelimiter is true, the delimiter will be included in the return value. Otherwise it will be discarded.
      timeout - read timeout in milliseconds
      Returns:
      Returns a String containing all characters read until the delimiter was reached, and including the delimiter if includeDelimiter is true.
      Throws:
      IOException
    • write

      public static void write(String port, String toWrite) throws IOException
      Throws:
      IOException
    • write

      public static void write(String port, String toWrite, int timeout) throws IOException
      Throws:
      IOException
    • write

      public static void write(String port, String toWrite, int timeout, String encoding) throws IOException
      Write a String, toWrite, to a serial port.
      Parameters:
      port - The previously configured serial port to use.
      toWrite - The String to write.
      timeout - The duration to wait, in milliseconds, before timing out.
      Throws:
      IOException
    • writeBytes

      public static void writeBytes(String port, byte[] toWrite) throws IOException
      Throws:
      IOException
    • writeBytes

      public static void writeBytes(String port, byte[] toWrite, int timeout) throws IOException
      Write a byte[], toWrite, to a serial port.
      Parameters:
      port - The previously configured serial port to use.
      toWrite - The byte[] to write.
      timeout - The duration to wait, in milliseconds, before timing out.
      Throws:
      IOException