[Rxtx] RXTX issue for not reading some dat

Daniel Morales Salas damorales at gmail.com
Thu Sep 22 10:57:57 MDT 2011


Have you tried purejavacomm ??

Greetings!

2011/9/22 vishal prasad <vishal.pdmail at gmail.com>

> Hi,
>
> Subject: RXTX losing data while reading  from a device.
>
> I am trying to read data from a device which sends  hex data,like
>
> Hex Data : 03 03  16  086)0  100   00  00 00  00 03  00  00 00  00 00  00
> 00 00 00 00 00 00
>
> Converted Data (Of interest to me ) 3.16 8.36 29.3 10.04  for values
> displayed on Device 3.16 8.36 29.3 10.04.
>
> The above data format and conversion have been obtained form cutecom, a Qt
> based serial Terminal program for Linux.
> As shown,  the conversion and device readings are exact.
>
> I am trying to fine tune the Java code so that I can read the data from the
> Device as consistently and correctly as cutecom does.
>
> After several attempts at fine tuning, I am still not able to read
> correctly and consistently from the device with my Java code using RXTX.This
> same code reads fine from other devices which do not send data in Hex
> format. Also, the same code when run under MS Windows, reads the first two
> values (3.16, 8.36) correctly about 90% of the time. But under Linux, it
> always loses binary data in several bytes. The loss occurs throughout the
> length of the Hex string at different times. I can rule out hardware / OS
> issues because cutecom is unfailingly giving correct readings all the time.
> I am lost as to what could be causing this behaviour? I have changed my read
> methods to , read(), read(bytes), read(bytes,offset,lenght), I have changed
> input streams to Java standard input stream and
> RXTXPORT.SerialPortInputstream. I have stored the binary data in bytes[ ],
> (value of binary data)  integer array[ ]. But no variation in technique is
> helping me to read the binary stream without loss.
>
> I have also run the program under SunJava and Openjdk.
>
> Any help will be greatly thanked for and appreciated in understanding the
> possible flaws in code. May I request that anybody willing to help will show
> the necessary changes in the attached code itself?
>
> (code is attached below)
> I just want to read the binary data or the integer equivalent . I have the
> decoding algorithm with me.
>
> I am using java version "1.6.0_22"
> OpenJDK Runtime Environment (IcedTea6 1.10.2) (suse-4.3.1-i386) ( swapped
> with Sun Java 1.6.u25)
>
> OpenJDK Server VM (build 20.0-b11, mixed mode)
> and RXTX-2.1-7 and Netbeans 7.0.1 for development.
>
> import gnu.io.*;
> import java.io.*;
> import java.util.*;
> import java.util.TooManyListenersException;
> import java.util.logging.Level;
> import java.util.logging.Logger;
>
> public class DeviceFinal {
>
>
>     public static CommPortIdentifier portId;
>     public static SerialPort serialPortUltra;
>     public static InputStream myIn;
>     public static DataInputStream dIns;
>     public static OutputStream myOs;
>     public static String portName="/dev/ttyS3";
>     //public static String portName="COM1";
>     public static RXTXPort rxtxport;
>
>
>     public static void HwDeviceTest(){
>
>        try {// try block no 1: to open port
>             //portId=CommPortIdentifier.getPortIdentifier(portName);
>             portId=CommPortIdentifier.getPortIdentifier(portName);
>             rxtxport=(RXTXPort)portId.open("Device Port",2000);
>
>             try{// try block 2 inside 1 : seting port parameters
>                 rxtxport.setSerialPortParams(2400,8,1,0);
>                 rxtxport.setFlowControlMode(0);
>
>                 try { // try block 3 inside 2 of 1 : setting input stream
>                     //myIn=rxtxport.getInputStream();
>                     myIn=rxtxport.getInputStream();
>                 } catch (Exception ex) {
>                     System.err.print("IO Exception occured");
>                 }// try block 3 inside 2 of 1 ends here
>                 try { // Inside 3nd Try of Second. setting output
> parameters
>                    myOs=new FileOutputStream("myfile.txt");
>
>                } catch (IOException ex) {
>                     System.err.println("Can't open output stream");
>                 }
>                 try{ // try block 4 inside 2 of 1 : dat avaliable
> notification
>
>                     try{ // checking for data avaliable
>                         rxtxport.notifyOnDataAvailable(true);
>                     }catch(NullPointerException ee){
>
>                     }
>                     rxtxport.enableReceiveTimeout(60);
>                     rxtxport.addEventListener(new
> Devicedata(serialPortUltra));
>                 }catch(TooManyListenersException e){
>
>              }
>             }catch(UnsupportedCommOperationException e12){
>                 System.err.println("comm port not supported");
>             } // try block 2 inside 1 ends here
>
>         } catch (NoSuchPortException ex) {
>             System.err.println("Sorry! Cannot find port!"+portName);
>         } catch (PortInUseException ex1) {
>             System.err.println("port In use exception occured");
>         } // try block no1 ends here
>
>     }
>
>         // Start of inner class
>       public static class Devicedata implements SerialPortEventListener {
>
>           public byte[]        tempByte=new byte[30];
>           public byte[ ]     byteArray=new byte[25];
>           public byte[ ][ ]  byteStoreArray=new byte[25][240];
>           public int[ ]      noOfBytesArray= new int[25];
>           public int[ ]      intArray=new int[30];
>           StringBuffer strBuffer;
>           byte[] buffer = new byte[1024];
>           int counter=0;
>           public Devicedata(SerialPort portname){
>
>           }
>           public void serialEvent(SerialPortEvent event){
>               //System.out.println("Trying to read from Device");
>
>
>
>                  int data;
>
>                  try
>                  {
>                      int len = 0;
>                      while ( ( data = myIn.read()) > -1 )
>                     {
>                         System.out.println("data="+data);
>                     }
>
>                  }catch ( IOException e ){
>                         e.printStackTrace();
>
>                  }
>
>           }
>      }// end of inner class
>     public static void main(String[] args) {
>         // TODO code application logic here
>         DeviceFinal.HwDeviceTest();
>     }
> }
>
> OUTPUT WHEN RUN IN LINUX
>
> run:
> Stable Library
> =========================================
> Native lib Version = RXTX-2.1-7
> Java lib Version   = RXTX-2.1-7
> RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyS3
> data=0
> data=0
>  data=0
> data=0
> data=134
> data=0
> data=0
> data=224
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=134
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
>  data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
> data=0
>  data=0
> data=0
>
> EXPECTED OUTPUT for  actual reading in device- 3.0 9.1 32.4 2.55
> data=3
>  data=0
>  data=144
>  data=16 or 1
>  data=50
>  data=64 or 4
>  data=2
>  data=85
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=134
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>  data=0
>
> Regards
> Vishal Prasad
> Java developer with extensive RXTX API
> Bangalore, India
>
> _______________________________________________
> Rxtx mailing list
> Rxtx at qbang.org
> http://mailman.qbang.org/mailman/listinfo/rxtx
>
>


-- 
Atte:
Daniel Dario Morales Salas
Ingeniero Civil en Computación e Informática
Teléfono: 02 684 3417
Celular: 06 594 1574
Santiago, Chile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qbang.org/pipermail/rxtx/attachments/20110922/c87c4c89/attachment-0154.htm>


More information about the Rxtx mailing list