1

I googled lot about reading from a com port but it seems very difficult work for me. I found this but I don't know how to add jSSC library to my netbeans project.

Please help me by giving instructions to adding that library to my project or giving a simple code to read a string/character from a com port.

1 Answer 1

2

To add jSSC library in netbeans, right click on "Libraries" in your project and then "add JAR/Folder..." to select your file(s)

enter image description here

You can read with something like this :

SerialPort serialPort = new SerialPort("/dev/ttyUSB0");// For windows "COMX" (e.g : "COM1") should works
if (serialPort.openPort()) {
    serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_ODD);
    byte[] buffer = serialPort.readBytes(1);// Read one byte
    String str = new String(buffer);
    serialPort.closePort();
}
Sign up to request clarification or add additional context in comments.

4 Comments

I mean your library file(s). For jSSC add "jssc.jar" and then you can use it (import jssc.SerialPort;)
when i used System.out.println(str) It shows only one letter and stops. What changes do i have to do?
If you know how many bytes you will have replace "1" by your number in readBytes, otherwise you can use "getInputBufferBytesCount".
Thank u very much I can do what I wanted now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.