java - Incorrectly Reading Serial Using RXTX in Ubuntu -


i reading accelerometer signals connected arduino board through serial interface. using rxtx library , following code.

private void initializeserial() {     commportidentifier portid = null;     enumeration portenum = commportidentifier.getportidentifiers();      while (portenum.hasmoreelements()) {         commportidentifier currentportidentifier = (commportidentifier) portenum.nextelement();         (string portname : port_names) {             if (currentportidentifier.getname().equals(portname)) {                 portid = currentportidentifier;                 break;             }         }     }      if (portid == null) {         system.out.println("port not found");         return;     }      try {          serialport = (serialport) portid.open(this.getclass().getname(), 2000);         serialport                 .setserialportparams(115200, serialport.databits_8, serialport.stopbits_1, serialport.parity_none);          input = new bufferedreader(new inputstreamreader(serialport.getinputstream()));         output = serialport.getoutputstream();          serialport.addeventlistener(this);         serialport.notifyondataavailable(true);      } catch (exception e) {         system.err.println("initialization failed : " + e.tostring());     } }  @override public void serialevent(serialportevent event) {     if (event.geteventtype() == serialportevent.data_available) {         try {             string inputline = input.readline();             string[] inputvalues = inputline.split(",");             system.out.println(inputline);              if (inputvalues.length == 10 && inputvalues[0].equals("stx")                     && inputvalues[inputvalues.length - 1].equals("etx")) {                  double classid = 0;                 double accx = 0;                 double accy = 0;                 double accz = 0;                 boolean num_error = false;                  try {                      classid = integer.parseint(txtclassid.gettext());                     accx = double.parsedouble(inputvalues[2]);                     accy = double.parsedouble(inputvalues[4]);                     accz = double.parsedouble(inputvalues[6]);                     num_error = false;                  } catch (numberformatexception numex) {                     num_error = true;                 }                  if (recording) {                      if (!num_error) {                         gesturelist.add(new double[] { classid, accx, accy, accz });                         system.out.println("classid : " + classid + " \tadding : "+ accx +","+ accy+","+ accz);                     }                      system.out.println("classid : " + classid + " \tadding : " + accx + accy + accz);                 } else {                     if (gesturelist.size() > 0) {                         gesturecollection.add(gesturelist);                         system.out.println("segment :" + (gesturecollection.size()) + "   items : "                                 + gesturelist.size());                         txtsegments.append("segment " + (gesturecollection.size()) + "\titems : "                                 + gesturelist.size() + "\n");                          // combosegments.additem(gesturecollection.size());                          gesturelist = new arraylist<>();                     }                 }                  txtrawdata.append(inputline + "\n");             }         } catch (exception ex) {             ex.printstacktrace();         }     } } 

the problem have that, i'm reading values in windows environment perfectly, without issues. in ubuntu data damaged , partially read. here java console output when did in ubuntu.

these correct readings.

stx,16564.00,16565.65,-352.00,-431.09,-17840.00,-17941.79,-178.64,-42.72,etx stx,16524.00,16562.53,-440.00,-431.76,-17848.00,-17934.75,-178.63,-42.73,etx stx,16572.00,16563.24,-420.00,-430.88,-17992.00,-17939.05,-178.64,-42.72,etx

but readings too. (in considerable amount)

stx,16580.00,16551.27,-432.00,-438.85,-17936.00,-17922.1724.00,16548.94,-380.00,-439.41,-17880.00,-17921.05,-178.61,-42.71,etx

9-178.56,-42.75,etx

.,-454.82,-17944.00,-17916.45,-178.54,-42.72,etx

stx,16584.00,16558.19,-464.00,-465.68,-18007416.00,-446.99,-18008.00,-17935.43,-178.56,-42.71,etx

why happen, can read in windows , not in ubuntu.

any please? thank you.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -