ProXR Relay board TCPIP communication issue

Fellow programmers… I’ve just recently solved a stubborn communication problem with my ProXR relay boards. The problem was of my own making, but could catch someone else.

I have a 3-tiered web application (database/Business Layer/Client Layer) based on the MVP model. The business layer is where all communication to the ProXR boards take place. The client sends requests to the business layer via specific URL’s to the various controllers supporting the application.

What was happening was that I would turn specific relays on, then a while later, the client would send another command to turn them off, but seemingly randomly, the business layer lost all connectivity to the ProXR boards. After a while, it would mysteriously come back.

What was happening was that the MVP controller would instantiate a new instance of a relay processing class that opened ports to the ProXR and did the requested work. After the work was done, control passed back to the MPV controller method tha formatted a HttpResponseMessage and sent it back to the client.

What I failed to do was properly dispose of the relay processing class. Because this is a web application, IIS keeps a cache of recently used objects figuring if you use them once, you’ll likely use them again. Unfortunately, subsequent calls to different entry points in the MVP controller would instantiate a new instance of the relay processing class and since the ProXR boards only support 1 socket connection, it would fail to open a new port to the ProXR board. It appeared that the board was not working, even though I could communicate with the board via the web interface on the board. Very frustrating.

As it turned out, ff I waited long enough, the IIS garbage collection would take place and the relay class object was destroyed and all communication would be restored. Until the next time.

Finally I realized my error and properly disposed of the relay controller class in the MVP controller before returning to the client. Problem solved!

Hope this helps someone.

3 Likes