473,796 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rs232 Thread issue

Lou
I get a thread exception in this class the second time the Callback
"SerialPort_Dat aReceived" is called. The first
time its fine but the subsequent time I get a thread message

This call is created in frmMain
Dim WithEvents SerialPort As New cRs232
'My Serial class code
Option Explicit On

Option Strict On

Imports System.IO.Ports

Public Class cRs232

Private WithEvents SerialPort As New SerialPort

Public Event Rs232DataReceiv ed(ByVal Rs232ReceivedDa ta As String)

Public Event Rs232DataSent(B yVal Rs232DataSent As String)

Private Sub SerialPort_Data Received(ByVal sender As Object, ByVal e As
System.IO.Ports .SerialDataRece ivedEventArgs) Handles SerialPort.Data Received

Dim Rs232DataReceiv ed As String = SerialPort.Read Line

'THREAD ERROR MESSAGE HERE THE SECOND TIME THIS GETS CALLED!

'RaiseEvent Rs232DataReceiv ed(Rs232DataRec eived)

End Sub

Public Sub OpenPort()

Try

SerialPort.Baud Rate = 9600

SerialPort.Port Name = "Com3"

' Open the serial port

SerialPort.Open ()

' Set the event handler for data reception

AddHandler SerialPort.Data Received, AddressOf SerialPort_Data Received

Catch ex As System.Exceptio n

MessageBox.Show (ex.Message)

End Try

End Sub

Public Sub ClosePort()

SerialPort.Clos e()

End Sub

Public Sub SendData(ByVal cmd As String)

cmd += vbCrLf

'Dim Bytes() As Byte = System.Text.Enc oding.GetEncodi ng(1252).GetByt es(cmd)

Dim Bytes() As Byte = System.Text.Enc oding.Default.G etBytes(cmd)

Try

' Write a line to the serial port

SerialPort.Writ e(Bytes, 0, (Bytes.Length - 1))

'txtData.Append Text(Now.ToShor tTimeString & "->Sent: " & cmd)

'RaiseEvent Rs232DataSent(c md)

Catch ex As System.Exceptio n

MessageBox.Show (ex.Message)

End Try

End Sub

End Class
Jun 2 '07 #1
0 1017

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7826
by: Dan | last post by:
I wnat to see in browser an status from an device connected on rs232 port The java class for read from serial port is: //Serial.java import java.io.*; import java.util.*; import java.lang.*; import javax.comm.*;
8
2063
by: Terry Olsen | last post by:
I'm trying to use the RS232 class that was in the Platform SDK (i think). Has anyone else used this with events successfully? Here's what i've got: ====================== Public WithEvents bbsPort As Rs232 = New Rs232 With bbsPort .BaudRate = baud .DataBit = dataBits .Parity = parity .Port = comPort
4
1268
by: Lou | last post by:
I am using the rs232 control and when I get the datareceived and try to assign it to a textbox I get some sort of thread message error -Lou
7
4083
by: Lou | last post by:
I have a class that uses the serial port class Private SerialPort as New SerialPort When I receive the asyncronous serial port response it appears that data is on a different thread than my UI. When I try to raise an event in my class my frmMain doesn't get the callback. i think this is a threading issue. Question is how do I get the serial port response from my vb class to my main form.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.