Main Site Documentation

NETMF time-critical task


#1

Hello guys,

I need a little hint. I have to write an application for our board which is using EMX. We already have an application which serves as attendance panel - user can choose from list of attendance events, enclose his RFID card, so the event is generated, stored on SD card and send over LAN to our server. It works well without any significant problems.

Now, we have to connect it directly to our control unit (runs Linux) which communicates with devices over RS 485 bus. Problem is that our control unit periodically tests device on the bus if they are responding by sending connection tests. Device has to reply to this connection test in 30 ms, otherwise connection lost with this device is declared by the control unit. I have already managed to write simple communication using SerialPort class in .NETMF which can respond to this packet in 30 ms. But now I need to implement GUI for user interaction and I’m starting to worry that I cannot ensure that I will always respond to connection test in 30 ms. Any hints how can I solve such a time-critical task?

Thank you
Martin


#2

That’s indeed very tight requirements! First of all, make all of your variables static so GC never runs (nothing happens while it’s running). Then, I suggest making your event handlers short and quick; if they are not at the moment, use AutoResetEvent (or ManualResetEvent) in the handler, so it simply unblocks a separate thread that actually handles the event. You’ll get some lag between action and response, but your event and interrupts will be quick thus increasing your chances to respond in time.

Finally, if that doesn’t help, you can use RLP to handle serial interrupt directly in native code.


#3

Thank you for reply. As far as I know, you can just call RLP methods from NETMF and in this case, you cannot do anything in NETMF until this call finshes, so I can’t do my GUI things?


#4

No, you can’t, but RLP stuff is usually fast. For UI, your window is ~100ms — more than enough.

Besides, If you handle the interrupt in RLP, managed code isn’t even called, so sending a response sdould be a matter of a few milliseconds.


#5

Thats generally true.
But you can also handle Interrupts in RLP, so there is no Need to actually call a RLP method to answer your Serial message.
And since you Need to answer it in less than 30ms, it should not block you GUI even that not C# code is executed during that time.


#6

Okay, I’m going to ask the stupid question. Why is the control panel requiring a response in only 30ms? Based on the requirements you listed, that seems like an incredibly small amount of time to wait before declaring a device dead. Is there some security threat that it is trying to mitigate? Or, was someone just in a hurry to deliver bad news?


#7

Yeah, I also found that kind of strange…


#8

This time-out is not from my head but I understand it’s because there can be up to 30 devices connected to RS 485 bus and only one can communicate at a time. So it’s because we need to keep all devices on the bus responsive as much as possible.


#9

Hi, guys, I have one more question. I have managed to write communication in RLP, response is indeed superfast for connection test, so there is no more problems. But there are some other packets when I don’t have to be so fast and I would like to process them in .NET. Is there a way how to quickly tell .NET application that I have received some bytes into my read buffer in RLP or do I have to make some kind of polling mechanism from managed environment to ask if there are any data available?


#10

Check the RLP.h file. It has a PostManagedEvent function, it does exactly that.


#11

That’s exactly what I neeed, thank you guys again for quick reply.