Connection portal serial scale using JSSC

Asked

Viewed 1,081 times

0

I communicate with a scale via serial port, and today I use the library JSSC however the returns of the hour balance are of weight and time are of different characters, researching I have come to the conclusion that may some door configuration information that may not be legal, but I checked the settings that mark the balance suggests and I did as requested but remains the same way.

Follow the code to extract the information.

import java.io.UnsupportedEncodingException;
import jssc.SerialPort;
import jssc.SerialPortException;
import jssc.SerialPortList;

public class Balanca {

public static void main(String[] args) throws UnsupportedEncodingException {
    String[] portNames = SerialPortList.getPortNames();
    for (String portName : portNames) {
        System.out.println(portName);
    }

    SerialPort serialPort = new SerialPort("COM1");
    try {
        System.out.println("Port opened: " + serialPort.openPort());
        System.out.println("Params setted: " + serialPort.setParams(4800, 8, 1, 0));
        System.out.println("successfully writen to port: " + serialPort.writeBytes(new byte[]{0x04}));
        byte[] buffer = serialPort.readBytes(46);//Read 10 bytes from serial port
        System.out.println(new String(buffer));
        System.out.println("Port closed: " + serialPort.closePort());
    } catch (SerialPortException ex) {
        System.out.println(ex);
    }

}
}

And the way out is this:.

When I get return of characters

COM1
Port opened: true
Params setted: true
successfully writen to port: true
 &��&ӐSӓӐSӓӐSӓӐSӓӐSӓӐS
Port closed: true

When I get data return in numbers

COM1
Port opened: true
Params setted: true
successfully writen to port: true
60013600136001360013600136001360
Port closed: true

The communication I used extracted from the same answer from the forum.

RXTX: serial scale port connection

  • which scale model and make?

  • Friend already got a solution soon put a response.

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.