Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

I am having some trouble with interrupt handling.

I have a device which sends me an interrupt every 5 seconds, and I need my code (using either VB.NET or c++) to respond to the interrupt as soon as it is fired.

Is there anyone who would know how to do that ?

Thanks :-\

Posted

Poll the device..which means create a continous loop that checks for input.

When you recieve the input, temporarily stop the loop (setting a flag would be one way to achieve this), fire an EVENT that parses the input and resets the flags when the method is done processing the information.

 

InputDevice device1 = new InputDevice();

EventHandler inputEvent = new EventHandler;

bool processing = false;

 

do

{

 

if (!processing)

{

if (device1.InputReady())

{

inputEvent(device1, null)

}

}

 

} while (true);

 

 

if you need to send the event method different parameters, create a new delegate and eventhandler.

Posted

hey, thanks so much for the reply.

 

I ended up multithreading, and so I sort of used a polling technique (my main reason why i didnt use polling before was that i wanted to be able to call other functions and do other things at the same time as the timer). So multithreading seemed to be the best way.

Also, thanks for the info on how to raise events in c++. If I wanted to "catch" the events in VB.NET, would you know how I can do that (what would be the syntax in vb)? (I'm planning on wrapping the c++ code and using it as a dll in vb.)

 

Thanks again ;)

 

 

 

 

Poll the device..which means create a continous loop that checks for input.

When you recieve the input, temporarily stop the loop (setting a flag would be one way to achieve this), fire an EVENT that parses the input and resets the flags when the method is done processing the information.

 

InputDevice device1 = new InputDevice();

EventHandler inputEvent = new EventHandler;

bool processing = false;

 

do

{

 

if (!processing)

{

if (device1.InputReady())

{

inputEvent(device1, null)

}

}

 

} while (true);

 

 

if you need to send the event method different parameters, create a new delegate and eventhandler.

Posted

To handle the event, you merely add a function to the event handler array list

 

For example, if you expose the event MarryRussianBride from a class, eg.

 

class MailOrderBrides

{

 

public event MarryRussianBride;

 

}

 

 

 

and then handle the event in another class

 

Public Class ProcessMarriages

 

Private mob as New MailOrderBrides();

 

mob.MarryRussianBride.AddHandler(addressOf(HandleRussianBrides));

 

Public Sub HandleRussianBrides (sender as Object, e as EventArgs)

'process event

End Sub

 

End Class

Posted

hey, thanks again for ur help. I'll see if this code is ok for dll's (coz I have to expose the functions written in c++, in vb.net, by using libraries).

Anyways, thanks again. :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...