inzomniac 0 Newbie Poster

Hi.

I've been struggling with this for about a 3 days now, maybe someone could help. It isn't as specific as it seems. Please read on, i'm losing my mind over this :(.

Here's the thing:

The Parallax BasicSTAMP1 USB Board was never meant to be used as a front-end to a PC program. There isn't a built-in operation for writing out to its programming port (such as SEROUT in BS2), but this guy came with the idea of using the Debug stream so you could read from it freely with only some parsing to do. It's actually quite nice, and the Visual Basic examples that Parallax provide work very well. You can actually read the temperature of the enviroment (with a little extra hardware of course) or simply monitor the enviroment variables. Blah blah blah.

The thing is, according to the code provided, the VB programs use MSComm1 (??? i've never used VB in my life...) and actually handle the USB port (now recognized as COM6!) as an serial one; not only that, the VB source shows how to configure it (like a SERIAL ONE!):

.DTREnable = True
.RTSEnable = False
.Settings = "4800,n,8,1"
.RThreshold = 1
.PortOpen = True

So it seems like you just have to read from a Port, and this is the part where java kicks in (i'm using javax.comm). When you use Sun's typical SimpleRead.java, the CommPortIdentifier also recognizes COM6 as a port. In fact, you actually are able to read from the port, the problem is the things you read.

public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}

That last one System.out.print, prints a lot of gibberish, a lot of blank squares and weird symbols. And there hasn't been a way of working around that problem, even if my BS1USB board is only sending a "1" every minute, i'm not able of capturing that stupid little number. So, although it seems like a little too specific problem, my real question is...if the port can be treated as serial by VB's MSComm, is there any problem doing the same in java? Aren't I just reading the bytes that are being written to the port? WTF is the problem!?

Thanks in advance.