Figure out when NXT has disconnected

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

Moderators: roger, 99jonathan, imaqine

Figure out when NXT has disconnected

Postby clintonb » Sat Nov 03, 2012 3:31 am

Greetings.

As part of Enchanting, a program to help kids program their NXT, a user connects and NXT to their computer, and the software recognizes it, and they program it and might remove the NXT (or it could go to sleep), while they continue to code (and the cycle repeats). It is expected that the code editor will deal gracefully with the NXT connecting or disconnecting.

I'm using code that reads messages from the NXT (and acts upon them), and, when it gets an exception, it knows that the NXT has disconnected. This worked fine using leJOS 0.9.0, but I am having difficulties doing so with leJOS 0.9.1.

While I may well be doing things "wrong", and would be happy to have an alternative method, here is some shortened (but compiling code) that illustrates the issues, followed by sample output. Note that this code runs on the computer, and doesn't care about which firmware is on the NXT. Also note that you do need to change a couple of lines with '///', based on the comments, to make it compile for leJOS 0.9.0 or 0.9.1.

Code: Select all
import java.io.*;
import lejos.nxt.remote.*;
import lejos.pc.comm.*;

// The purpose of this application is to test when the NXT is connected or disconnected

public class ConnectionTest {

   private String nxtname = "";
   private String address = "";
   private int protocols = NXTCommFactory.USB; // | NXTCommFactory.BLUETOOTH;
   /// private NXTCommand nxtcommand = new NXTCommand();   /// use in leJOS 0.9.0
   private NXTCommand nxtcommand;                     /// use in leJOS 0.9.1
   private NXTConnector nxtconnector = new NXTConnector();

   public void delay(int ms) {
      try {
         Thread.sleep(500);      
      } catch (InterruptedException e) {
         // we are unlikely to be interrupted
         throw new RuntimeException(e);
      }   
   }

   ConnectionTest() {
      while (true) {
      
         // Connect to an NXT
         boolean connected = false;
         System.out.print("Connecting");
         while (!connected) {
            delay(500);
            System.out.print(".");
            
            try {
               connected = nxtconnector.connectTo(nxtname, address, protocols);
            } catch (java.lang.RuntimeException e) {
               System.out.println("\nRuntimeException occurred while trying to connect to NXT: " + e.getMessage());
            }
         }
         System.out.println(" Connected.");
         /// nxtcommand.setNXTComm(nxtconnector.getNXTComm());   /// use in leJOS 0.9.0
         nxtcommand = new NXTCommand(nxtconnector.getNXTComm()); /// use in leJOS 0.9.1
         
         // Communicate with the NXT until we are disconnected
         try {
            System.out.print("Reading data: ");
            while (true) {
               byte[] message = nxtcommand.messageRead((byte) 0, (byte) 0, true);
               System.out.printf("%d, ", message.length);
               delay(500);   
            }
         } catch (IOException e) {
            System.out.println("\nIOException occurred while reading messages: " + e.getMessage());
         }
         System.out.println("\nDisconnected.");
      }
   }

   public static void main(String[] args) {
      new ConnectionTest();
   }
}


After setting environment variables, I compile and run this program thusly:

Code: Select all
nxjpcc ConnectionTest.java && nxjpc ConnectionTest


Here are the results (which I expect) using leJOS 0.9.0:
(Note that the $ indicates the bash prompt on my OS computer, and ^C appears when I press control-C).

Code: Select all
$ nxjpcc ConnectionTest.java && nxjpc ConnectionTest
Connecting....................Found NXT: NXT 00165313BBE5
 Connected.
Reading data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
IOException occurred while reading messages: Failed to send data

Disconnected.
Connecting.......................Found NXT: NXT 00165313BBE5
 Connected.
Reading data: 0, 0, 0, 0, 0,
IOException occurred while reading messages: Failed to send data

Disconnected.
Connecting.............Found NXT: NXT 00165313BBE5
 Connected.
Reading data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
IOException occurred while reading messages: Failed to send data

Disconnected.
Connecting...^C$


I connect and disconnect several times, and everything works well.


Here is what happens using leJOS 0.9.1:

Code: Select all
$ nxjpcc ConnectionTest.java && nxjpc ConnectionTest
Connecting.................Found NXT: NXT 00165313BBE5
 Connected.
Reading data: 0, 0, 0, 0, 0, 0, ^C$


I finally press control-C to quit the application after it, well, stopped responding for many seconds. (I've let this run for a long time and never seen it start to respond again). Also, the 'java' process on my computer starts using 99% of the CPU while this is blocking, and of course goes away when I quit the program.


If I adjust the code slightly to only use bluetooth connections, and pair my device to my computer so they'll work, this is what I get with leJOS 0.9.0:

Code: Select all
$ nxjpcc ConnectionTest.java && nxjpc ConnectionTest
Connecting.BlueCove version 2.1.0 on mac
. Connected.
Reading data: 0, 0, 0, 0, 0,
IOException occurred while reading messages: End of file

Disconnected.
Connecting. Connected.
Reading data: 0, 0, 0, 0, 0, 0, 0, 0, 0,
IOException occurred while reading messages: Failed to write [0xe00002d7]

Disconnected.
Connecting.^CBlueCove stack shutdown completed
$


It takes several seconds to connect, and must be fifteen seconds or so before it recognizes that I've turned off my NXT, but everything works right.


Here's what I get using bluetooth with leJOS 0.9.1:

Code: Select all
$ nxjpcc ConnectionTest.java && nxjpc ConnectionTest
Connecting.BlueCove version 2.1.0 on mac
 Connected.
Reading data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
IOException occurred while reading messages: Failed to write [0xe00002d7]

Disconnected.
Connecting.
RuntimeException occurred while trying to connect to NXT: already connected
.
RuntimeException occurred while trying to connect to NXT: already connected
.
RuntimeException occurred while trying to connect to NXT: already connected
.
RuntimeException occurred while trying to connect to NXT: already connected
.
RuntimeException occurred while trying to connect to NXT: already connected
.


It went on and on, repeating those last two lines of output, and never did reconnect.


Is there something I should be doing differently, to know when the NXT has disconnected, and to reconnect to it when it becomes available again?

Thank you,
Clinton Blackmore
clintonb
Active User
 
Posts: 87
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Figure out when NXT has disconnected

Postby skoehler » Sat Nov 03, 2012 10:47 am

When you disconnect the NXT, what do you mean? Are you using USB or Bluetooth? If USB, do you mean you simply unplug the USB cable?
skoehler
leJOS Team Member
 
Posts: 1128
Joined: Thu Oct 30, 2008 4:54 pm

Re: Figure out when NXT has disconnected

Postby clintonb » Sat Nov 03, 2012 12:59 pm

In the simplest form, with a USB connection, the device is disconnected when you unplug the USB cable between them. (This is reasonable if you upload a program that requires the robot to move around, then unplug it, try it, and plug it back in to make changes, and so on).

With either a bluetooth or USB connection, the NXT is disconnected when it turns off -- either through a user turning it off, or from it turning itself off to fall asleep (or, presumably, if it loses power).

Lastly, and it never occurred to me before now, bluetooth could be disconnected if the user turns off the bluetooth radio on their computer or on their NXT, of, if the NXT goes out of range.


I am primarily using USB in my testing, and turning off the NXT to disconnect it.
clintonb
Active User
 
Posts: 87
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Figure out when NXT has disconnected

Postby skoehler » Sat Nov 03, 2012 2:47 pm

and you're using Linux, right?
skoehler
leJOS Team Member
 
Posts: 1128
Joined: Thu Oct 30, 2008 4:54 pm

Re: Figure out when NXT has disconnected

Postby clintonb » Sat Nov 03, 2012 2:56 pm

My primary development platform is the Mac, but enchanting is cross platform and I need a method that will work on Mac, windows, and Linux. (The results above are from Mac OS X 10.7.4).
clintonb
Active User
 
Posts: 87
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Figure out when NXT has disconnected

Postby skoehler » Sat Nov 03, 2012 3:30 pm

clintonb wrote:My primary development platform is the Mac, but enchanting is cross platform and I need a method that will work on Mac, windows, and Linux. (The results above are from Mac OS X 10.7.4).


I was hoping that it would not be the Mac *sigh*. I cannot really support Mac, as I don't own one. I can however run your program on Windows and Linux. You will have to assist me by running some tests on your Mac.

In the end, it might not even be a problem with leJOS code, but a problem with the fantom driver. (You have the latest version installed?)

BTW: The mac platform means big trouble for us anyways, as Lego doesn't provide a 64Bit driver and Oracle has dropped support for 32 Bit Java on the Mac.
And the fantom driver is not the best piece of software anyways.

Actually, how does the NXT-G 2.0 software perform? Does it reliably detect a disconnect?


Regards,
Sven
skoehler
leJOS Team Member
 
Posts: 1128
Joined: Thu Oct 30, 2008 4:54 pm

Re: Figure out when NXT has disconnected

Postby clintonb » Sat Nov 03, 2012 10:24 pm

skoehler wrote:I was hoping that it would not be the Mac *sigh*. I cannot really support Mac, as I don't own one. I can however run your program on Windows and Linux. You will have to assist me by running some tests on your Mac.


I'd be delighted to run some tests on my Mac. I should run some tests on Windows and Linux and post the output, too -- I'll do that if I have time and it would help. I do believe that this is an issue on Windows as well, and just assumed that it was under Linux.

skoehler wrote:In the end, it might not even be a problem with leJOS code, but a problem with the fantom driver. (You have the latest version installed?)


I think so; I'll download and install the latest version just to be certain.

skoehler wrote:BTW: The mac platform means big trouble for us anyways, as Lego doesn't provide a 64Bit driver and Oracle has dropped support for 32 Bit Java on the Mac.


Yes, I recently noticed Java 7 on another Mac and thought, more or less, "Drat. I wonder if leJOS can still load Lego's 32-bit driver using this version of Java."

skoehler wrote:And the fantom driver is not the best piece of software anyways.


I'd come to that conclusion, too.

skoehler wrote:Actually, how does the NXT-G 2.0 software perform? Does it reliably detect a disconnect?


I'm trying to remember if it indicates when an NXT dis/connects or not while you are using it. I don't have it installed on my Mac at the moment to test it. I don't recall any issues; I think it works fine.


Sven, perhaps I can offer some assistant on the Mac version of leJOS. My project is pretty tightly entwined with it; it sure wouldn't hurt to understand it better.

As I recall, leJOS generalizes the method used to connect to a device, and then offers specific implementations using Fantom, bluetooth, and libUSB. The Linux version uses libUSB 0.1, right? It looks like libUSB 1.0 should work on the Mac, and there is a compatibility library for code targetting libUSB 0.1 to use 1.0.

I'll see if I can figure out how to compile leJOS, and libUSB, and if I can make the two work together. Java is not my strong suit, and I've never touched JNI code, but I was a professional C++ programmer, so there is hope. I'm bound to run into things I don't understand -- it opening another thread on this forum the best place to ask questions?

Alternative and/or supplementally, I can make my computer available for remote access -- perhaps using Skype, perhaps something else. Many weekdays I could make time from say 5:30 to 6:30 am or 7 to 9 pm Mountain Standard Time (googling "Time in Edmonton" will tell you). If anyone would like to take me up on that for making leJOS work with the new java on the Mac, my contact info is here.

Cheers,
Clinton
clintonb
Active User
 
Posts: 87
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Figure out when NXT has disconnected

Postby skoehler » Sat Nov 03, 2012 11:53 pm

clintonb wrote:Sven, perhaps I can offer some assistant on the Mac version of leJOS. My project is pretty tightly entwined with it; it sure wouldn't hurt to understand it better.

As I recall, leJOS generalizes the method used to connect to a device, and then offers specific implementations using Fantom, bluetooth, and libUSB. The Linux version uses libUSB 0.1, right? It looks like libUSB 1.0 should work on the Mac, and there is a compatibility library for code targetting libUSB 0.1 to use 1.0.


For USB: Lego's fantom driver is used on Windows and OS X. libusb is used on Linux only.
For Bluetooth: Bluecove (a java library) is used on all platforms.

And there more bad news: Unfortunately, Bluecove doesn't work on OS X 10.8 and up anymore and the maintainer of the Bluecove project is pretty inactive right now.

I talked to the libusbx people (a fork of libusb). They said, that libusbx (which is still pretty much the same as libusb) will work on OS X, but it
a) cannot the detach the Lego Fantom driver from a device. So if the Lego Fantom driver claims the device, we will not be able to communicate with it
b) will require a so called "codeless kext" to prevent the cdc_acm driver from claiming the Lego NXT device when it's in firmware update mode (The NXT mimics an ordinary serial device, which of course would be usually claimed by some default OS X driver)

Note, that I believe the Lego Fantom driver already "overrides" OS X's default cdc_acm driver when it comes to the NXT in firmware update mode. Hence, a serial device may not be created if the Lego Fantom driver is installed. What a mess.

clintonb wrote:I'll see if I can figure out how to compile leJOS, and libUSB, and if I can make the two work together. Java is not my strong suit, and I've never touched JNI code, but I was a professional C++ programmer, so there is hope. I'm bound to run into things I don't understand -- it opening another thread on this forum the best place to ask questions?


We need solution "for the masses". I mean, requiring that people uninstall the Lego Driver will probably drive them mad. (As they can't switch between firmwares easily)
On the other hand, not using the Fantom driver was never very stable (especially when I/O was performed by different threads in parallel).

To get libusb (and maybe libusbx) your might have to install macports.
In order to avoid trouble with the Driver, we might have to change the NXTs USB ID, so that the device won't be claimed by the Fantom driver anymore.
However, before we do that, we first have to finish winusb support for Windows, so that we can ship our own driver (that is based on winusb) for Windows XP and above.

Basically, you could also simply write a C/C++ program to
a) iterate over the connected NXTs
b) connect to an NXT and maybe query it for its name

We can turn that into JNI code later.

clintonb wrote:Alternative and/or supplementally, I can make my computer available for remote access -- perhaps using Skype, perhaps something else. Many weekdays I could make time from say 5:30 to 6:30 am or 7 to 9 pm Mountain Standard Time (googling "Time in Edmonton" will tell you). If anyone would like to take me up on that for making leJOS work with the new java on the Mac, my contact info is here.


That is very kind of you. But I think I would need physical access to your computer for rebooting, unplugging an NXT, etc.
Also right now, I'm not really sure what to do.
skoehler
leJOS Team Member
 
Posts: 1128
Joined: Thu Oct 30, 2008 4:54 pm

Re: Figure out when NXT has disconnected

Postby clintonb » Sun Nov 04, 2012 1:03 am

skoehler wrote:And there more bad news: Unfortunately, Bluecove doesn't work on OS X 10.8 and up anymore and the maintainer of the Bluecove project is pretty inactive right now.


Darn. That's news to me; it does look like several people are working on it -- I do hope they have success.

If we do find another way to use the fantom library, it takes care of bluetooth connections -- but I'm sure that it is nice to use the bluecove code on every platform if at all possible.

skoehler wrote:I talked to the libusbx people (a fork of libusb). They said, that libusbx (which is still pretty much the same as libusb) will work on OS X, but it
a) cannot the detach the Lego Fantom driver from a device. So if the Lego Fantom driver claims the device, we will not be able to communicate with it
b) will require a so called "codeless kext" to prevent the cdc_acm driver from claiming the Lego NXT device when it's in firmware update mode (The NXT mimics an ordinary serial device, which of course would be usually claimed by some default OS X driver)

Note, that I believe the Lego Fantom driver already "overrides" OS X's default cdc_acm driver when it comes to the NXT in firmware update mode. Hence, a serial device may not be created if the Lego Fantom driver is installed. What a mess.


