串口通信?
VB2005 如何从串口读和写数据?
[解决办法]
If SerialPort1.IsOpen = False Then SerialPort1.Open()
SerialPort1.BaudRate = 9600
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.DataBits = 8
SerialPort1.Parity = IO.Ports.Parity.None
Dim s As String
s = "#07A " + Chr(13)
SerialPort1.Write(s)
System.Threading.Thread.Sleep(1000)
Dim R() As Byte
ReDim R(SerialPort1.BytesToRead)
SerialPort1.Read(R, 1, SerialPort1.BytesToRead)
Dim i As Integer
If R.Length = 0 Then Exit Sub
TextBox1.Text = " "
For i = 1 To R.Length - 1
TextBox1.Text = TextBox1.Text + Chr(R(i))
Next
[解决办法]
你注意一下,你所要的是按什么发,如果是和硬件勾通,楼上那位的代码要改
变为用byte队列发
byte[] b2 = System.Text.Encoding.Default.GetBytes(你想发的数据);
serialPort.Write(b2, 0, length);
[解决办法]
.......