Java Reference
In-Depth Information
" Serial to Javelin " , 20000);
}
catch (PortInUseException pie) {
println ("Error: Port in use");
fCurrentPort -- = null;
fSelectedPortID -- = null;
return;
}
// Set up the serial port
try {
fCurrentPort -- .setSerialPortParams (
BAUD - RATE,
SerialPort.DATABITS - 8,
SerialPort.STOPBITS - 1,
SerialPort.PARITY - NONE
);
}
catch (UnsupportedCommOperationException uce) {
// This error shouldn ' t happen
}
try {
getStreams ();
}
catch (IOException ioe) {
println ("Error: Cannot open streams to port");
fCurrentPortLabel.setText ("No Port Open");
fCurrentPort -- .close ();
return;
}
fCurrentPortLabel.setText (port - name);
fGetJavelinData.setStreams (fPortInStream,
fPortOutStream);
fGoButton.setEnabled (true);
}
}
} // actionPerformed
The code first looks for a match to the port name. It then attempts to open the
port. If it succeeds it sets the serial port parameters to a baud rate of 9600, eight
data bits, one stop bit, and no parity. The serial line device must, of course, use
the same settings (we show how to program the Javelin Stamp evaluation card in
Chapter 24).
 
Search WWH ::




Custom Search