Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Enumerating Serial Ports in Kura(Raspberry Pi)
Enumerating Serial Ports in Kura [message #1729089] Mon, 11 April 2016 06:53 Go to next message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi,

I'm using USB Ports of Raspberry Pi for Serial Communication. I had a lot of trouble with doing this, and finally I understood what is going on.

I used javax.comm.CommPortIdentifier to check if port exist or not. But sometimes, my USB Ports didn't listed in here. When I check it from Raspberry's terminal, (/dev/ttyUSBx), my port is listed here but I can't get it from inside Kura (by Java).

When I looked inside this CommPortIdentifier class, I noticed that, port names are loading once. The portname loading is in a static block, so the portname list is belongs, when CommPortIdentifier's ClassLoader loads this class. After the class loaded, if you plug another usb or unplug existing one, the port list doesn't change.

Short story, in IoT, we want to build live systems, plug-n- play systems. And this Serial Port scanning is a little bit weird. I have two question (idea),

1 - The javax.comm packet is open for contribution? I believe something should be done about this port name scanning, everything in Kura and IoT world modular, but , I have to restart my Raspberry if I plug USB.

2 - AFAIK, if we plug more than one USB to the device, we need device vid/pid beyond the port name (dev/ttyUSBx). I looked python serial library and love it. I think we should consider it as a reference.

I'm eager to hear your ideas,
Thanks in advance
Said.

[Updated on: Mon, 11 April 2016 13:08]

Report message to a moderator

Re: Enumerating Serial Ports in Kura [message #1731109 is a reply to message #1729089] Mon, 02 May 2016 20:55 Go to previous messageGo to next message
Ilya Binshtok is currently offline Ilya BinshtokFriend
Messages: 14
Registered: September 2015
Junior Member
Hi Said,

Yes, inability to track plug/unplug USB events is a shortcoming of the javax.comm package.
But I think you should still be able to use the /dev/ttyUSB device after unplugging a usb2serial dongle and plugging it back as long as:
1. The usbserial port (i.e. /dev/ttyUSB0) is closed by the user application after device is unplugged.
2. The same /dev/ttyUSB0 port is assigned to the device after it us plugged back.

I believe the following two scenarios would cause the problem:
Scenario 1:
1. A usb2serial device is plugged in and it uses the /dev/ttyUSB0 port.
2. A usb2serial device is unplugged but user application doesn't close the /dev/ttyUSB0 port.
3. A usb2serial device is plugged back, but since the usbserial subsystem thinks that /dev/ttyUSB0 port is in use, it assigns the next available ttyUSB port (i.e. /dev/ttyUSB1).
4. The user application is still configured to use the /dev/ttyUSB0 port.

Scenario 2:
1. A usb2serial device (DUT) is plugged in and it uses the /dev/ttyUSB0 port.
2. The DUT is unplugged and user application closes the /dev/ttyUSB0 port on the IOException.
3. Another usb2serial device is plugged in and usbserial subsystem assignes the /dev/ttyUSB0 port to it.
4. The DUT is plugged back but now the /dev/ttyUSB1 port is assigned to it since the /dev/ttyUSB0 is already being used.
5. The user application is still configured to use the /dev/ttyUSB0 port.

Do you think this is something that may be happening? If so, I think that you may need to modify your application to put USB address instead of /dev/ttyUSB port in your configuration and let USB service to find out what ttyUSB device is assigned. You can use the serialPortExists() method of the PositionServiceImpl.java as an example.

Please let me know if this helps.

Best regards,

Ilya
Re: Enumerating Serial Ports in Kura [message #1733355 is a reply to message #1731109] Thu, 26 May 2016 19:00 Go to previous messageGo to next message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi Ilya,

Your scenarios seem possible. For now, I use one usb2serial device and there is no other device, so, I think I didn't faced your scenario 2. Scenario 1 could be, I will deep look at it. Thanks for you clear examples. But, what I want to say, in the javax.comm package, the loading ports part is in a static block. This means, the block executed only one time, on start-up (When the class load by its classloader). Hence, If I start Kura and my bundle without usb2serial device plugged, after bundle starts, it means nothing to plug usb device. javax.comm never reload ports. This is my problem (1) . To solve my problem to, it is required to solve problem 1 either. I hope I am more clear now.

Sorry for late reply. I was busy for other works.
Thanks again,
Best Regards

Said.
Re: Enumerating Serial Ports in Kura [message #1746888 is a reply to message #1733355] Mon, 07 November 2016 10:20 Go to previous messageGo to next message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi,

Recently, I faced same problem again and I want to ask what can I do under below circumstances.

I think the problem is this, on startup I have ttyUSB0 and I open this SerialPort in my bundle. Somehow, the device I plugged in to Pi is reset and I catch an Exception in my bundle. At this point, the device name changes to ttyUSB1 under my Pi. Due to static loader in javax.comm, I couldn't see this ttyUSB1 device in my portlist. When I add manually using the method CommPortIdentifier.addPortName(), I couldn't open anyway. There is some examples about this port list loading in the internet, like using classloader to reload CommPort class etc. I'm really stuck at this point and if you have an idea it would be great. What should I do when I catch an exception while using both InputStream and OutputStream. Should I try to close port or do nothing? By the way, is Kura Connection Api based on javax.comm or rxtx library?

Best regards,
Said.
Re: Enumerating Serial Ports in Kura [message #1748732 is a reply to message #1746888] Mon, 28 November 2016 06:17 Go to previous messageGo to next message
Ilya Binshtok is currently offline Ilya BinshtokFriend
Messages: 14
Registered: September 2015
Junior Member
Hi Said,

I am currently working on a test bundle that will hopefully handle ttyUSB ports correctly if usb2serial device resets. If it works for me, I'll send you this example to try.

Best regards,

Ilya
Re: Enumerating Serial Ports in Kura [message #1748738 is a reply to message #1748732] Mon, 28 November 2016 07:52 Go to previous messageGo to next message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi Ilya,

It will be really great. I will looking forward,
Thank you so much,

Best Regards,
Said.

Re: Enumerating Serial Ports in Kura [message #1749990 is a reply to message #1748738] Wed, 14 December 2016 20:01 Go to previous messageGo to next message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi Ilya,

Do you have any progress about serial port reconnection bundle? I can try to contribute your work if you can share your code.

Thanks again,
Said.
Re: Enumerating Serial Ports in Kura [message #1751210 is a reply to message #1749990] Thu, 05 January 2017 16:48 Go to previous messageGo to next message
Ilya Binshtok is currently offline Ilya BinshtokFriend
Messages: 14
Registered: September 2015
Junior Member
Hi Said,

I am sorry for not replying earlier, it was a busy end of the year. Please take a look at attached com.eurotech.example.javax.comm project. It is an example of opening and closing ttyUSB port based on UsbDeviceAdded and UsbDeviceRemoved events (see handleEvent() method). Please let me know if you still have problems if you are using this approach.

Best regards,

Ilya
Re: Enumerating Serial Ports in Kura [message #1751259 is a reply to message #1751210] Fri, 06 January 2017 14:08 Go to previous message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi Ilya,

Thanks for your help about this, I will give a try at the weekend and will write the result here.

Thanks again,
Best wishes,

Said.
Previous Topic:Configurable Application not displayed
Next Topic:JDK 8 support? (Error exporting bundle...)
Goto Forum:
  


Current Time: Wed Apr 24 16:08:30 GMT 2024

Powered by FUDForum. Page generated in 0.03574 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top