In- and OutputStream "simultaneously" over USB

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, 99jonathan, imaqine

In- and OutputStream "simultaneously" over USB

Postby halfbit » Wed Sep 26, 2012 8:50 am

Hi! New to lejos and the NXT but am really liking it so far :)

My only question so far is, how does one realize it to have an InputStream and OutputStream from the PC to the Brick at pretty much the same time?
I know that the Fantom driver won't allow more then one stream from PC to NXT, but are there maybe mods to the driver/other drivers that would?

Or can it somehow be resolved programatically?
I tried asking for available bytes with the InputStream.available() method, but it always returns 0...
I also tried to shut the InputStream down for some time to write to the NXT and then continue listening again, but that doesn't work either because
  1. Interrupt seems to be ignored in the NXT-Stream
  2. The Thread.stop() method is deprecated and doesn't work anymore
  3. The Thread.wait() method doesn't work on blocking operations (like reading from a Stream...)
And closing the Connection (to abruptly and forcefully cancel the Stream) and creating a new one would be ...really... slow, so that's not really an option.
I know I could just stick with Bluetooth, but I don't really want to limit myself over some stupid, bad drivers. Also I want to try things out and learn^^

So... wat do?

Thanks for any suggestions and help! :)
halfbit
New User
 
Posts: 4
Joined: Wed Sep 26, 2012 8:37 am

Re: In- and OutputStream "simultaneously" over USB

Postby gloomyandy » Wed Sep 26, 2012 9:48 am

What is it you are trying to do? There is no problem with having input and output streams open at the same time. What you can't do is have multiple connects over USB, or have one thread performing a read while another thread attempts to write to the device. This means you are pretty much limited to having one side send data and have the other side respond. I don't believe there is any way around this when using the Lego fantom driver driver, that is simply how it is. Your only option is to either avoid doing this by having say the PC poll the NXT for data, or to not use the Fantom driver, so for instance this limitation does not exist if use use leJOS under Linux (which does not use the Lego driver), you could write your own USB driver for Windows/Mac and this would avoid the problem...

The fantom driver read function is basically a read with a fixed period timeout (approx 20 seconds I think). So probably the best that could be done would be to make the the low level devRead and devWrite calls synchronous. This would have the effect of allowing a write call to take place each time the fantom read call timed out. Which would allow a blocking read from one thread with a write call every 20 seconds or so from another thread. But this is not really a general purpose solution...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: In- and OutputStream "simultaneously" over USB

Postby halfbit » Wed Sep 26, 2012 10:14 pm

gloomyandy wrote:What is it you are trying to do? There is no problem with having input and output streams open at the same time. What you can't do is have multiple connects over USB, or have one thread performing a read while another thread attempts to write to the device.

Yeah that's what I meant, reading and writing at the same time. I've written a little program that remote controls the NXT over USB and Bluetooth (which I'm actually quite proud of :) here and here). Writing works well but I wanted to be prepared for certain "emergency" situations on the NXT. For example if I shut down the NXT by catching a press of the escape key and shutting it down I want to tell the program on the PC do exit as well, but I can't do that because I have no possibility to receive anything from the NXT when I also want to be able to send to it at any given moment (ie remote control it from the PC).
gloomyandy wrote:This means you are pretty much limited to having one side send data and have the other side respond. I don't believe there is any way around this when using the Lego fantom driver driver, that is simply how it is.

Are there no other drivers for Windows that can be used to connect to the NXT?
gloomyandy wrote:[...] you could write your own USB driver for Windows/Mac and this would avoid the problem...

Ah, sadly I'm not yet that good :D

gloomyandy wrote:The fantom driver read function is basically a read with a fixed period timeout (approx 20 seconds I think). So probably the best that could be done would be to make the the low level devRead and devWrite calls synchronous. This would have the effect of allowing a write call to take place each time the fantom read call timed out. Which would allow a blocking read from one thread with a write call every 20 seconds or so from another thread. But this is not really a general purpose solution...

So pretty much read/write cyclus every 20s? That's not really practical for an application that should remote control the NXT ^^'

So I'm pretty much stuck with using Bluetooth if I want to read and write at the same time from windows...
Well at least now I'm sure it's not possible.

Thanks a lot :)

BTW, really nice how active you all are here and how fast you always help! :)
halfbit
New User
 
Posts: 4
Joined: Wed Sep 26, 2012 8:37 am


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff