问题描述
大家好,
我在使用C#向串口发送字符串和十六进制命令时遇到了一些麻烦。我需要将一个字符串发送到显示器,然后使用十六进制命令保存该字符串。更改启动命令的十六进制命令是FE 40.虽然,我能够成功地
在显示器上打印字符串,但我不知道如何保存它。启动显示时,字符串应显示在启动屏幕上。在使用hex命令发送之前,我应该将字符串转换为十六进制吗?我是C#的新手,所以任何帮助都会受到赞赏。
这就是我到目前为止。
//写入屏幕
private void btnWrite_Click(object sender,EventArgs e)
{
string str = tbLine1.Text + tbLine2.Text + tbLine3.Text + tbLine4.Text;
byte [] splash_str = Encoding.ASCII.GetBytes(str);
byte [] change_screen = new byte [2] {0xFE,0x40};
尝试
{
sp.Write(splash_str,0,splash_str.Length);
//sp.Write(str);
sp.Write(change_screen,0,change_screen.Length);
}
catch(Exception E){MessageBox.Show(E.ToString()," Error"); }
}
Hi everyone,
I'm having some trouble sending a string and hex command to a serial port using C#. I need to send a string to a display and then save that string with a hex command. The hex command to change the start up command is FE 40. Although, I am able to successfully print the string on the display, I don't know how to save it. When starting the display that string should show up on the start-up screen. Should I convert the string to hex before sending it with the hex command? I'm new to C# so any help would be appreciated. This is what I have so far.
// write to screen private void btnWrite_Click(object sender, EventArgs e) { string str = tbLine1.Text + tbLine2.Text + tbLine3.Text + tbLine4.Text; byte[] splash_str = Encoding.ASCII.GetBytes(str); byte[] change_screen = new byte[2] { 0xFE, 0x40 }; try { sp.Write(splash_str, 0, splash_str.Length); //sp.Write(str); sp.Write(change_screen, 0, change_screen.Length); } catch (Exception E) { MessageBox.Show(E.ToString(), "Error"); } }
这篇关于将字符串和十六进制命令发送到串行端口。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!