NXT reading data from a .txt file on my computer using leJOS

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

Moderators: 99jonathan, roger, imaqine

NXT reading data from a .txt file on my computer using leJOS

Postby frederik » Sun Jan 20, 2008 9:29 pm

Hi,

Is it possible for the NXT, running a leJOS program, to read data from a text-file or database on my computer? For example: My name is in a name.txt file in "My Documents" and it is printed on the NXT-screen by a leJOS program PrintName.nxj. The NXT and the computer are always connected with USB.

If it is possible, how should I program this, or where can I find an example to make this work in my new project.

Thanx!
Frederik.
________
DODGE CARAVAN
Last edited by frederik on Sun Feb 13, 2011 11:14 pm, edited 1 time in total.
frederik
New User
 
Posts: 23
Joined: Fri Dec 28, 2007 8:42 am

Postby lawrie » Mon Jan 21, 2008 1:32 am

Base the PC program on the USBSend sample. Read the String from your PC file using FileInputStream. Write the data to the USB stream using writeChars on the DataOutputStream and then do writeChar('\n') to write a newline character.

Base the NXT program on USBReceive. Read the name from the DataInputStream from readLine.

I have not tried this, but it should work. If it doesn't work for you, let me know, and I will try it.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

difficult...

Postby frederik » Tue Jan 22, 2008 9:58 pm

Wow... This sounds quite difficult to me. I tried to compile the USBSend part with a java compiler (Xcode and javac) but it gave 7 errors and I am no advanced programmer at all. I feel this project is going to be very challenging for me and maybe you are willing to help me.

Now, I'm editing this reply. Ik found Lawrie's tutoriol about rcx.comm. This tutorial and the NXT/Samples/UsbSend and receive examples will be helpfull... So, I have to do my homework first before posting more questions on this forum.

But... Tips are always welcome! thanx.
________
ALASKA DISPENSARIES
Last edited by frederik on Sun Feb 13, 2011 11:14 pm, edited 1 time in total.
frederik
New User
 
Posts: 23
Joined: Fri Dec 28, 2007 8:42 am

Postby lawrie » Fri Jan 25, 2008 11:35 pm

If USBSend has compilation errors, you probably need to add %NXJ_HOME%/lib/pccomm.jar to your CLASSPATH - see the comments in USBSend.java.

I am currently writing a tutorial for leJOS NXJ, but it may take some time.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Postby frederik » Sun Jan 27, 2008 9:45 am

Hi Lawrie,

Thanks for your reply!
In OSX I added the pccomm.jar-file to the folder Library/Java/Extensions/
I think that's the same as adding it to the classpath (?).

Instead of 7 errors there are 2 errors left:

[color=blue][MacBook-van-Frederik:programming/06_USB_send_receive/USBSend] frederik% javac *.java
USBSend.java:9: unreported exception lejos.pc.comm.NXTCommException; must be caught or declared to be thrown
NXTInfo[] nxtInfo = nxtComm.search(null, NXTCommFactory.USB);
^
USBSend.java:16: unreported exception lejos.pc.comm.NXTCommException; must be caught or declared to be thrown
nxtComm.open(nxtInfo[0]);
^
2 errors[/color]

You refered to the comments in USBSend.java, But in my file there are no comments at all. Do we both have different versions of the file?

I'm looking forwards to the tutorial you're writing.
Frederik.
________
Deauville
Last edited by frederik on Sun Feb 13, 2011 11:15 pm, edited 1 time in total.
frederik
New User
 
Posts: 23
Joined: Fri Dec 28, 2007 8:42 am

Postby kirkpthompson » Sun Jan 27, 2008 3:54 pm

It appears you need to to try {} .... catch (NXTCommException e) around the method calls on lines 9 and 16 of USBSend.java.

The nxtComm.search and nxtComm.open now appear to throw NXTCommException and must be handled with a try ... catch (or a throws on the method signature)

eg:
Code: Select all
try {
   nxtComm.open(nxtInfo[0]);
} catch (NXTCommException e) {
   System.out.println("Exception in open");
}


-K
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Postby frederik » Sun Jan 27, 2008 8:36 pm

Thanks again! I added the try catch and I added "throws exception" and the USBSend.java program is compiling without errors and running fine now. I see a number of bytes in the LCD screen of the NXT. It's another small step...
________
Cannabis seeds
frederik
New User
 
Posts: 23
Joined: Fri Dec 28, 2007 8:42 am


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests

more stuff