VB.net 编程问题,,TextBox2.Text = s '回显收到数据,s = SerialPort1.ReadExisting '接受串口数据 两个
PublicClassForm1PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventA...
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With SerialPort1
.PortName = "COM1" '选择串口1
.BaudRate = 9600 '波特率 9600bps
.Parity = IO.Ports.Parity.None '无校验
.DataBits = 8 '8位数据位
.StopBits = IO.Ports.StopBits.One '1位停止位
.ParityReplace = 0
End With
SerialPort1.Open() '打开串口
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.RtsEnable = True '启用请求发送
SerialPort1.DtrEnable = True '接受就绪
SerialPort1.Write(TextBox1.Text) '发送数据至串口
TextBox2.Text = s '回显收到数据
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
s = SerialPort1.ReadExisting '接受串口数据
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
SerialPort1.Close() '关闭串口
End Sub
End Class 展开
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With SerialPort1
.PortName = "COM1" '选择串口1
.BaudRate = 9600 '波特率 9600bps
.Parity = IO.Ports.Parity.None '无校验
.DataBits = 8 '8位数据位
.StopBits = IO.Ports.StopBits.One '1位停止位
.ParityReplace = 0
End With
SerialPort1.Open() '打开串口
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.RtsEnable = True '启用请求发送
SerialPort1.DtrEnable = True '接受就绪
SerialPort1.Write(TextBox1.Text) '发送数据至串口
TextBox2.Text = s '回显收到数据
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
s = SerialPort1.ReadExisting '接受串口数据
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
SerialPort1.Close() '关闭串口
End Sub
End Class 展开
1个回答
2012-06-09
展开全部
不会 是 参考 人家的 程序吧
变量 S 再哪里 定义?
把 这个 Private s As String 加 Public Class Form1 之后 试试
Ok了,我 调试过
变量 S 再哪里 定义?
把 这个 Private s As String 加 Public Class Form1 之后 试试
Ok了,我 调试过
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询