Menu

Methods

public SerialPort()

Initializes a new instance of the SerialPort class.

public SerialPort(java.lang.String portName)

Initializes a new instance of the SerialPort class using the specified port name.
portName - The port to use (for example, COM1).

public SerialPort(java.lang.String portName, int baudRate)

Initializes a new instance of the SerialPort class using the specified port name and baud rate.
portName - The port to use (for example, COM1).
baudRate - The baud rate.

public SerialPort(java.lang.String portName, int baudRate, Parity parity)

Initializes a new instance of the SerialPort class using the specified port name, baud rate, and parity bit.
portName - The port to use (for example, COM1).
baudRate - The baud rate.
parity - One of the Parity values.

public SerialPort(java.lang.String portName, int baudRate, Parity parity, int dataBits)

Initializes a new instance of the SerialPort class using the specified port name, baud rate, parity bit, and data bits.
portName - The port to use (for example, COM1).
baudRate - The baud rate.
parity - One of the Parity values.
dataBits - The data bits value.

public SerialPort(java.lang.String portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)

Initializes a new instance of the SerialPort class using the specified port name, baud rate, parity bit, and data bits.
portName - The port to use (for example, COM1).
baudRate - The baud rate.
parity - One of the Parity values.
dataBits - The data bits value.
stopBits - One of the StopBits values.

public void Open()
Opens a new serial port connection.
Throws:
ConnectionException
ParameterException

public void close()
Closes the port connection, sets the IsOpen property to false, and disposes of the internal Stream object.

public void Read(byte[] buffer, int offset, int count)
Reads a number of bytes from the SerialPort input buffer and writes those bytes into a byte array at the specified offset.
buffer - The byte array to write the input to.
offset - The offset in buffer at which to write the bytes.
count - The number of bytes to read. The additional byted will be ignored
Throws:
ReadException

public void Write(byte[] buffer, int offset, int count)
Writes a specified number of characters to the serial port using data from a buffer.
buffer - The character array that contains the data to write to the port.
offset - The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.
count - The number of characters to write.
Throws:
WriteException

public static byte[] StringToArrayOfByte(String stringToConvert)
Converts a String to a array of byte to send via com-port
stringToConvert String to convert to array of byte
returns: array of byte to send via COM-Port

Example:
serialPort.Write(SerialPort.StringToArrayOfByte("Hello World"), 0, SerialPort.StringToArrayOfByte("Hello World").length);

public static String ArrayOfByteToString(byte[] arrayToConvert)
Converts an array of byte to String which can be read from Com-Port
arrayToConvert Array of byte to convert to String
returns: Converted String

public boolean isOpened()
Returns TRUE if the serial port has already been opened, FALSE otherwise


Related

Wiki: Home