本文介绍了使用数据接收事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨论坛

我不知道如何使用我给出的代码中的数据接收事件..请你帮我。我不知道在哪里放数据接收事件。

I am not sure how to use data received events from this code I given.. Can you help me please.I dont know where to put the data received events.

Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Imports System.Data
Imports System.Text


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        SerialPort1.Close()
        SerialPort1.PortName = "com4" 'change com port to match your Arduino port
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default 'very important!


    End Sub


    Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click

        Dim SP As String
        Dim FB As Integer
        Dim A As Integer

        SP = TextBox1.Text
        FB = CInt(Label2.Text)
        A = SP - FB
        Label3.Text = A

        SerialPort1.Open()
        SerialPort1.Write(A)

    End Sub



    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
        Dim s As String
        Try
            s = SerialPort1.ReadExisting()
            Label2.Text = s
        Catch ex As Exception

        End Try
    End Sub






End Class




推荐答案

al


这篇关于使用数据接收事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 21:06