需要帮助在java中的杆显示器上显示消息

发布于 2024-10-10 04:06:44 字数 1682 浏览 0 评论 0原文

我使用的是具有以下设置的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-10-17 04:06:44

您的波特率可能不正确。该设备以 9600 或 19200 波特率运行,但您已将端口速率设置为 300 波特率。

我期待这样的一行:

serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, 
    SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

我从 this 中汲取智慧资源 - 从未使用过此设备。据我了解,命令是:

new byte[]{0x0C}  // clear display
new byte[]{0x1f, 0x24, 0x01, 0x02};  // move cursor to column 1, row 2 (example)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文