Class PJSerialComm

java.lang.Object
serialComms.jserialcomm.PJSerialComm

public class PJSerialComm extends Object
PAMGuard wrapper around some of the jserialcomm functionality in order to make it slightly easier to use in the PAMGuard swing environment. http://fazecast.github.io/jSerialComm/
Author:
dg50
  • Method Details

    • openSerialPort

      public static PJSerialComm openSerialPort(String portName, int baudRate) throws PJSerialException
      Create and open a serial port with default values of 8 data bits; 1 stop bit; no parity and flow control disabled.
      Parameters:
      portName - port name (e.g. COM1)
      baudRate - baud rate
      Returns:
      valid port object. Never null (throws exception first)
      Throws:
      PJSerialException - exception if port unavailable or busy.
    • openSerialPort

      public static PJSerialComm openSerialPort(SerialPortParameters serialPortParameters) throws PJSerialException
      Open a serial port with parameters defined in serialPortParameters
      Parameters:
      serialPortParameters -
      Returns:
      valid port object. Never null (throws exception first)
      Throws:
      PJSerialException - exception if port unavailable or busy.
    • openSerialPort

      public static PJSerialComm openSerialPort(String portName, int baudRate, int dataBits, int stopBits, int parity, int flowControl) throws PJSerialException
      Create and open a serial port.
      Parameters:
      portName - port name (e.g. COM1)
      baudRate - baud rate
      dataBits - data bits
      stopBits - stop bits
      parity - parity
      flowControl - flow control
      Returns:
      valid port object. Never null (throws exception first)
      Throws:
      PJSerialException - exception if port unavailable or busy.
    • addLineListener

      public void addLineListener(PJSerialLineListener serialLineListener)
    • addDataListener

      public void addDataListener(com.fazecast.jSerialComm.SerialPortDataListener serialPortDataListener)
      Call through to underlying serial port to add a data listener.
      Parameters:
      serialPortDataListener -
    • addCharListener

      public void addCharListener(PJSerialLineListener serialLineListener)
    • closePort

      public boolean closePort()
      Close the serial port and any associated data buffers.
      Returns:
      true if any reading threads close properly.
    • portExists

      public static boolean portExists(String portName)
      Check whether a port exists.
      Parameters:
      portName - port name (.e.g
      Returns:
      true if it exists
    • getSerialPortNames

      public static String[] getSerialPortNames()
      Get a list of available comm ports in alphabetical order.
      Returns:
    • getSerialPorts

      public static com.fazecast.jSerialComm.SerialPort[] getSerialPorts()
    • getOutputStream

      public OutputStream getOutputStream()
    • writeToPort

      public void writeToPort(String string, boolean checkCRLF) throws IOException
      Send the passed string to the output stream. If checkCRLF is true, a \r\n is added to the end of the string if it does not already have that
      Parameters:
      string - the text to send
      checkCRLF - if true, append \n to string if needed
      Throws:
      IOException
    • writeToPort

      public void writeToPort(String string) throws IOException
      Send the passed string to the output stream
      Parameters:
      string - the text to send
      Throws:
      IOException
    • checkPortStatus

      public boolean checkPortStatus()
    • getDefaultSerialPortName

      public static String getDefaultSerialPortName()
    • getSerialPort

      public com.fazecast.jSerialComm.SerialPort getSerialPort()
      Returns:
      the serialPort