Hi all ,

i'm writing a program that communicates with com port.
i need to send a few packets.

the thing is that i want to wait after each packet so that the receiver could send me an ack !

in pseud code :

for (x=0;x<Packets.Lenth;x++)
{
    sendData(Packets[x]);
    
   waitForDataReceivedEvent ();
}

my question is how do i implement waitForDataReceivedEvent ?

a serialport class event is raised - its called SerialDataReceivedEventHandler. how can i make my original method (the one with the for loop) to wait until this event is raised ?

thanks
Zvika

Use the AutoResetEvent class, and call WaitOne() where you want to wait for the packet.

Then you need to write a SerialDataReceivedEventHandler function, and in there call the Set() method on the same AutoResetEvent instance that you are waiting on.

had already found it at msdn sorry for not marking it as solved ...
anyway it works great !


Zvika

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.