Ik gebruik volgdende code:
Visual Basic Code:
Public Class Form1
Private SartoriusPort As New SerialPort
Private combuffer As Byte()
Private Delegate Sub updateformdelegate()
Private updateformdelegate1 As updateformdelegate
Private Sub sartoriusport_datareceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
updateformdelegate1 = New updateformdelegate(AddressOf updatedisplay)
Dim n As Integer = SartoriusPort.BytesToRead
combuffer = New Byte(n - 1) {}
SartoriusPort.Read(combuffer, 0, n)
Me.Invoke(updateformdelegate1)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CommPortSetup()
AddHandler SartoriusPort.DataReceived, AddressOf sartoriusport_datareceived
End Sub
Private Sub updatedisplay()
Label2.Text = CStr(combuffer(0))
End Sub
Private Sub CommPortSetup()
With SartoriusPort
.PortName = "COM10"
.BaudRate = 1200
.DataBits = 7
.Parity = Parity.Odd
.StopBits = StopBits.One
Try
SartoriusPort.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End With
End Sub
End Class
Maar ik krijg nog geen resultaat in mijn label.
Ik ben wel zeker dat ik connectie heb met mijn weegschaal.
Weet iemand wat ik verkeerd doe?
Ik krijg volgende dingen:
A first chance exception of type 'System.unauthorizedaccesexcetion' occurred in system.dll
A first chance exception of type 'System.invalidoperationexception' occurred in system.dll
A first chance exception of type 'System.argumentexception' occurred in system.dll