473,836 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asynchronous Serial port

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.
5)in result, the read operation is executed(provid ed that the BytesToRead are
present n the stream)
i encountered a problem that despite of Setting the BytesToRead property,the
read operation is executed and reads 1 byte from the stream.
after the read operation is completed i generate another async read request
so the port is always in "Listening" mode.

am i doing something wrong?
can't i work asynchronically ?
do i have to lock the stream or the port or the buffer itself?

Thanks

--
Message posted via http://www.dotnetmonster.com
Nov 28 '05 #1
2 11975
shayke wrote:
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.
5)in result, the read operation is executed(provid ed that the BytesToRead are
present n the stream)
i encountered a problem that despite of Setting the BytesToRead property,the
read operation is executed and reads 1 byte from the stream.
after the read operation is completed i generate another async read request
so the port is always in "Listening" mode.

am i doing something wrong?
can't i work asynchronically ?
do i have to lock the stream or the port or the buffer itself?

Thanks

I encountered the same problem.at the first read operation the read operation
returns after reading only the first byte.i think it is a problem of timeout
settings.i am not sure.
anyone else knows???

--
Message posted via http://www.dotnetmonster.com
Nov 29 '05 #2


shayke via DotNetMonster.c om wrote:
am i doing something wrong?
can't i work asynchronically ?
do i have to lock the stream or the port or the buffer itself?


In general, all .NET read primitives can read less bytes than "requested" .

If bytes are not arriving fast the async read operation *should* return
a number of bytes less than BytesToRead.

If you need to wait until a certain number of bytes have arrived you
must copy those bytes into a buffer yourself and signal an event when
it's full.
--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 30 '05 #3

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

Similar topics

4
9096
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
13
4839
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have been told it is not possible to access the serial ports from asp.net. The application is used to control custom hardware. The hardware is connected to a PC through serial ports. Our customer wants to control the hardware from a remote...
4
11209
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the same machine. The mobile application would access the web service via a network connection. It...
2
1576
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...
4
17828
by: Frank | last post by:
Hello, how to get information about all serial ports in the PC? I use the following code, but i got only the data of the FIRST serial port. All other serial port information are not available with this code sample: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from WIN32_SerialPort");
5
7905
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...
13
6217
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I am sending a short message to a group of embedded boxes daisy chained via the serial port. When I send a 'global' message, all the connected units should reply with their Id and Ack in this format '0 Ack' To be certain that I didn't miss a...
8
4586
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
2095
by: Martijn | last post by:
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.Write() and SerialPort.WriteLine() write to the buffer, they do not return until all bytes have been actually transmitted (I tested this by sending 1K @
0
9810
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
9656
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
10819
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...
0
10240
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
9355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7772
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
5641
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5811
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3100
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.