I (ab)use Windows to talk to motes, so what I sent should work. Getting a null pointer I would guess that BuildSource.makePacketSource() isn't working correctly, and that is probably due to an incorrect MOTECOM setting. Windows uses COMn port names in MOTECOM... and somewhat counter-intuitively /dev/ttyXX names in the setting for the programmer itself... So that might be the problem. If you have a debugger, try stepping through the make...() call and see what happens.
You can send raw bytes, but there is a lot of formatting that you need to do to make an acceptable message. If you are receiving stuff, you should have the right port settings and drivers installed. The Listen and ListenRaw demo programs in the Java tools work at the lowest usable level of the code to receive messages so if you can get port and MOTECOM setting to work with them you should be ready to go with sending. MS ashkan ekhtiari wrote: > I use the same thin , as I told before I tried a couple of ways since I > thought maybe it is not possible to communicate directly from windows to > mote. > > this code mentioned by you works pretty well on my Linux version of > application, but on Windows version it doesn't open > PrintStreamMessanger.err and exactly on the line : > > ps.open(PrintStreamMessenger.err); > I get the NullPointer Exception. > > However I tried just sending bytes directly into serial port, the fact > is that it doesn't send even a bit to mote, my mote is sensetive to > input array of bytes and responds according to the input, but it doesn't > happen on XP version of application meaning that sending to mote is not > possible or needs more details maybe. > > Note that I get the InputStream by the code : > > InputStream in = serialport.getInputStream(); > > and I get data coming from mote into this input stream , if I try > > OutputStream out = serialport.getOutputStream(); > > and then use out.write(byteaaray); > > it also doesn't work. > > Am i missing something ? I have no idea for this streng problem. > > Regards > > On Thu, Jul 15, 2010 at 7:11 PM, Michael Schippling <[email protected] > <mailto:[email protected]>> wrote: > > I use this to get the Source. It opens the right kind of > channel based on the setting of the MOTECOM envvar: > > // get the TOS connection > PacketSource ps = BuildSource.makePacketSource(); > if (ps == null) > { > System.err.println( > "Invalid packet source \ > (check your MOTECOM environment variable)"); > System.exit(2); > } > ps.open(PrintStreamMessenger.err); > > and then to write a message: > > byte[] data = // get message buffer // > ps.writePacket( data ); > > or read a message > > byte[] data = ps.readPacket(); > > > Where "data" is the raw message buffer and must be a byte[] array > of exactly the length specified in the message (plus the header > etal) with the header formatted correctly. The Packetizer.java > code is what does the real work of sending and receiving, and > it will deal with framing, escaping, and CRC's. You can look > for uses of these methods in the existing code for pointers > as to what and how. > > MS > > ashkan ekhtiari wrote: > > Hello, > I need to communicate with mote connected to USB in windows XP > within a java application, tinyos jar file is available in > javahome and also getenv.dll and tosscomm.dll are available in > bin folder. > I use netbeans and can see all net.tinyos library available. In > this java application two way was tried to communicate with my > mote, first with Outputstream that is instantiated by > serialport.getOutputstream() , by this outputstream it sends > nothing to mote when attempting out.write method by passing > byte[] or int. > whoever the second way also was tried by constructing > packetSource pks = BuilsSource.makePacketSource(). > and on the second line I use : pks.open(PrintStreamMessenger.err); > 1- pks= > net.tinyos.packet.BuildSource.makePacketSource("COM6 > <mailto:ser...@com6 <mailto:ser...@com6>>"); // here I tried > ser...@com6:57600 <mailto:ser...@com6 > <mailto:ser...@com6>:57600> or even nothing but the result was > the same > > 2- pks.open(PrintStreamMessenger.err); > on code line 2 it gives exception NullPointerException which I > do not understand. > So what can I do to actually communicate with my mote in > windows via serial port(USB)? > -- > Best Regards > Ashkan Ekhtiari > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Tinyos-help mailing list > [email protected] > <mailto:[email protected]> > > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > > > > > -- > Best Regards > Ashkan Ekhtiari _______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
