Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

C# MessageBasedSession freezes after continuous operation

Hello,

 

I have been having a nuisance problem with an instance of a MessageBasedSession.  I am using VISA to communicate with an environmental chamber via RS232.  When the test program is running, the chamber is polled every 2 seconds to retrieve the current temperature and humidity inside the chamber.  Everything works perfectly during the first hour of the test.  After two to three hours, however, the program freezes (does not throw any exceptions) when the chamber is queried.  Here is the code:

 

///////////////begin

public EnvironmentalChamberControl(int COMPortInteger)
        {
            try
            {
                resourceString = "ASRL" + COMPortInteger.ToString() + "::INSTR";
                mbSession = (MessageBasedSession)ResourceManager.GetLocalManager().Open(resourceString);

                mbSession.SetAttributeInt32(NationalInstruments.VisaNS.AttributeType.AsrlBaud, 9600);
                mbSession.SetAttributeInt16(NationalInstruments.VisaNS.AttributeType.AsrlDataBits, 8);
                mbSession.SetAttributeInt16(NationalInstruments.VisaNS.AttributeType.AsrlParity, 0);

                mbSession.Timeout = 1000;
            }
            catch (Exception ex)
            {
                Console.WriteLine("EnvironmentalChamberControl.EnvironmentalChamberControl(): " + ex.Message);
            }
        }

 

private string SendCommandToChamberAndQuery(string command)
        {
            try
            {
                string response = mbSession.Query(command + "\n");
                return response;
            }
            catch (Exception ex)
            {
                return "QUERY FAILED";
            }
        }

/////////////////end

 

This code works perfectly for at least 1 hour.  After that, the program will continue to run for 1 to 2 hours before freezing at the line above (highlighted in bold).  The "SendCommandToChamberAndQuery" method is called once every 2 seconds from a timer event in the main thread.  Any ideas as to what is causing this problem?

 

Thank you for your assistance!!

 

-Eric

0 Kudos
Message 1 of 6
(4,696 Views)

This sounds like a memory leak.  Are you opening a new VISA session multiple times or just once at the beginning of execution?  I've seen this behavior in LabVIEW when VISA Open was called in a loop.

 

Regards,

Ben

National Instruments
Certified LabVIEW Associate Developer
Certified TestStand Developer
0 Kudos
Message 2 of 6
(4,669 Views)

Hi Ben,

 

I am opening the session at the start of the program, and then I query the chamber every 2 seconds.  The session stays open and at the end of the program, the session is disposed.  However, the program can run for up to 24 hours, and the program seems to freeze during the 2nd or 3rd hour of the test.

0 Kudos
Message 3 of 6
(4,663 Views)

EricJay,

 

I have several more questions about your application: 

 

1. What happens when the program freezes?  Are you forced to quit the program and start again?

 

2. What do you mean by the program can run for 24 hours?  Is this what it is supposed to do and it can't because the program freezes?  Or does the program unfreeze and run until it reaches 24 hours?

 

3. Does the program freeze every time after running for several hours or is it intermittant?

 

4. Can you check your resouce usage after several hours of running and make certain that there isn't a memory leak?

 

Regards,

Ben

National Instruments
Certified LabVIEW Associate Developer
Certified TestStand Developer
0 Kudos
Message 4 of 6
(4,643 Views)

1.  When the program freezes, I must forcefully terminate it, and I must restart the computer.  I cannot create and new VISA instances after the program crashed.  Also, I am unable to communicate with any VISA resources from within MAX until after a reboot.

 

2. The application runs a test program which consists of a series of test sequences.  Many tests require over 100 sequences, which would take approximately 24 hours to complete.  Therefore, the VISA session would be open for up to 24 hours, and queries would be executed every 2 seconds during this time.  However, after about 2-3 hours, the program completely freezes (all controls and indicators are unresponsive).  Since the application is running in hosted debug mode, I can see exactly where the program has frozen.  It freezes when it attempts to execute the messageBasedSession query during one of the 2-second chamber polls.  I don't see anything in the call stack that is not where it isn't supposed to be.

 

3. The problem appears to be intermittent, however, it occurs maybe 80% of the time.

 

4. I will double-check the resources.  I am also using VISA instances to control two other pieces of hardware simulatanously.  I have no problems with either of them, although I am not continuously polling them either.

 

Thank you for your help with this.

 

-Eric

0 Kudos
Message 5 of 6
(4,639 Views)

You could try running the experiment without communicating with the other pieces of hardware.  Determining if having only one VISA session to one instrument makes any difference in the behavior would be a useful test.

 

Ben

National Instruments
Certified LabVIEW Associate Developer
Certified TestStand Developer
0 Kudos
Message 6 of 6
(4,616 Views)