[purejavacomm] Re: PureJavaComm with Arduino Micro on Windows

  • From: ant elder <ant.elder@xxxxxxxxx>
  • To: purejavacomm@xxxxxxxxxxxxx
  • Date: Wed, 6 Nov 2013 20:05:20 +0000

Ok that problem is fixed, i stumbled upon this discussion explaining that
you need to set DTR high -

http://forum.arduino.cc/index.php?PHPSESSID=4jj1gs018301ipo4c1pfc1ll42&topic=119557.msg1044485#msg1044485

so in my Java code doing serialPort.setDTR(true) just after its opened
appears to fix the problem.

I've another problem now where it usually hangs while trying to close the
serial port. I've a thread dump of the hang which shows it in a
PureJavaComm call. Any ideas on this one?

"System Bundle Shutdown" prio=6 tid=0x0000000010e37800 nid=0x23b0 runnable
[0x00000000147cd000]
   java.lang.Thread.State: RUNNABLE
        at com.sun.jna.Native.invokeInt(Native Method)
        at com.sun.jna.Function.invoke(Function.java:332)
        at com.sun.jna.Function.invoke(Function.java:276)
        at com.sun.jna.Library$Handler.invoke(Library.java:218)
        at com.sun.proxy.$Proxy6.GetOverlappedResult(Unknown Source)
        at jtermios.windows.WinAPI.GetOverlappedResult(WinAPI.java:731)
        at jtermios.windows.JTermiosImpl$Port.close(JTermiosImpl.java:163)
        - locked <0x00000007c3518ed8> (a jtermios.windows.JTermiosImpl)
        at jtermios.windows.JTermiosImpl.close(JTermiosImpl.java:512)
        at jtermios.JTermios.close(JTermios.java:397)
        at
purejavacomm.PureJavaSerialPort.close(PureJavaSerialPort.java:1026)
        - locked <0x00000007c3518f78> (a purejavacomm.PureJavaSerialPort)
        at com.ibm.ws.arduino.impl.ArduinoImpl.close(ArduinoImpl.java:116)
        at com.ibm.ws.arduino.impl.Activator.stop(Activator.java:17)
        at
org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:771)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:764)
        at
org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:510)
        at
org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:566)
        at
org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1206)
        at
org.eclipse.osgi.framework.internal.core.StartLevelManager.decFWSL(StartLevelManager.java:592)
        at
org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:257)
        - locked <0x00000007c3519248> (a java.lang.Object)
        at
org.eclipse.osgi.framework.internal.core.StartLevelManager.shutdown(StartLevelManager.java:215)
        at
org.eclipse.osgi.framework.internal.core.InternalSystemBundle.suspend(InternalSystemBundle.java:284)
        at
org.eclipse.osgi.framework.internal.core.Framework.shutdown(Framework.java:692)
        - locked <0x00000007c35781c8> (a
org.eclipse.osgi.framework.internal.core.Framework)
        at
org.eclipse.osgi.framework.internal.core.Framework.close(Framework.java:600)
        - locked <0x00000007c35781c8> (a
org.eclipse.osgi.framework.internal.core.Framework)
        at
org.eclipse.osgi.framework.internal.core.InternalSystemBundle$1.run(InternalSystemBundle.java:261)
        at java.lang.Thread.run(Thread.java:744)

Thanks again for all your help.

   ...ant



On Tue, Nov 5, 2013 at 4:40 AM, Kustaa Nyholm
<feedback2@xxxxxxxxxxxxxxxxx>wrote:

> 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: