1

I am using S7.NetPlus library to connect to Siemens S7-1500. When trying to read data from the plc, there are no problems. However, I am having a vary difficult time Writing new values to the plc. I have tried using plc.Write or plc.WriteClass. The weird part is, certain values do get changed when running simulation (all except DB46.DBX0.0 - no command seems to effect this field, even if trying to change its value in the TIA v17 portal).

Example 1:

Plc.Write("DB46.DBX0.0", true);       
Plc.Write("DB46.DBX0.1",true);

Example 2:

data.START = true;
data.STATUS_FINISHED = true;
data.STATUS_ERROR = true;
data.STATUS_ON = true;
data.LIFE_BIT = (short)(ushort)1;
Plc.WriteClass(data, 46);

When connection to actual plc none of the variables get changed when using the Write functions. What can I do?

SeeSharper
  • 23
  • 4

1 Answers1

0

Has this been resolved?

I have experienced somewhat similar situation: I am able to write to the (S7-1500 OpenController) PLC but eventually it will stop writing. Or is it the case that the PLC stops accepting the external writing?

It seems like the connection to the controller is established, the write function is excecuted without error and connection is finally closed.

When writing to PLC from the windows application stops working, the PC part has to be restarted to be able to write again. But the same situation keeps repeating itself.

logText(string.format("Card {0} detected in range. ", cardID));
logText(string.format("Previous detected state is {0}", prevDectedStatus));

logText("Attempting to open a connectiong to the PLC");

plc.Open();

if (plc.IsConnected)
{
    logText("Connection established");

    try
    {
        // The RFID
        rfidValue.Value = cardID;
        rfidValue.Count = cardID.Length;

        // The DateTime datatype must be of the correct S7 format.
        String dt = DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss");
        rfidTime.Value = DateTime.ParseExact(dt, "yyyy-MM-dd-HH:mm:ss", null);

        // Card in range
        rfidDet.Value = isCardDetected;

        dataItemsWrite.Add(rfidValue);
        dataItemsWrite.Add(rfidTime);
        dataItemsWrite.Add(rfidDet);

        logText(string.format("Attempting to write rfid={0}, time={1}, detected={2}", rfidValue.Value, rfidTime.Value, rfidDet.Value));
        plc.Write(dataItemsWrite.ToArray());

        logText("Done writing to PLC");
    }
    catch (Exception ex){
        logText(string.format("Caught an exception: {0}", ex));
    }
}
else
{
    logText("Failed to establish a connection to PLC");
}

logText("Store state (prev=cur), used when card leaves field");
prevDectedStatus = isCardDetected;
logText("Done storing state");

logText("Attempt to close connection to PLC");
plc.Close();
logText("Done, connection is " + (plc.IsConnected ? "open":"closed"));
skari
  • 45
  • 1
  • 8