Tax the wealthy. Problem solved.

java question

Why would

public ListOpenPorts() {
        portList = CommPortIdentifier.getPortIdentifiers();
    }


return false when I query it thus

portList.hasMoreElements(); 


????

I clearly have a COM1 port available.

Thanks.
Permalink Send private email sharkfish 
September 4th, 2006 2:00am
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. :-/
Permalink Send private email Philo 
September 4th, 2006 2:22am
Hmmm.  This is irritating.

portId = CommPortIdentifier.getPortIdentifier("COM1");

gives me a NoSuchPortException error.

Clearly I have a COM1 port.  Maybe I should reboot.

Tomorrow.
Permalink Send private email sharkfish 
September 4th, 2006 2:48am
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.
Permalink Send private email sharkfish 
September 4th, 2006 2:56am
But Java does not hate yoooooooo...
Permalink Send private email Java 
September 4th, 2006 2:58am
Is that a constructor? Cause you seem to be missing a return type there.
Permalink Lustiges Häschen 
September 4th, 2006 5:08am
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.
Permalink Send private email sharkfish 
September 4th, 2006 5:22am
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.
Permalink Send private email sharkfish 
September 4th, 2006 5:26am
It actually moves?
Permalink Lustiges Häschen 
September 4th, 2006 5:41am
> 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.
Permalink son of parnas 
September 4th, 2006 10:35am
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.
Permalink Somebody 
September 4th, 2006 10:41am
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.
Permalink Somebody 
September 4th, 2006 10:46am
D'oh.  "SerBaud CON 16468" -- for 9600 8N1.  I'm always messing that one up.
Permalink Somebody 
September 4th, 2006 10:50am
++parnesson.
Permalink Send private email just me 
September 4th, 2006 11:14am
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...
Permalink Somebody 
September 4th, 2006 11:20am
the should have put the properties file in place during the install.
Permalink sharkfish sympathizer 
September 4th, 2006 11:42am
thanks, somebody. I'll have to try these later.

And yes, Java should have put those files in place during the install!
Permalink Send private email sharkfish 
September 4th, 2006 2:49pm
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...
Permalink Send private email Philo 
September 4th, 2006 2:53pm
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.
Permalink Send private email sharkfish 
September 4th, 2006 2:58pm

This topic is archived. No further replies will be accepted.

Other topics: September, 2006 Other topics: September, 2006 Recent topics Recent topics