简体   繁体   English

将十六进制代码发送到串行端口

[英]to send hex codes to serial port

I am using posiflex customer display, and I am trying to clear the display. 我正在使用posiflex客户显示器,我正在尝试清除显示器。 I have gone through the user's manual, and I found PST command mode, which uses hex codes. 我已经阅读了用户手册,我找到了PST命令模式,它使用十六进制代码。 I don't know how to pass these hex codes to serial port to clear my display. 我不知道如何将这些十六进制代码传递给串口来清除我的显示器。 From the manual, I need to send the following hex numbers: 14 0E 从手册中,我需要发送以下十六进制数字: 14 0E

I tried the following code to send these bytes, but I don't know how to pass two bytes at the same time. 我尝试使用以下代码发送这些字节,但我不知道如何同时传递两个字节。

SerialPort sp = new SerialPort();

    sp.PortName = "COM6";
    sp.BaudRate = 9600;
    sp.Parity = Parity.None;
    sp.DataBits = 8;
    sp.StopBits = StopBits.One;
    sp.Open();
   byte[] bytestosend = new byte[1] { 0x0E };

    sp.Write(bytestosend, 0, 1);
    sp.Close();
    sp.Dispose();
    sp = null;

When i use this code, no operation is performed (display is not cleared). 当我使用此代码时,不执行任何操作(不清除显示)。

To send multiple bytes just use comma to separate the bytes. 要发送多个字节,只需使用逗号分隔字节。 You should have something like this: 你应该有这样的东西:

sp.PortName = "COM6";
sp.BaudRate = 9600;
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.Open();
byte[] bytestosend = { 0x14, 0x0E };

sp.Write(bytestosend, 0, bytestosend.Length);
sp.Close();
sp.Dispose();
sp = null;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM