private void TestHex(MouseEventArgs e)
{
int pu = e.Y;
string hex = Convert.ToString(e.Y, 16); //把整数转换成16进制表示的字符串 } private void button8_Click_1(object sender, EventArgs e)
{
this.timer1.Interval = 100;//事件间隔
this.timer1.Enabled = true;
Byte[] Txdata ={ 0xff, 0x05, 0x04,pu };
this.serialPort1.Write(Txdata, 0, 4);
}将pu转换成byte
或者
byte[] txdata2 = BitConverter.GetBytes(pu);
不知道你想做什么。
byte[] Txdata{0xff, 0x05, 0x04};
byte[] b=BitConverter.GetBytes(pu);
Txdata = Txdata.Union(b);
改为
byte[] Txdata = {0xff, 0x05, 0x04};