nima1985 Posted July 4, 2005 Posted July 4, 2005 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 :-\ Quote
Diesel Posted July 5, 2005 Posted July 5, 2005 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. Quote
nima1985 Posted July 5, 2005 Author Posted July 5, 2005 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. Quote
Diesel Posted July 5, 2005 Posted July 5, 2005 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 Quote
nima1985 Posted July 6, 2005 Author Posted July 6, 2005 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.