如何从体重秤中获取数据到vb.net中的软件

问题描述

我尝试了如下所示的代码来访问串行端口,但是当我尝试关闭表单时,它挂起了,软件停止了响应。

    Imports System
    Imports System.ComponentModel
    Imports System.Threading
    Imports System.IO.Ports

    Public Class frmMain
        Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing of data

        Private Sub SerialPort1_DataReceived(ByVal sender As Object,ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            ReceivedText(SerialPort1.ReadLine())    'Automatically called every time a data is received at the serialPort
        End Sub

        Private Sub ReceivedText(ByVal [text] As String)
            'compares the ID of the creating Thread to the ID of the calling Thread
            If Me.Label1.Invokerequired Then
                Dim x As New SetTextCallback(AddressOf ReceivedText)
                Me.BeginInvoke(x,New Object() {(text)})
            Else
                Me.Label1.Text = ([text] / My.Settings.deci)
            End If
        End Sub

        Private Sub frmMain_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load
            SerialPort1.PortName = My.Settings.comport          'Set SerialPort1 to the selected COM port at startup
            SerialPort1.Baudrate = My.Settings.baud
            'Set Baud rate to the selected value on 

            'Other Serial Port Property
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.DataBits = 8
            'Open our serial port
            SerialPort1.open()
        End Sub

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)