0

In a C# application I have this code:

for (var i = 0; i < 10; i++)
{
    try
    {
        var op = operators[i]; // retrieve data
        plc.Modbus.WriteSingleRegister(MODBUS_TABLE_OP + i * 2, op.Id);
        plc.Modbus.WriteSingleRegister(MODBUS_TABLE_OP + i * 2 + 1, op.Password);
    }
    catch (Exception ex)
    {
        Logger.Error("Error: {0}", ex);
        throw;
    }
}

Where Modbus is an EasyModbus instance, and Id and Password are type int limited by software to 16-bit (i.e. op.Id = value & 0xFFFF). The code always ran fine, but since few days on the production machine after 4 or 5 iterations an exception is caught. This now happens every time the code runs. The exception message is:

Impossibile scrivere dati sulla connessione di trasporto: Connessione interrotta dal software del computer host

Unfortunately the production machine is set to Italian and I cannot change this setting. Nor I can run the code in debug mode on the production machine. Anyway, the most literal translation in English is:

Unable to write data on the transport connection: The connection was interrupted by the host computer software

I have difficult to understand the message itself, both in Italian and in English:

  1. what does host computer mean in this context? The local machine (where the C# application runs) or the remote one?

  2. what does software mean in this context? My software or a 'generic' one, like libraries or even the OS?

Without understanding these meanings I'm not able to figure out what has changed and where.

Update

Right know I can have the log of i and the op fields:

i    op.Id    op.Password
0    2        1111
1    5        1112
2    6        8765
3    7        0000
4    9        7877
// -> disconnection 
Mark
  • 4,338
  • 7
  • 58
  • 120
  • Do you have a non-production machine to run the same code against? This will isolate the problem from the production machine and show if its the machine that your application is running on that causes the problem. Have you checked that there is actually a modbus network connected? Can you log more information such as value of `i` and `op.id` and say `ex.data` ? – ChrisBD Aug 05 '21 at 10:22
  • @ChrisBD, I have my dev machine but it would be very hard they grant me the permission to connect it to the PLC. I will try, indeed. The modbus is connected because other features work fine, and even the first rows are sent successfully. – Mark Aug 05 '21 at 10:53
  • @ChrisBD, from your comment it seems the message itself is not clear enough to understand where is the problem, is it? – Mark Aug 05 '21 at 10:56
  • Sorry I meant to say that the plc may drop the connection due to an issue with values of `i` of 5 or above – ChrisBD Aug 05 '21 at 11:02
  • @ChrisBD, it could, but until few days ago it worked fine. It was designed (and tested!) to receive up to 10 records. And nobody made changes since then. – Mark Aug 05 '21 at 11:07
  • If there is a Modbus error (say, address out of range) it should answer with the error frame, not closing the connection. Sorry to repeat again: *does the message clearly state that is the **remote** end-point that close the connection?* – Mark Aug 05 '21 at 11:08
  • Do you log connect and disconnect events or calls? – ChrisBD Aug 05 '21 at 11:22
  • Not really, but I log if the remote devices answer to pings periodically. After this error for few seconds the PLC doesn't answer, then it comes back "online". – Mark Aug 05 '21 at 11:27
  • Does it behave the same if you started your loop with `i=4` e.g. it fails when `i==9`? – ChrisBD Aug 05 '21 at 11:31
  • I need to try when I can go to the factory. Anyway, I'm still looking for the exact meaning of the message sentence. It's not easy, but I can debug with similar trials though. – Mark Aug 05 '21 at 11:42

0 Answers0