Why would
public ListOpenPorts() {
portList = CommPortIdentifier.getPortIdentifiers();
}
return false when I query it thus
portList.hasMoreElements();
????
I clearly have a COM1 port available.
Thanks.
java questionWhy would
public ListOpenPorts() { portList = CommPortIdentifier.getPortIdentifiers(); } return false when I query it thus portList.hasMoreElements(); ???? I clearly have a COM1 port available. Thanks. Is it instantiated to the first port? If so, then wouldn't it be pointing to COM1 and not "have more ports"?
Just throwing ideas out. :-/ Hmmm. This is irritating.
portId = CommPortIdentifier.getPortIdentifier("COM1"); gives me a NoSuchPortException error. Clearly I have a COM1 port. Maybe I should reboot. Tomorrow. for fuck's sake
http://forum.java.sun.com/thread.jspa?threadID=501695 I need some kind of properties file somewhere. Fuck this. I'm over it. Damn it all. I hate Java. HATE IT. But Java does not hate yoooooooo...
Is that a constructor? Cause you seem to be missing a return type there.
constructor, yes.
I have it working now. You have to put javax.comm.properties in your java jdk lib folder, and win32comm.dll in the java jdk bin folder. And suddenly it works. For the life of me, I don't understand why I need a properties file for this to work. Since this mishap, I've been trying to get java serial communications to pass a byte to the PIC Basic program on the chip.
So far, no go. I can send, but I'm not receiving. Now I have to learn PIC Basic in detail to find out why. All these damn tangents just to get to the meat. I really want to be experimenting with the infrared sensors, so I should just put the Java away and bang out PIC Basic and come back to the Java to control my chip from the PC. But I just wanted to try a "leeetle bitty bit" to get my whistle whet, and here I am 4:30AM, with little more than my contraption lighting up and spinning wheels and scaring the cats. I really wanted it to be line following or avoiding objects by now. > For the life of me, I don't understand why
> I need a properties file for this to work. Because it's all OS dependent stuff. Hey, Sharky. If you have a BS2, you need "PBasic" or "Parallax Basic", not "PIC Basic" which is a product of ME Labs.
First, everything you send to the BS2 will be echo'ed back to you by the BS2 hardware, so you'll have to filter that. Second, when you open the port, the default is for the PC to pull DTR 'High', which WILL reset the BS2. Thus, open the port ONCE, don't open--close--open--close, because each open will reset the BS2 back to start. Next, you do realize that the BS2 will 'pend' in the 'SERIN' call, and wait for data, right? Also, that serial comm on the BS2 is NOT buffered, which means if the BS2 is NOT 'pended' in a SERIN call, then it won't get the data. Plus, it's fairly simple to write a program for the BS2 like:
SerPin CON 16 SerBaud CON 16348 ' Check the Parallax documentation SEROUT SerPin, SerBaud, ["Reset!", 13] ' Detects resets MAIN: SEROUT SerPin, SerBaud, ["Hello", 13] pause 200 ' Pause 200 mSec, so you don't get flooded GOTO MAIN Now, you can run this from the IDE, and use the 'debug' window to see the 'Hello' messages. Then, bring down the IDE (or close the 'debug' window) and try your Java program. Note only ONE program can 'own' the serial port at a time. D'oh. "SerBaud CON 16468" -- for 9600 8N1. I'm always messing that one up.
And on the BS2 side, to recieve a byte:
MyByte VAR BYTE SerPin 16 SerBaud 16468 SEROUT SerPin, SerBaud ["Reset!", 13] MAIN: SERIN SerPin, SerBaud, [MyByte] ' Pend waiting for byte SEROUT SerPin, SerBaud, [MyByte] ' Echo byte GOTO MAIN ' And go 'pend' again... the should have put the properties file in place during the install.
thanks, somebody. I'll have to try these later.
And yes, Java should have put those files in place during the install! Hey sharky, check out this thread:
http://www.crazyontap.com/topic.php?TopicId=10058&Posts=5 I know from experience that dealing with serial comms from a 3GL can cause problems (garbage collection, race conditions, etc). Unless you find some great docs on serial comms with Java, you may be better served writing servo control objects in C++ and exposing an interface you can consume from a Java app. I can't recall if you know C++, but it's never a bad thing to learn... I know enough C++ to get by.
The book I'm using is The Definitive Guide to Java Robotics and the author makes his code available on sourceforge. He has a whole chapter on serial communication, and he has a class that opens and closes at the right time...you just override his code and it works. My problem last night (4am) was I did something that hung up the com port so I had to reboot. But it still didn't work two ways, per his instruction. So I have to troubleshoot his code. Using PBasic (yes the proper term for my BS2 compiler) is something I have never done before so Somebody's code is a lot clearer to me than his and I'll try it again before the day is out. |
|
|
|
|