问题描述
- VB上位机问题 给定的端口名称未以 COM/com 开头或未解析为有效的串行端口
-
调试舵机用的上位机
临时抱佛脚 求大神指点
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "串口上位机(舵机调试用):"
Label1.Text = "串口选择"
Label2.Text = "波特率"
Button1.Text = "打开串口"
Button2.Text = "关闭串口"End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.Text = "COM4" Then SerialPort1.PortName = 4 ElseIf ComboBox1.Text = "COM9" Then SerialPort1.PortName = 9 ElseIf ComboBox1.Text = "COM10" Then SerialPort1.PortName = 10 End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) SerialPort1.Close() '关闭串口 End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged If ComboBox2.Text = "9600" Then SerialPort1.BaudRate = 9600 SerialPort1.DataBits = 8 SerialPort1.StopBits = 1 SerialPort1.RtsEnable = True ElseIf ComboBox2.Text = "19200" Then SerialPort1.BaudRate = 19200 SerialPort1.DataBits = 8 SerialPort1.StopBits = 1 SerialPort1.RtsEnable = True ElseIf ComboBox2.Text = "115200" Then SerialPort1.BaudRate = 115200 SerialPort1.DataBits = 8 SerialPort1.StopBits = 1 SerialPort1.RtsEnable = True End If End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort1.Open() '打开串口 End Sub
End Class
解决方案
看看你的计算机是否有com4 com9 com10
时间: 2024-09-21 00:03:51