[英]Convert string to char textbox
I need to send the data to the serial port in Char I have tried 我需要将数据发送到我尝试过的Char中的串口
textbox1.Text[0]
Convert.Tochar(textbox1.Text);
so basically serialPort1.WriteLine(textBox1.Text)
; 所以基本上是serialPort1.WriteLine(textBox1.Text)
; must be sent in char 必须以char发送
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;
serialPort1.WriteLine(textBox1.Text);
textBox1.Text = "";
}
The SerialPort.WriteLine
method in the System.IO.Ports
namespace is declared as System.IO.Ports
命名空间中的SerialPort.WriteLine
方法声明为
public void WriteLine (string str);
So I'm not sure why you think you need to pass it a char
. 所以我不确定你为什么认为你需要传递一个char
。 Maybe it helps to set the encoding 也许它有助于设置编码
serialPort.Encoding = Encoding.ASCII;
尝试这样的事情:
serialPort1.Write(new [] { textBox1.Text == "1" ? '1' : '0' }, 0, 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.