Hello there...
For my diploma thesis I am developing a program that controls a measuring instrument via rs232. I am quite new in VB and programming but I am trying hard:)
I was quite successfull in writing on the rs232 port, reading i working, too.
My problem is the data_receved handle.
this code works:
Public Function Read()
sRead = SerialPort.ReadByte()
sRead = SerialPort.ReadExisting
LB_Kom.Items.Add("RX: " + sRead)
End Function
But, I have to initiate this function manually. Ths is not exactly what my program should do, it should run automaticlly:)
Thus I tried this:
Public Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived ' For i As Int32 = 0 To SerialPort1.BytesToRead ' Alle Bytes einzel lesen und anzeigen
Text = SerialPort1.ReadByte()
Text = SerialPort1.ReadExisting
MsgBox(Text)
Me.Invoke(datenlesen)
End Sub
Private Delegate Sub DSub()
Private datenlesen As New DSub(AddressOf Datenanzeige)
Private Sub Datenanzeige()
LB_Kom.Items.Add("RX: " + Text)
End Sub
It does not work, I do net get the message box. When i initiate the "read()" function manually, everything workds fine, I am able to read the incomming answer of teh instuement,
Does anybody now, why the DataReceived thing does not work properly
Thanks and greetings...
Carsten

Serial Port, Data Received does not work
mliesmons
@Carsten Kanstrup: I've already seen your page and the project. Great Work!
@other: Yes, "Typo" was the key word. I 'had myself on in the project.. There was the slight difference between serialport and serialport1.
Now the DataReceived Event works! I can receave the incoming data from the measuring instrument, and now I have got some other problems. We'll discuss them in other Threads..
Thanks a lot, folks!
Carsten
soulmate75
My guess is that you have forgotten "WithEvents in the SerialPort definition (Dim WithEvents SerialPort1 As New SerialPort). Without this it will not be able to activate SerialPort1_DataReceived.
In the knowledgebase on our homepage you may find a small sample program for serial port communication including source code and documentation. The program is able to do what you want, that is, to receive automatically. The URL is: http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm
Good luck with the diploma.
Innovatic, Carsten Kanstrup
Rossel