I'm using a PL200 pole display with the following settings * Char type: USA/Europe (default) * Command mode: EPSON (default) Baud * rate: 9600, n , 8, 1 (default?) * Passthru None (Default)
The display just goes off each time i run my code and i get the exception message like the "device does not recognize this command."
I guess that i'm not getting the commands right can any one please give sample code to write to the pole display?
The code...
try
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("COM1");
if (portIdentifier.isCurrentlyOwned())
{
System.out.println("Port in use!");
}
else {
System.out.println(portIdentifier.getName());
SerialPort serialPort = (SerialPort) portIdentifier.open("ListPortClass", 300);
int b = serialPort.getBaudRate();
System.out.println(Integer.toString(b));
serialPort.setSerialPortParams(300, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
OutputStream mOutputToPort = serialPort.getOutputStream();
InputStream mInputFromPort = serialPort.getInputStream();
String mValue = "AT\r";
System.out.println("beginning to Write . \r\n");
mOutputToPort.write(mValue.getBytes());
System.out.println("AT Command Written to Port. \r\n");
mOutputToPort.flush();
System.out.println("Waiting for Reply \r\n");
Thread.sleep(500);
byte mBytesIn [] = new byte[20];
mInputFromPort.read(mBytesIn);
mInputFromPort.read(mByte开发者_StackOverflow中文版sIn);
String value = new String(mBytesIn);
System.out.println("Response from Serial Device: "+value);
mOutputToPort.close();
mInputFromPort.close();
}
catch (Exception ex)
{
System.out.println("Exception : " + ex.getMessage());
}
Your baudrate may be incorrect. The device operates on either 9600 or 19200 Baud but you've set the port rate to 300 Baud.
I'd expect a line like this:
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
I took my wisdom from this resource - never used this device. As far as I understand, the commands are:
new byte[]{0x0C} // clear display
new byte[]{0x1f, 0x24, 0x01, 0x02}; // move cursor to column 1, row 2 (example)
精彩评论