基本信息
源码名称:vb 读取和发送串口数据
源码大小:0.87M
文件格式:.rar
开发语言:ASP
更新时间:2020-08-17
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
:读取和发送串口数据

请在窗体上添加SerialPort控件

设置串口参数,

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SerialPort1.Encoding = System.Text.Encoding.UTF8
        SerialPort1.BaudRate = 9600
    End Sub

发送数据

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            SerialPort1.WriteLine(TextBox1.Text)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

读取数据

  Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        If SerialPort1.BytesToRead > 0 Then
            TextBox2.Text = SerialPort1.ReadExisting.ToString
        Else
            TextBox2.Text = "(没有多余数据)"
        End If

    End Sub