473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

simple question about event

Hi
I have an event that receives data from RS port

rs.DataReceived += new SerialDataReceivedEventHandler(rs_DataReceived);

I need to block raising an event when the previous one has not lelft yet.

RS port is receiving very fast the portions of data. When first data
receives, user is asked to do something with this data. Then each another
raise of this event is dooing the same what user did with this data.
The problem is when first raise of event finishes, i have already full
buffer. And event is raised
Or maybe there is a way to clear the buffer....

Any help would be appreciated
May 16 '06 #1
2 1065
Hi,

This is an example of Producer-Consumer escenario. you can google for
several way to solve this.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"PiotrKolodziej" <pi*************@gmail.com> wrote in message
news:9e***************************@news.chello.pl. ..
Hi
I have an event that receives data from RS port

rs.DataReceived += new SerialDataReceivedEventHandler(rs_DataReceived);

I need to block raising an event when the previous one has not lelft yet.

RS port is receiving very fast the portions of data. When first data
receives, user is asked to do something with this data. Then each another
raise of this event is dooing the same what user did with this data.
The problem is when first raise of event finishes, i have already full
buffer. And event is raised
Or maybe there is a way to clear the buffer....

Any help would be appreciated

May 16 '06 #2
I tend to avoid multithreading when I can, just because it complicates
everything, but in this case I don't see how you can get around it.

The problem, as I understand it, is that you have no idea how long it's
going to take the user to make a decision about what to do with the
data, and so it's not really an option to wait for a response before
you react to other events coming in from the RS port.

Therefore, you have little choice but to change your architecture.
Basically, you should be stacking up data coming in from the RS port in
a queue of some kind while the user is making up his or her mind as to
what to do. Whenever you get an event from the RS port you should
immediately grab the data from the buffer, stick it in some object, and
then queue that object for processing.

When the first piece of data arrives, the program must ask the user
what to do with it, but you can't ask on the same thread on which
you're reading from the RS port, because you can't afford to have the
question to the user blocking you while more data is coming in.

This means (to me) that somehow you have to be reading the RS port from
a background thread, while you ask the user what to do on the main UI
thread.

When the user finally responds, you then process all of the data in the
queue and then wait for more to be queued. I assume that this would be
a yet a third thread, that would simply read from the queue and deal
with the data, then when the queue is empty go to sleep and wait to be
woken up when there is more data in the queue.

At the very least you need something, like a queue, between the RS port
read and the processing to be done, so that data can build up while the
user is deciding what to do and nothing will be lost.

May 16 '06 #3

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

Similar topics

4
by: Applebrown | last post by:
I'm trying my hand at developing a new website for my professional career, and am trying to implement a simple Rollover > Pop-out Menu system, and am finding the javascript confusing to do. I am...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
6
by: Scott Niu | last post by:
Hi, I have this following simple c++ program, it will produce memory leak ( see what I did below ). My observation also showed that: There will be a mem leak when all the 3 conditions are true:...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
12
by: Peter Proost | last post by:
Hi group, I've got what seems a simple problem, but I can't find the solution. I've got a textbox and a handheld scanner to scan barcodes, the scanner just generates keypresses like a keyboard...
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
6
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
15
by: Bjoern Schliessmann | last post by:
Hello all, I'm trying to simulate simple electric logic (asynchronous) circuits. By "simple" I mean that I only want to know if I have "current" or "no current" (it's quite digital) and the only...
10
by: blaine | last post by:
Hey everyone! I'm not very good with Tk, and I am using a very simple canvas to draw some pictures (this relates to that nokia screen emulator I had a post about a few days ago). Anyway, all is...
10
by: Rob | last post by:
For example, how could you programatically "click" on a button in a Form ?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.