I have a class that creates an instance of the seril Port.
Every thing works fine except whenever I receive data I cannot display the
recieved data. I get no errors but the recived data seems to just go no
where.
I can see the recived data in my serial receive function but when I either
raise an event
with it or try to display it in a text box nothing happens. I do use
beginInvoke on the text box.
If I trace the code through it all appears as if should work but the receive
data doesn't get displayed
and the callback never gets executed. Been wrestling with this one for days
now. It's very Wierd!
I have socket stuff in the same class and it's recieve callbacks work just
fine and displays just fine.
Public Function SendData(ByVal sData As String) As Boolean
Try
If SerialPort.IsOpen = False Then OpenSerialPort(mComPort)
' Write a line to the serial port
SerialPort.Write(Bytes, 0, (Bytes.Length - 1))
SendOutForDisplay(sData, True, mName)
RaiseEvent Rs232DataSent(sData)
Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
End Function
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As
SerialDataReceivedEventArgs)
Dim serial As SerialPort
Dim BytesAvailable As Integer
serial = CType(sender, SerialPort)
BytesAvailable = serial.BytesToRead
If BytesAvailable < 1 Then
Debug.Print("Serial Port read zero bytes...")
Exit Sub
End If
Dim bytes(256) As [Byte]
Dim retval As Integer = SerialPort.Read(bytes, 0, BytesAvailable)
Dim received As String = Encoding.Default.GetString(bytes)
RaiseEvent Rs232DataReceived(received)
SendOutForDisplay(received, False, mName)
End Sub
Private Sub SendOutForDisplay(ByVal sData As String, ByVal bSendOut As
Boolean, ByVal DeviceName As String)
frmMain.colDisplayData.Add(sData)
If frmMain.txtData.InvokeRequired Then
MessageBox.Show("Invoke required")
End If
frmMain.DisplayData(sData, bSendOut, DeviceName)
End Sub
Private Sub Device_Rs232DataReceived(ByVal sData As String) Handles
Device.Rs232DataReceived
If txtData.InvokeRequired Then
txtData.BeginInvoke(New txtDataControlDelegate(AddressOf DisplayData), New
Object() {sData, False, Device.Name})
Else
DisplayData(sData, False, Device.Name)
End If
End Sub
Public Sub DisplayData(ByVal Buffer As String, ByVal bSent As Boolean, ByVal
DeviceName As String)
Dim Whichway As String
If bSent = True Then
Whichway = "Sent: "
Else
Whichway = "Received: "
End If
Buffer = Buffer.Replace(vbCr, "")
Buffer = Buffer.Replace(vbLf, "")
If Len(txtData.Text) 32000 Then txtData.Clear()
txtData.AppendText(vbCrLf & Now.ToLongTimeString & "->" & Whichway & "[" &
DeviceName & "]" & Buffer)
End Sub 2 6132
Lou,
It may be possible that the bytestream contains zero value bytes, which are
not displayable in a string. You may want to check for zero bytes in the
byte stream and not try to display those.
I'll also take a look through some old serial port code I have (which works)
to check it against yours.
Hope this helps,
Steve
"Lou" <lo********@comcast.netwrote in message
news:e7**************@TK2MSFTNGP02.phx.gbl...
>I have a class that creates an instance of the seril Port.
Every thing works fine except whenever I receive data I cannot display the
recieved data. I get no errors but the recived data seems to just go no
where.
I can see the recived data in my serial receive function but when I either
raise an event
with it or try to display it in a text box nothing happens. I do use
beginInvoke on the text box.
If I trace the code through it all appears as if should work but the
receive data doesn't get displayed
and the callback never gets executed. Been wrestling with this one for
days now. It's very Wierd!
I have socket stuff in the same class and it's recieve callbacks work just
fine and displays just fine.
Public Function SendData(ByVal sData As String) As Boolean
Try
If SerialPort.IsOpen = False Then OpenSerialPort(mComPort)
' Write a line to the serial port
SerialPort.Write(Bytes, 0, (Bytes.Length - 1))
SendOutForDisplay(sData, True, mName)
RaiseEvent Rs232DataSent(sData)
Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
End Function
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As
SerialDataReceivedEventArgs)
Dim serial As SerialPort
Dim BytesAvailable As Integer
serial = CType(sender, SerialPort)
BytesAvailable = serial.BytesToRead
If BytesAvailable < 1 Then
Debug.Print("Serial Port read zero bytes...")
Exit Sub
End If
Dim bytes(256) As [Byte]
Dim retval As Integer = SerialPort.Read(bytes, 0, BytesAvailable)
Dim received As String = Encoding.Default.GetString(bytes)
RaiseEvent Rs232DataReceived(received)
SendOutForDisplay(received, False, mName)
End Sub
Private Sub SendOutForDisplay(ByVal sData As String, ByVal bSendOut As
Boolean, ByVal DeviceName As String)
frmMain.colDisplayData.Add(sData)
If frmMain.txtData.InvokeRequired Then
MessageBox.Show("Invoke required")
End If
frmMain.DisplayData(sData, bSendOut, DeviceName)
End Sub
Private Sub Device_Rs232DataReceived(ByVal sData As String) Handles
Device.Rs232DataReceived
If txtData.InvokeRequired Then
txtData.BeginInvoke(New txtDataControlDelegate(AddressOf DisplayData), New
Object() {sData, False, Device.Name})
Else
DisplayData(sData, False, Device.Name)
End If
End Sub
Public Sub DisplayData(ByVal Buffer As String, ByVal bSent As Boolean,
ByVal DeviceName As String)
Dim Whichway As String
If bSent = True Then
Whichway = "Sent: "
Else
Whichway = "Received: "
End If
Buffer = Buffer.Replace(vbCr, "")
Buffer = Buffer.Replace(vbLf, "")
If Len(txtData.Text) 32000 Then txtData.Clear()
txtData.AppendText(vbCrLf & Now.ToLongTimeString & "->" & Whichway & "[" &
DeviceName & "]" & Buffer)
End Sub
Thanks, I have been at this for days!
It looks like it should just work!
"PlatinumBay" <st*******@community.nospamwrote in message
news:O3****************@TK2MSFTNGP04.phx.gbl...
Lou,
It may be possible that the bytestream contains zero value bytes, which
are not displayable in a string. You may want to check for zero bytes in
the byte stream and not try to display those.
I'll also take a look through some old serial port code I have (which
works) to check it against yours.
Hope this helps,
Steve
"Lou" <lo********@comcast.netwrote in message
news:e7**************@TK2MSFTNGP02.phx.gbl...
>>I have a class that creates an instance of the seril Port. Every thing works fine except whenever I receive data I cannot display the recieved data. I get no errors but the recived data seems to just go no where. I can see the recived data in my serial receive function but when I either raise an event with it or try to display it in a text box nothing happens. I do use beginInvoke on the text box. If I trace the code through it all appears as if should work but the receive data doesn't get displayed and the callback never gets executed. Been wrestling with this one for days now. It's very Wierd! I have socket stuff in the same class and it's recieve callbacks work just fine and displays just fine.
Public Function SendData(ByVal sData As String) As Boolean
Try
If SerialPort.IsOpen = False Then OpenSerialPort(mComPort)
' Write a line to the serial port
SerialPort.Write(Bytes, 0, (Bytes.Length - 1))
SendOutForDisplay(sData, True, mName)
RaiseEvent Rs232DataSent(sData) Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
End Function
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
Dim serial As SerialPort
Dim BytesAvailable As Integer
serial = CType(sender, SerialPort)
BytesAvailable = serial.BytesToRead
If BytesAvailable < 1 Then
Debug.Print("Serial Port read zero bytes...")
Exit Sub
End If
Dim bytes(256) As [Byte]
Dim retval As Integer = SerialPort.Read(bytes, 0, BytesAvailable)
Dim received As String = Encoding.Default.GetString(bytes)
RaiseEvent Rs232DataReceived(received)
SendOutForDisplay(received, False, mName)
End Sub Private Sub SendOutForDisplay(ByVal sData As String, ByVal bSendOut As Boolean, ByVal DeviceName As String)
frmMain.colDisplayData.Add(sData)
If frmMain.txtData.InvokeRequired Then
MessageBox.Show("Invoke required")
End If
frmMain.DisplayData(sData, bSendOut, DeviceName)
End Sub Private Sub Device_Rs232DataReceived(ByVal sData As String) Handles Device.Rs232DataReceived
If txtData.InvokeRequired Then
txtData.BeginInvoke(New txtDataControlDelegate(AddressOf DisplayData), New Object() {sData, False, Device.Name})
Else
DisplayData(sData, False, Device.Name)
End If
End Sub Public Sub DisplayData(ByVal Buffer As String, ByVal bSent As Boolean, ByVal DeviceName As String)
Dim Whichway As String
If bSent = True Then
Whichway = "Sent: "
Else
Whichway = "Received: "
End If
Buffer = Buffer.Replace(vbCr, "")
Buffer = Buffer.Replace(vbLf, "")
If Len(txtData.Text) 32000 Then txtData.Clear()
txtData.AppendText(vbCrLf & Now.ToLongTimeString & "->" & Whichway & "[" & DeviceName & "]" & Buffer)
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Polerio Babao Jr.II |
last post by:
file fbus3.py
resource shared by Chris Liechti <cliechti@gmx.net>
during the
conversation last september 2002. I made it available so that other
user would benefit from it. I've used with...
|
by: Haluk Gokmen |
last post by:
I had an inquiry about the use of MSComm OCX in a C# application awhile
ago and I really appreciated Nicholas Paldino's help, which is listed
below...
My code worked well in VS2003. I am now...
|
by: Mike |
last post by:
Sorry, don't know if this is the correct board for my question. I'm a novice so I guess I have a valid excuse
My question : I'm using Visual C++ and I need to collect data from a serial port. ...
|
by: Michael Chong |
last post by:
I wrote a program that communicate with SerialComm. In every 300
milliseconds, my program continuously send & receive data via the serial
port once the program starts.
My program is once in a...
|
by: ken |
last post by:
Hello everyone,
I'm new to visual VB and I am trying to setup communications using the
Function ReceiveSerialData() As String example found in the help
section of Microsoft Visual Basic 2005...
|
by: chapeau_melon |
last post by:
Hello,
I'm basicly not a programmer...
I found some C++ codes on the net that almost satisfy me needs, wich
is to communicate with an other device that sends data to me, wich I
have to receive...
|
by: Tony K |
last post by:
I have a slight problem. When attempting to receive data via my serial port
I sometimes do not get the complete data. For example, I have a scanner
that reads barcodes. When reading barcode...
|
by: joaquimfpinto |
last post by:
Dear All,
I made an app in c# that uses several serial ports.
For the serial ports I use a pnp Sunix board, some with 8 serial ports
other with 4 or even 2 serial ports.
Whenever I use the...
|
by: mmrasheed |
last post by:
Hi,
I am newbie in python. I am working on Telit GM862 GPS/GPRS module
which has python interpreter built in. But it seems this problem is
pretty much related to general python structure.
I...
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |