Wednesday, September 26, 2007
read/write to serial port

This is the code Francis Bitonti and Makiko nukaga used to interface with the serial port.
SERIN (example) PBASIC
' {$STAMP BS2}
' {$PBASIC 2.5}
check VAR Byte
proIn VAR Byte
Main:
DO
check = IN3
proIn = IN10
SERIN 16, 16780, [proIn]
IF proIn = 65 THEN
HIGH 14
ENDIF
PAUSE(250)
LOOP
END
SERIN (PROCESSING CODE)
import processing.serial.*;
Serial myPort; // The serial port
void setup() {
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 2400);
}
void draw() {
while (myPort.available() > 0) {
int inByte = myPort.read();
println(inByte);
}
}
SEROUT (example) PBASIC
' {$STAMP BS2}
' {$PBASIC 2.5}
check VAR Byte
Main:
DO
check = IN3
IF check = 0 THEN
SEROUT 16, 16780, [DEC 1]
PAUSE(250)
ENDIF
LOOP
END
SEROUT (PROCESSING CODE)
import processing.serial.*;
// The serial port:
Serial myPort;
// List all the available serial ports:
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 2400);
println(myPort.available());
while (myPort.available() == 0) {
delay(300);
myPort.write(65);
}
Labels: mf