Yuck indeed.

skoehler wrote:
clintonb wrote:I'll see if I can figure out how to compile leJOS, and libUSB, and if I can make the two work together. Java is not my strong suit, and I've never touched JNI code, but I was a professional C++ programmer, so there is hope. I'm bound to run into things I don't understand -- it opening another thread on this forum the best place to ask questions?


We need solution "for the masses". I mean, requiring that people uninstall the Lego Driver will probably drive them mad. (As they can't switch between firmwares easily)
On the other hand, not using the Fantom driver was never very stable (especially when I/O was performed by different threads in parallel).


I agree -- we need a solution for the masses.

Some sort of solution that requires an admin password (and a restart?!) to move one library to the side and another into its place might be livable, but it wouldn't really be for the masses.

I wonder if this will become a problem for LEGO. Is there any way at all to:
1) find out if they plan to produce a 64-bit library?
2) load a 32-bit plugin from a 64-bit program?

I'm pretty sure "2" is a no, and "1" may be moot.

skoehler wrote:To get libusb (and maybe libusbx) your might have to install macports.
In order to avoid trouble with the Driver, we might have to change the NXTs USB ID, so that the device won't be claimed by the Fantom driver anymore.
However, before we do that, we first have to finish winusb support for Windows, so that we can ship our own driver (that is based on winusb) for Windows XP and above.


I'm not fond of MacPorts. I'd see if I can compile it without it, but if that is what it takes, thats what it takes.

Do you mean to say that when we upload the firmware onto the NXT, we can change the USB IDs so that a different driver can talk to it? Interesting. On the minus side, would that not mean that no third-party tools could be used to access the device (such as using NXT-G to restore the stock firmware) -- or would it -- what would happen when the device is in firmware update mode -- surely we can't change those IDs.

skoehler wrote:Basically, you could also simply write a C/C++ program to
a) iterate over the connected NXTs
b) connect to an NXT and maybe query it for its name

We can turn that into JNI code later.


I've done something like that in the past. I'll see if I can find the source, or recreate it -- the project didn't get very far.

How does this limited functionality help in interfacing 64-bit Java to the 32-bit fantom driver, supporting the functionality leJOS needs?

skoehler wrote:
clintonb wrote:Alternative and/or supplementally, I can make my computer available for remote access -- perhaps using Skype, perhaps something else. Many weekdays I could make time from say 5:30 to 6:30 am or 7 to 9 pm Mountain Standard Time (googling "Time in Edmonton" will tell you). If anyone would like to take me up on that for making leJOS work with the new java on the Mac, my contact info is here.


That is very kind of you. But I think I would need physical access to your computer for rebooting, unplugging an NXT, etc.
Also right now, I'm not really sure what to do.


I can be your hands in the remote location. I have debugged a little like this and its a pain, but it does help.


Oh, one more thing. Detecting disconnects is not an issue with the Fantom driver. My tests with leJOS 0.9.0 and 0.9.1 were on the same computer, minutes apart, with the same driver, and one worked while the other ... responds differently.
clintonb
Active User
 
Posts: 87
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Figure out when NXT has disconnected

Postby skoehler » Sun Nov 04, 2012 1:44 am

clintonb wrote:
skoehler wrote:And there more bad news: Unfortunately, Bluecove doesn't work on OS X 10.8 and up anymore and the maintainer of the Bluecove project is pretty inactive right now.


Darn. That's news to me; it does look like several people are working on it -- I do hope they have success.

If we do find another way to use the fantom library, it takes care of bluetooth connections -- but I'm sure that it is nice to use the bluecove code on every platform if at all possible.


I believe leJOS tried to use the fantom driver for bluetooth but then moved away from using the it for bluetooth. And I don't trust the fantom driver, e.g. when it comes to doing I/O from different threads etc.
Hence, I'd like to stay away from the fantom library when it comes to bluetooth.

