[purejavacomm] Re: PureJavaComm with Arduino Micro on Windows

  • From: Kustaa Nyholm <feedback2@xxxxxxxxxxxxxxxxx>
  • To: purejavacomm@xxxxxxxxxxxxx
  • Date: Tue, 05 Nov 2013 06:40:42 +0200

On 02/11/2013 10:29, ant elder wrote:
Hi, thank you for PureJavaComm, I've been using it for a project with
Arduino's and its working really well and easy to get going.

I do have one problem when using it with an Arduino Micro board when
PureJavaComm is running in Windows 7, where it hangs reading from the
inputstream.

The same code works fine when running on Linux, and it works fine on
Windows when talking to other Arduino boards like the Uno or Nano. The
Arduino Micro works differently than other Arduino boards in that it has a
virtual serial port, see -
http://arduino.cc/en/Guide/ArduinoLeonardoMicro?from=Guide.ArduinoLeonardo

The interesting parts of my code are:

         serialPort = (SerialPort)commPort.open(this.getClass().getName(),
2000);
         serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
         portWriter = new OutputStreamWriter(serialPort.getOutputStream());
         portReader = new BufferedReader(new
InputStreamReader(serialPort.getInputStream()));

  ... do some other stuff including println's to portWriter, then ...

         jtermios.JTermios.JTermiosLogging.setLogMask(0xFF); // switch on
logging
         String response = portReader.readLine();

and that hangs in the readLine and the logging on the console is:

log: 623209,class purejavacomm.PureJavaSerialPort$2 line 844, thread id 1,
main,>  tcsetattr(0,0,jtermios.Termios@8b99f2e1)
log: 623269,class jtermios.windows.JTermiosImpl line 730, thread id 1,
main,>  SetCommTimeouts(native@0x370 (jtermios.windows.WinAPI$HANDLE@370),
[ReadIntervalTimeout 0 ReadTotalTimeoutMultiplier 0
ReadTotalTimeoutConstant 0 WriteTotalTimeoutMultiplier 0
WriteTotalTimeoutConstant 0])
log: 623271,class jtermios.windows.JTermiosImpl line 730, thread id 1,
main,<  SetCommTimeouts(native@0x370 (jtermios.windows.WinAPI$HANDLE@370),
[ReadIntervalTimeout 0 ReadTotalTimeoutMultiplier 0
ReadTotalTimeoutConstant 0 WriteTotalTimeoutMultiplier 0
WriteTotalTimeoutConstant 0]) =>  true
log: 623273,class jtermios.windows.JTermiosImpl line 589, thread id 1,
main, vmin 1 vtime 0 ReadIntervalTimeout 0 ReadTotalTimeoutConstant 0
ReadTotalTimeoutMultiplier 0
log: 623274,class purejavacomm.PureJavaSerialPort$2 line 844, thread id 1,
main,<  tcsetattr(0,0,jtermios.Termios@8b99f2e1) =>  0
log: 623276,class purejavacomm.PureJavaSerialPort$2 line 891, thread id 1,
main,>  select(1,[0],[],[],jtermios.TimeVal@30296f76)
log: 623277,class jtermios.windows.JTermiosImpl line 757, thread id 1,
main,>  ClearCommError(native@0x370 (jtermios.windows.WinAPI$HANDLE@370),
[0], [fFlags 0000 cbInQue 0 cbInQue 0])
log: 623279,class jtermios.windows.JTermiosImpl line 757, thread id 1,
main,<  ClearCommError(native@0x370 (jtermios.windows.WinAPI$HANDLE@370),
[0], [fFlags 0000 cbInQue 0 cbInQue 0]) =>  true
log: 623280,class jtermios.windows.JTermiosImpl line 806, thread id 1,
main,>  ResetEvent(native@0x398 (jtermios.windows.WinAPI$HANDLE@398))
log: 623281,class jtermios.windows.JTermiosImpl line 806, thread id 1,
main,<  ResetEvent(native@0x398 (jtermios.windows.WinAPI$HANDLE@398)) =>
true
log: 623282,class jtermios.windows.JTermiosImpl line 815, thread id 1,
main,>  SetCommMask(native@0x370 (jtermios.windows.WinAPI$HANDLE@370),
0x00000001)
log: 623284,class jtermios.windows.JTermiosImpl line 815, thread id 1,
main,<  SetCommMask(native@0x370 (jtermios.windows.WinAPI$HANDLE@370),
0x00000001) =>  true
log: 623285,class jtermios.windows.JTermiosImpl line 818, thread id 1,
main,>  WaitCommEvent(native@0x370 (jtermios.windows.WinAPI$HANDLE@370),
[0], auto-allocated@0x7881b60 (32 bytes))
log: 623287,class jtermios.windows.JTermiosImpl line 818, thread id 1,
main,<  WaitCommEvent(native@0x370 (jtermios.windows.WinAPI$HANDLE@370),
[0], auto-allocated@0x7881b60 (32 bytes)) =>  false
log: 623288,class jtermios.windows.JTermiosImpl line 826, thread id 1,
main,>  GetLastError()
log: 623289,class jtermios.windows.JTermiosImpl line 826, thread id 1,
main,<  GetLastError() =>  997
log: 623290,class jtermios.windows.JTermiosImpl line 849, thread id 1,
main,>  WaitForMultipleObjects(2,
[2,native@0x398(jtermios.windows.WinAPI$HANDLE@398
),native@0x38c (jtermios.windows.WinAPI$HANDLE@38c)], false, 2147483647)

I've tried several PureJavaComm releases including the 0.0.18 one but
they're all the same. Any ideas on how to fix this?

Many thanks,

    ...ant

Hi,

nothing leaps to eye, expect that you might want to try (just to test
this) without the BufferedReader and readline, just write code that
performs simple reads from the PureJavaSerialPort input stream.

According to the log the code is happy and waiting for more data...
could be an incompatibility between RXTX and PJC which your
set up forces into the surface.

br Kusti


Other related posts: