NeuronRobotics / nrjavaserial

A Java Serial Port system. This is a fork of the RXTX project that uses in jar loading of the native code.
Other
345 stars 143 forks source link

how to encode byte read from com port #149

Closed jrajauriya closed 4 years ago

jrajauriya commented 4 years ago

we are using jSerialComm library. we read byte from com port. but we are not able to encoded byte.

        ```
    public static void main(String[] args) {
    SerialPort comPort = SerialPort.getCommPort("COM1");
    comPort.openPort();     
    comPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY);
    reading_bytes(comPort);
}

      public static void reading_bytes(SerialPort comPort){     
    comPort.addDataListener(new SerialPortDataListener() {
        @Override
        public int getListeningEvents() {
            return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
        }

        @Override
        public void serialEvent(SerialPortEvent event) {
            if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE)
                return;
            byte[] readBuffer = new byte[comPort.bytesAvailable()];
            int numRead = comPort.readBytes(readBuffer, readBuffer.length);
            System.out.println("Read " + numRead + " bytes.");
            for (byte b : readBuffer)
                System.out.print((int) b + ",");
            System.out.println();
        }
    });     
}

and we got following output::


Read 14 bytes.
9,25,35,6,-20,73,-19,-64,33,62,108,-8,116,-2,
Read 0 bytes.

Read 14 bytes.
58,124,28,25,14,-58,24,62,-26,116,-96,7,7,-35,
Read 0 bytes.

Read 14 bytes.
3,6,15,54,59,-116,25,15,15,29,-125,6,-104,-16,
Read 0 bytes.

Read 14 bytes.
-48,-74,-60,100,-122,6,6,6,14,14,14,6,6,6,
Read 0 bytes.
.
.
.
mizoguch-ken commented 4 years ago

How about changing from

System.out.print((int) b + ",");

to

System.out.print((char) b + ",");
jrajauriya commented 4 years ago

@mizoguch-ken thanks for reply. after convert to System.out.print((char) b + ","); we got following row data.

Read 14 bytes.
    ,,#,,~,?,?,?,?,?,,,?,F,
Read 0 bytes.

Read 14 bytes.
,#,,,,,,2,p,>,t,?,,',
Read 0 bytes.

Read 14 bytes.
,,,,h,?,p,?,?,2,f,?,2,2,
Read 0 bytes.

Read 14 bytes.
G,,9,,@,?,,,,,,,,
,
Read 0 bytes.

Read 14 bytes.
,,,,,,,,
,,?,#,,`,
Read 0 bytes.

Read 14 bytes.
,0,p, , ,?,,
,7,l,?,",f,?,
Read 0 bytes.

Read 14 bytes.
,?,,:,h,,r,?,?,1,?,,?,,
Read 0 bytes.

Read 14 bytes.

,,,,
,,,,
,,,,
,,
Read 0 bytes.

Read 14 bytes.
,,
,,,,
,,,,
,,,,
Read 0 bytes.

Read 14 bytes.

,,,,
,,,,
,,,,
,,
Read 0 bytes.
mizoguch-ken commented 4 years ago

If the result is different from what you expect, can you tell me what value you expect?

jrajauriya commented 4 years ago

expected result something like this:

O|1|LID668||^WBC^^\^RBC^^|R||20030516161149||||A||The
patient is abc.|||Dr. xyz||sus.blasts^?\var.
lymph^++||100^\^|1.00^2.0^3.0^4.0^5.0^6.0^7.0^8.0^^^^
^^8.0^10.0^11.0^12.0^13.0^14.0^15.0^^^^^||||Q<CR>
mizoguch-ken commented 4 years ago

I think that byte data and expected value do not match. Is the communication setting correct?

jrajauriya commented 4 years ago

yes, we set the parameters comPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY); according to machine manual.

mizoguch-ken commented 4 years ago

Is it possible to get the actual settings instead of the manual?

jrajauriya commented 4 years ago

@mizoguch-ken yes it is possible, we got same output from com port to without set baud rate, data bits and parity.

mizoguch-ken commented 4 years ago

From the expected results, I think it is probably a LIS Interface. If so, Can I view Configure LIS settings with DM Configuration Tool?

madhephaestus commented 4 years ago

not an issue in the library, closing