需要帮助在java中的杆显示器上显示消息
我使用的是具有以下设置的 PL200 杆式显示器 * 字符类型:美国/欧洲(默认) * 命令模式:EPSON(默认)波特率 * 速率:9600, n , 8, 1 (默认?) * Passthru None(默认)
每次运行代码时显示屏都会关闭,并且收到诸如“设备无法识别此命令”之类的异常消息。
我想我没有得到正确的命令,任何人都可以提供示例代码来写入杆显示器吗?
代码...
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(mBytesIn);
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());
}
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(mBytesIn);
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());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的波特率可能不正确。该设备以 9600 或 19200 波特率运行,但您已将端口速率设置为 300 波特率。
我期待这样的一行:
我从 this 中汲取智慧资源 - 从未使用过此设备。据我了解,命令是:
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:
I took my wisdom from this resource - never used this device. As far as I understand, the commands are: