Package serialComms.jserialcomm
Class PJSerialComm
java.lang.Object
serialComms.jserialcomm.PJSerialComm
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 Summary
Modifier and TypeMethodDescriptionvoidaddCharListener(PJSerialLineListener serialLineListener) voidaddDataListener(com.fazecast.jSerialComm.SerialPortDataListener serialPortDataListener) Call through to underlying serial port to add a data listener.voidaddLineListener(PJSerialLineListener serialLineListener) booleanbooleanClose the serial port and any associated data buffers.static Stringcom.fazecast.jSerialComm.SerialPortstatic String[]Get a list of available comm ports in alphabetical order.static com.fazecast.jSerialComm.SerialPort[]static PJSerialCommopenSerialPort(String portName, int baudRate) Create and open a serial port with default values of 8 data bits; 1 stop bit; no parity and flow control disabled.static PJSerialCommopenSerialPort(String portName, int baudRate, int dataBits, int stopBits, int parity, int flowControl) Create and open a serial port.static PJSerialCommopenSerialPort(SerialPortParameters serialPortParameters) Open a serial port with parameters defined in serialPortParametersstatic booleanportExists(String portName) Check whether a port exists.voidwriteToPort(String string) Send the passed string to the output streamvoidwriteToPort(String string, boolean checkCRLF) Send the passed string to the output stream.
-
Method Details
-
openSerialPort
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 ratedataBits- data bitsstopBits- stop bitsparity- parityflowControl- flow control- Returns:
- valid port object. Never null (throws exception first)
- Throws:
PJSerialException- exception if port unavailable or busy.
-
addLineListener
-
addDataListener
public void addDataListener(com.fazecast.jSerialComm.SerialPortDataListener serialPortDataListener) Call through to underlying serial port to add a data listener.- Parameters:
serialPortDataListener-
-
addCharListener
-
closePort
public boolean closePort()Close the serial port and any associated data buffers.- Returns:
- true if any reading threads close properly.
-
portExists
Check whether a port exists.- Parameters:
portName- port name (.e.g- Returns:
- true if it exists
-
getSerialPortNames
Get a list of available comm ports in alphabetical order.- Returns:
-
getSerialPorts
public static com.fazecast.jSerialComm.SerialPort[] getSerialPorts() -
getOutputStream
-
writeToPort
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 sendcheckCRLF- if true, append \n to string if needed- Throws:
IOException
-
writeToPort
Send the passed string to the output stream- Parameters:
string- the text to send- Throws:
IOException
-
checkPortStatus
public boolean checkPortStatus() -
getDefaultSerialPortName
-
getSerialPort
public com.fazecast.jSerialComm.SerialPort getSerialPort()- Returns:
- the serialPort
-