clintonb wrote:
skoehler wrote:
clintonb wrote:I'll see if I can figure out how to compile leJOS, and libUSB, and if I can make the two work together. Java is not my strong suit, and I've never touched JNI code, but I was a professional C++ programmer, so there is hope. I'm bound to run into things I don't understand -- it opening another thread on this forum the best place to ask questions?


We need solution "for the masses". I mean, requiring that people uninstall the Lego Driver will probably drive them mad. (As they can't switch between firmwares easily)
On the other hand, not using the Fantom driver was never very stable (especially when I/O was performed by different threads in parallel).


I agree -- we need a solution for the masses.

Some sort of solution that requires an admin password (and a restart?!) to move one library to the side and another into its place might be livable, but it wouldn't really be for the masses.

I wonder if this will become a problem for LEGO. Is there any way at all to:
1) find out if they plan to produce a 64-bit library?
2) load a 32-bit plugin from a 64-bit program?

I'm pretty sure "2" is a no, and "1" may be moot.


I had this idea, of writing a 32Bit C-program that would be started by leJOS as an external process. This program would communicate via STDIN/STDOUT with Java, and would implement some form of RPC to communicate with the fantom driver. That would work. Loading a 32Bit library into a 64Bit process is simply not possible.

I'd like to be talk to Lego about that. But I'm pretty sure by email would be discarded by first level support.
Second, all the Lego stuff is based on National Instruments software. I'm not even sure whether the National Instruments libraries exist in 64Bit. If they exist, Lego would probably have to pay for it (even though they don't need it themselves).


clintonb wrote:
skoehler wrote:To get libusb (and maybe libusbx) your might have to install macports.
In order to avoid trouble with the Driver, we might have to change the NXTs USB ID, so that the device won't be claimed by the Fantom driver anymore.
However, before we do that, we first have to finish winusb support for Windows, so that we can ship our own driver (that is based on winusb) for Windows XP and above.


I'm not fond of MacPorts. I'd see if I can compile it without it, but if that is what it takes, thats what it takes.

Do you mean to say that when we upload the firmware onto the NXT, we can change the USB IDs so that a different driver can talk to it? Interesting. On the minus side, would that not mean that no third-party tools could be used to access the device (such as using NXT-G to restore the stock firmware) -- or would it -- what would happen when the device is in firmware update mode -- surely we can't change those IDs.


The leJOS firmware is in full control of the USB hardware. We can change IDs, and pretty much everything else.
It is true, that thirdparty tools would not be able to talk to the NXT when it's running leJOS. If we keep the Lego protocol (LCP) it could be added to the open source ones. Going back to the original firmware would always be possible by using the NXTs reset button. However, when leJOS is running, NXT-G would not be able to talk to the NXT. (When I last tried, it didn't really work anyways.)

However, recent versions of nxjflash (not nxjflashg though) are actually able to flash the original Lego firmware.

clintonb wrote:
skoehler wrote:Basically, you could also simply write a C/C++ program to
a) iterate over the connected NXTs
b) connect to an NXT and maybe query it for its name

We can turn that into JNI code later.


I've done something like that in the past. I'll see if I can find the source, or recreate it -- the project didn't get very far.

How does this limited functionality help in interfacing 64-bit Java to the 32-bit fantom driver, supporting the functionality leJOS needs?


That C/C++ program would of course have to be a 64Bit program and thus cannot rely on the fantom driver ;-)
It would be a prototypic implementation of whatever method we chose for communicating with the NXT.

BTW: if we chose to change the USB IDs of the NXT etc. - then we could have the NXT appear as a normal serial device. Acessing a COM device should be rather easy - however, finding out which serial device is actually a Lego NXT might be quite a pain.

skoehler wrote:
clintonb wrote:Alternative and/or supplementally, I can make my computer available for remote access -- perhaps using Skype, perhaps something else. Many weekdays I could make time from say 5:30 to 6:30 am or 7 to 9 pm Mountain Standard Time (googling "Time in Edmonton" will tell you). If anyone would like to take me up on that for making leJOS work with the new java on the Mac, my contact info is here.


That is very kind of you. But I think I would need physical access to your computer for rebooting, unplugging an NXT, etc.
Also right now, I'm not really sure what to do.


I can be your hands in the remote location. I have debugged a little like this and its a pain, but it does help.[/quote]

OK, I'll keep that in mind. But first we have to decide which road we take.
Also, I have to talk to Andy. I'd like to know what he is thinking..

clintonb wrote:Oh, one more thing. Detecting disconnects is not an issue with the Fantom driver. My tests with leJOS 0.9.0 and 0.9.1 were on the same computer, minutes apart, with the same driver, and one worked while the other ... responds differently.


Your logic is flawless. Of course you're right. I will have a go at reproducing this on Windows and Linux on Monday.
skoehler
leJOS Team Member
 
Posts: 1128
Joined: Thu Oct 30, 2008 4:54 pm

Re: Figure out when NXT has disconnected

Postby clintonb » Sun Nov 04, 2012 1:50 am

Sounds good.

I'll wait until you've talked to Andy. I might play with some of this stuff to see what I can do, and if I try it out with Windows/Linux, I'll post my results here.
clintonb
Active User
 
Posts: 87
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Figure out when NXT has disconnected

Postby clintonb » Sun Nov 04, 2012 3:20 am

skoehler wrote:That C/C++ program would of course have to be a 64Bit program and thus cannot rely on the fantom driver ;-)
It would be a prototypic implementation of whatever method we chose for communicating with the NXT.


Oh, I missed that subtlety. My sample program used the fantom driver. I'm not quite sure where to begin, then.

Not saying I like the idea, but it seems to me that one could have a 32-bit C++ program, and interface to it from leJOS with sockets. (My inclination is to think that while it may work, it is probably not the right way forward).

Clinton
clintonb
Active User
 
Posts: 87
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Figure out when NXT has disconnected

Postby skoehler » Sun Nov 04, 2012 4:39 pm

Also note, that we don't support the fantom driver anymore, leJOS will not be able to communicate with NXTs that run the default firmware (the one by Lego). Remote-Controlling NXTs via leJOS seems to be a quite common usecase.
skoehler
leJOS Team Member
 
Posts: 1128
Joined: Thu Oct 30, 2008 4:54 pm

Re: Figure out when NXT has disconnected

Postby clintonb » Wed Nov 07, 2012 1:03 am

What do you think about this idea?

When the leJOS library is activated on the Mac, it checks for the presence of the Fantom driver.
- if Fantom is installed, leJOS uses it via socket communication to a 32-bit application that has loaded the driver.
- if it is not installed, leJOS uses something like libUSBX to communicate directly with the NXT.

Similarly, at install time, if Fantom is not installed, a kext is installed for use with leJOS. (Hopefully, if Fantom is installed later, it doesn't prove to be a problem).


-------

Have you been able to reproduce the issue of not detecting disconnects on the platform(s) you are testing on? (I still mean to try Linux and Windows and report back, but have yet to do so).
clintonb
Active User
 
Posts: 87
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Figure out when NXT has disconnected

Postby gloomyandy » Wed Nov 07, 2012 11:30 am

Hi,
We are currently discussing this via email. The problem with doing anything like this using libUSBX or kexts or whatever is who is going to get it working and maintain it. Very few of the leJOS developers have a Mac, and I'm not sure if those that do want to work at this low level. It took a very long time to get the fantom driver support working on the Mac and to be honest with you that is not an experience I'm keen to repeat...

For this reason we are looking into using some sort of standard USB interface (like a com port) rather then having to have any sort of none standard driver. Whatever happens I suspect it is going to take some time., so in the short term it may be best to try and get things back to the state they were in the earlier release. It would seem that some sort of change in the leJOS code has broken things...

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

Next

Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff