. NET Call window serial to read the electronic scale data

Source: Internet
Author: User

Private serialPort as SerialPort ' definition

Public Function Createserialport () as String
Dim strweights as String = ""
Dim strdata as String = ""
Dim Bsetpointnum as Double = 0.0

If SerialPort IsNot Nothing Then
If Serialport.isopen Then
Me.serialPort.Close ()
End If
Me.serialPort.Dispose ()
End If

Try
SerialPort = New SerialPort ("COM" + clxml.read ("login", "Bserialportnames", "" "), Integer.parse (Clxml.read (" Login "," Bbaudrate ",")), CType ([Enum]. Parse (GetType (Parity), Clxml.read ("Login", "bparity", ""), Parity), Integer.parse (Clxml.read ("Login", "Bdatabits", " ")), CType ([Enum]. Parse (GetType (stopbits), Clxml.read ("Login", "Bstopbits", "")), StopBits))
Serialport.writetimeout = 20000
Serialport.readtimeout = 20000
Serialport.readbuffersize = 20480
Serialport.writebuffersize = 20480
Serialport.open ()
Dim portname as String = "COM" + clxml.read ("Login", "Bserialportnames", "" ")
If Serialport.isopen Then
Dim readlength as Integer = 8
Dim offset as Integer = 0
Dim data as Byte () = New byte (readLength-1) {}
Do
Dim bytelenght as Integer = serialport.read (data, offset, readlength)
Offset + = Bytelenght
Readlength-= Bytelenght
Loop while Serialport.bytestoread > 0
Strdata = Encoding. [Default]. GetString (data)
Bsetpointnum = Clxml.read ("Login", "Bsetpoint", "" ")
SetPoint ()
If IsNumeric (strdata) = True Then
Strweights = IIf (Strdata/bsetpointnum < "0", Bsetpoint, Val (Strdata/bsetpointnum))
Application.doevents ()
Else
Strweights = Bsetpoint
End If

If strweights = "Then
Return Createserialport ()
End If

End If
Catch ex as Exception
C.msginfro (C.getresource ("MyResource", "Public_serialporterror"), "notices", True)
End Try
Return strweights
End Function

. NET Call window serial to read the electronic scale data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.