I used javax.comm (win32com.dll) to connect to find the comm ports, and
serial forwarder to make the connections. Below is an method that will
locate each available serial COM port in java. After knowing which COM
ports exist, it's possible to use that information to make serial forwarder
connect to each port, traverse through various baud rate/mote types, and
find the mote connected to the computer.
import java.util.Comparitor;
import java.util.Enumeration;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.comm.CommPortIdentifier;
/**
* @return a Set of the available COM ports
*/
private Set getComPorts() {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
Set listports = new TreeSet(
// The following anonymous Comparitor class ensures the
// CommPortIdentifier String names begin with "COM"
// and are sorted by their integer com port id value rather
// than lexigraphically, e.g. COM2 < COM10
new Comparator() {
public final int compare(Object p1, Object p2) {
Patter p = Pattern.compile("^(.*)(\\d+)$");
Matcher m1 = p.matcher((String) p1);
Matcher m2 = p.matcher((String) p2);
if(m1.matches() && m2.matches()) {
if(m1.group(1).equals(m2.group(1))) {
p1 = new Integer(Integer.parseInt(m1.group(2)));
p2 = new Integer(Integer.parseInt(m2.group(2)));
} else {
p1 = new String(m1.group(1));
p2 = new String(m2.group(1));
}
}
return ((Comparable) p1).compareTo(p2);
}
});
while(ports.hasMoreElements()) {
CommPortIdentifier current = (CommPortIdentifier) ports.nextElement();
if(current.getPortType() == CommPortIdentifier.PORT_SERIAL) {
println("Skipping " + current.getName() + ": currently in use");
} else {
listports.add(current.getName());
}
}
if(listports.size() == 0) {
// win32comm.dll may not be in the correct location if this error
happens
System.err.println("No COM ports found.");
}
return listports;
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Gelu
Contiu
Sent: Friday, March 31, 2006 4:59 AM
To: tinyos-help
Subject: RE: [Tinyos-help] Java and info about the connected motes
Hi,
Thank you for the message David . It is exactly what
I was asking for, too bad you can't share the
application.
One question though: The Java API for the USB
connections is not outstanding, I use win2000 + cygwin
as OS. I tried the jsr-80 API and I get a lot of
erros. What API did you use, and what was the OS ?
Thanks,
Gelu
--- David Moss <[EMAIL PROTECTED]> wrote:
> I have an autodetect application that does this, but
> I'm not able to share
> it immediately. I may be able to post this in the
> future, though, if
> there's interest.
>
> In the meantime, I can describe how it works so you
> can try to implement it
> yourself if you want.
>
> This system requires a component to be installed on
> the mote and it works by
> the computer polling the mote. On the application
> on the mote, wire up the
> AutoDetect component to Main.StdControl - that's all
> that's required. This
> autodetect component that sits on the mote detects a
> certain AM type message
> from the UART. When it receives the message, it
> responds with a packet
> describing its mote type, application id, etc. The
> mote type is setup
> automatically through the platforms directory - each
> different platform
> implements a PlatformType module that responds with
> a different number,
> corresponding to the type of mote.
>
> On the computer end, the Java application first
> finds all available COM
> ports on the computer. It traverses through the COM
> ports one by one,
> sending a message to each. There could be a problem
> here if there really is
> a piece of hardware on the other end of that com
> ports that does something
> incorrect with the incoming data, but this does not
> address that issue. For
> each COM port, the Java application sends several
> messages, adjusting the
> baud rate and mote type for each one. It waits for
> about a second on for
> each message it sends for a response. When it hears
> a response, the
> response comes from the mote in the form of that
> packet described above. At
> that point, your computer knows the COM port to use,
> the mote type, the baud
> rate, and the application ID (if defined). To speed
> up the autodetection
> process on the next run (because 1 second per
> possible mote type, per com
> port takes awhile), the Java application records the
> valid information in a
> file. The next time it tries to autodetect the
> mote, it traverses and
> attempts the latest connection settings on file
> first before trying the
> manual detection process.
>
> The serial forwarder was also modified for this
> application so it doesn't
> display errors, and also it remains open once the
> valid connection is found.
>
> I have successfully tested this with mica2,
> mica2dot, micaz, and telosb
> motes connected to various COM ports on the
> computer.
>
> Now that I described how it works, is this the type
> of functionality you're
> looking for?
>
> David
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> On Behalf Of Gelu
> Contiu
> Sent: Thursday, March 30, 2006 3:29 AM
> To: tinyos-help
> Subject: [Tinyos-help] Java and info about the
> connected motes
>
>
> Hi all,
>
> Does anyone know how to detect the connected motes
> to the pc (through usb) by using JAVA ? If detected,
> I
> need to know the COM and the type ( tmote, mica...
> ).
> Basicly, I need the same info that "motelist"
> provides, but using java to retrieve it.
>
> Thanks,
> Gelu
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
>
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help