byte [] Data = new byte [1];
if (serialPort1.IsOpen)
{
if (textBox1.Text != "")
{
if (!radioButton1.Checked)
{
try
{
serialPort1.WriteLine(textBox1.Text);
}
else
{
int t = Convert.ToInt32(textBox1.Text);
string str=t.ToString();
int i = str.Length;
Data[0] = (byte )Convert.ToInt32(str.Substring(0,i),10);
serialPort1.Write(Data,0,1);
private void button3_Click(object sender, EventArgs e)
{
byte [] Data = new byte [1];
if (serialPort1.IsOpen)
{
if (textBox1.Text != "")
{
if (!radioButton1.Checked)
{
try
{
serialPort1.WriteLine(textBox1.Text);
}
catch (Exception err)
{
MessageBox.Show("串口数据写入错误", "错误");
}
}
else
{
int t = Convert.ToInt32(textBox1.Text);
string str=t.ToString();
int i = str.Length;
Data[0] = (byte )Convert.ToInt32(str.Substring(0,i),10);
serialPort1.Write(Data,0,1);
}
}
}
}
}
}
Data[0] = (byte )Convert.ToInt32(str.Substring(0,i),10);
serialPort1.Write(Data,0,1);
请问,在这里我只能输入一个字节的整数,最大值为255,我想在文本框中输入16位或32位的整数得怎么改啊?(因为serialPort1.Write中的Data限制为byte[ ]型数组)
一周热门 更多>