Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instances affect each other in case of disconnects #90

Open
JeremyMahieu opened this issue Mar 28, 2023 · 1 comment
Open

Instances affect each other in case of disconnects #90

JeremyMahieu opened this issue Mar 28, 2023 · 1 comment

Comments

@JeremyMahieu
Copy link

It's not impossible that it's due to my own code but I'm having the following problem:
I connect to 5 modbus tcp server in a foreach loop. I try to connect and then read some values. The code is surrounded by try catches. Imagine server 1, 2, 3, and 5 is available but 4 is not available. After I get an exception on server 4, I don't get anything out of server 5 either. If I swap the place of 4 and 5, I can read values from server 5.

I don't think my "ModbusService" had any statics or dependency injected things that might be singleton. So I believe the problem must be in the library.

Any tips on how I could diagnose this?

        public DirigentService()
        {
            ModbusDevice dev1 = new ModbusDevice();
            dev1.IPEndPoint = new(IPAddress.Parse("192.168.0.2"), 502);
            dev1.ModbusService = new ModbusService();
            devices.Add(dev1);

            ModbusDevice dev2 = new ModbusDevice();
            dev2.IPEndPoint = new(IPAddress.Parse("192.168.0.3"), 502);
            dev2.ModbusService = new ModbusService();
            devices.Add(dev2);

            (...) add more devices

            // Set up a timer to read values every few seconds
            Log.Debug("Seting up read timer");
            timer = new System.Timers.Timer(2000);
            timer.Elapsed += (s, e) => DoRead();
            timer.Start();
        }

        private void DoRead()
        {
            foreach (var dev in in devices)
            {
                try
                {
                    dev.ConnectAndReadAllValues();
                }
                catch { }
            }

        }
@Apollo3zehn
Copy link
Owner

Sorry for being so late. FluentModbus has no (known) interdependencies between individual instances so they should not affect each other. I have no clue what could cause this behavior :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants