MIAC Slave raise event on input high

For MIAC users to discuss projects, applications, and any other issues related to the MIAC unit.

Moderators: Benj, Mods

Post Reply
singerinst_ben
Posts: 22
Joined: Fri Jun 20, 2014 4:41 pm
Location: England, UK
Has thanked: 10 times
Been thanked: 7 times
Contact:

MIAC Slave raise event on input high

Post by singerinst_ben »

Hi all,

I'm using the MIAC as a slave to a C# application. We have some external buttons hooked up to say input 1 and 2 on the MIAC. When we have one of these inputs go high I want to raise an event in my C# application. What's the best way of communicating the event between the slave firmware and the C# application - I guess have a background thread checking the input states as a bank and dispatching events when inputs go high? This seems very inefficient. Is there a way to trigger an event in the MIAC firmware that can be handled in the C# application so that I don't have to constantly ask the MIAC to feedback the state of it's inputs?

Regards,

Ben

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: MIAC Slave raise event on input high

Post by Benj »

Hello Ben,

Using the slave component polling from the PC might be your best option. If you used the serial USB component instead then you could get the MIAC to do the polling but then you have to change all your comms in the C# application which is probably not what you want to do.

singerinst_ben
Posts: 22
Joined: Fri Jun 20, 2014 4:41 pm
Location: England, UK
Has thanked: 10 times
Been thanked: 7 times
Contact:

Re: MIAC Slave raise event on input high

Post by singerinst_ben »

Thanks Benj,

Thank you very much for your reply. I assumed that was the case. I guess the polling will beneficial in the way that it will also be testing the connection with the MIAC.

One thing that would be really useful is if I added 8 boolean variables (1 for each input) that are set in a macro that is called each cycle of the main program loop on the firmware, that just checks the inputs and sets the relevant variable to high if the input has triggered (so in effect, latch high). Then if I created my own version of the Input_Bank_Read marco on the slave firmware which I could call from the Request_Handler when the command is, for example, 30, and this sets the outgoing variable to the states of the the variables rather than the inputs, and also reset all the variable to low ready for the next poll. This way I could poll from the C# say every 100ms, but have the MIAC read the inputs much more frequently than this so I could keep performance without the risk of missing the inputs going high. However, as the usbslave()::RunSlaveService() is a blocking function I can't poll the input in the main loop. Is there a way to keep the MIAC firmware running the slave service, which calls the request handler, but also regularly poll the inputs? Maybe a timer or something?

Regards,

Ben

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: MIAC Slave raise event on input high

Post by Benj »

Hi Ben,

Yes you can run a timer interrupt along side the slave service macro to do what you are thinking. Sounds like a good option to ensure you don't miss a pulse but also are not hammering the USB comms. Simply write to a glabal variable in the timer macro and read the global variable in the slave service macro.

Just remember to enable the timer interrupt in your main macro before starting the slave service and try to keep the code in the timer macro as short as possible so your not causing large delays at random points in your program.

singerinst_ben
Posts: 22
Joined: Fri Jun 20, 2014 4:41 pm
Location: England, UK
Has thanked: 10 times
Been thanked: 7 times
Contact:

Re: MIAC Slave raise event on input high

Post by singerinst_ben »

Hi Benj,

That's great - I've just implemented it and it works really well actually! When the project is finalized I'll drop out checking any of the inputs we aren't using to ensure it is as efficient as possible.

Thanks again for your help!

Regards,

Ben

Post Reply