473,978 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asynchronous serial i/o

Hi,

I am trying to perform asynchronous serial (RS232 port) I/O in C# in a
"proper" manner. I noticed there is an event that will tell me when there
is something on the port, but I can't find a similar construct for writing
to the port.

Although the documenation states that SerialPort.Writ e() and
SerialPort.Writ eLine() write to the buffer, they do not return until all
bytes have been actually transmitted (I tested this by sending 1K @
1200bps). I was hoping for some way to send something to the driver, and be
notified when it was transmitted on the port. Something like what would
happen by specifying FILE_FLAG_OVERL APPED to the native Win32 CreateFile()
call.

My options:

1) Create my own thread(s) to do the asynchronous reading and writing (seems
a bit expensive)
2) Use P/Invoke on CreateFile and whatever I need to write to it (not really
something I prefer)
3) I have missed something, and there is a "better way"

Any pointers would be greatly appreciated!

Thanks for the help,

--
Martijn
Jun 27 '08 #1
2 2098
Martijn wrote:
I am trying to perform asynchronous serial (RS232 port) I/O in C# in a
"proper" manner. I noticed there is an event that will tell me when there
is something on the port, but I can't find a similar construct for writing
to the port.
Tried SerialPort.Base Stream.BeginRea d/Write yet?

--
J.
http://symbolsprose.blogspot.com
Jun 27 '08 #2
Jeroen Mostert wrote:
Martijn wrote:
>I am trying to perform asynchronous serial (RS232 port) I/O in C# in
a "proper" manner. I noticed there is an event that will tell me
when there is something on the port, but I can't find a similar
construct for writing to the port.
Tried SerialPort.Base Stream.BeginRea d/Write yet?
Hi Jeroen,

Thanks for pointing this out, exactly what I was looking for. I knew
SerialPort used some kind of stream, and when browsing the documentation I
overlooked that property and it being so obvious to get at :S

Thanks a million,

--
Martijn
http://www.sereneconcepts.nl
http://blogger.xs4all.nl/mihaak/
Jun 27 '08 #3

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

Similar topics

1
1564
by: Julian Hershel | last post by:
Reading about asynchronous programming (ms-help://MS.NETFrameworkSDK/cpguidenf/html/cpconasynchronousdesignpatterno verview.htm) I could not clarify some doubts. Hope you can help me. 1) Are asynchronous programming and multithreaded programming two different pictures? As I read the help topic above it is not clear to me if the design pattern opens a new thread or not to run the methods asynchronously. 2) One unique thread can run...
2
1589
by: TrtnJohn | last post by:
I have a multi-threaded class that I am creating that needs needs to raise events when certain asynchronous events occur. I would always like the events to be raised to the primary UI thread of any application that is using my component. I can't just call raiseevent from the thread that catches the asynchronous data. (In this case from a serial port). This is because I have a separate thread reading from the serial device. How can I...
2
12001
by: shayke via DotNetMonster.com | last post by:
Hello, I am trying to write asynchronous serial port. meaning, read and write operations are made via async cllbacks. so far so good. I open my port in continues state: 1)Set the BytesToRead property of the serial port. 2)open the port 3)generate read request 4)meanwhile generate write request.
1
2886
by: dba123 | last post by:
I need to perform Asynchronous Inserts using DAAB. So far I have a method which does an insert but how can I do this Asyncronously so that it does not affect the load on our public production website? This question is wide open but make sure you give me some ideas in context with DAAB syntax. Some thoughts are threading, ATLAS, etc. but I have no clue how to even approach an Asynchronous Insert or any techniques at this point. Also, I...
5
7912
by: Mo | last post by:
Hi, I have an application where I read a serial port data from a barcode and set the labels on a form. I also have a textbox and button where you can enter the data and here is the problem. if I use the textbox and submit using thebutton everything works fine. If I use the SerialDataReceivedEventHandler method of the serial port, the application crahes. It seens like that when the serial port triggers and I call the same routines it is...
0
1767
by: Bishoy George | last post by:
Hi, I have a asp.net 2.0 web application. I want to implement the asynchronous model through http handler in web.config ------------------------------------------------------------------------------------------------------------------------- My web.config file: ---------------------
5
11128
by: Mo | last post by:
I am trying to set a text box value when data is received from the com port (barcode reader). I am getting the following error when I try to set the text box TXNumber after data is received Cross-thread operation not valid: Control 'TXNumber' accessed from a thread other than the thread it was created on. Any ideas how to work around this problem? Thanks
8
4593
by: panko | last post by:
Hello, I can't manage with asynchronous socket communication. :( I wrote a class CSocket.cs. This class is taking care of sending strings to LED display. This display is actually communicating via serial port and serial/ethernet converter (MOXA NE-4100T) with TCP server. So communication is in that way: MyApplication(TCP client)-----------------(TCPServer)MOXA(serial)---(serial)LED Display
2
3447
by: Nicolas Le Gland | last post by:
Hello everyone here. This is my first post in this newsgroup, I hope I won't be to much off-topic. Feel free to redirect me to any better group. I am getting strange timing issues when failing to asynchronously connect sockets on closed or filtered ports, but I'm quite unsure if this is a PHP issue or my misunderstanding, as it seems that socket streams only wrap around <sys/socket.h>.
0
10358
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
11425
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11593
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,...
1
8465
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7620
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
6562
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5162
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4742
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3773
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.