求助各位大牛如何用VB2015写串口调试助手,自己写了一个,接受到的数据完全不一样,实在是没有头绪,查了好多资料还是不会,希望各位能给我一些帮助,谢谢
Option Strict Off
Imports System.IO.Ports
Public Class Form1
Dim fx() As Byte
Dim rc() As Byte
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SerialPort1.BaudRate = 115200
SerialPort1.PortName = "COM7"
SerialPort1.DataBits = 8
SerialPort1.StopBits = StopBits.One
SerialPort1.Parity = Parity.None
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Button1.Text = "打开串口“ Then
SerialPort1.Open()
Button1.Text = “关闭串口“
Button2.Enabled = True
Timer1.Enabled = True
Else
If SerialPort1.IsOpen Then SerialPort1.Close()
Button1.Text = "打开串口“
Timer1.Enabled = False
Button2.Enabled = False
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim strrc As String
Dim i As Integer
Dim n As Integer
n = SerialPort1.BytesToRead
If n > 0 Then
ReDim rc(n)
strrc = ""
For i = 1 To n
rc(i) = SerialPort1.ReadByte
strrc = Hex(rc(i)) & ""
Next
TextBox2.Text = strrc
End If
End Sub
这是我写的部分源码,不知道哪的问题?希望各位解答一下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
那应该怎么写呢?这个就是参照网上的。
一周热门 更多>