Hello,
i am Currently busy with a Script that reads an Digital Agent (1 or 0) that represents when an machine is running or not. I managed to read the raw value of the digital when the page opens (i have a messagebox that pops up saying the machine has stopped when the value is 0 and when it is 1 then the page loads normally) however when i change the value to 1 and then 0 again i want the message box to pop up again and at this moment it does not.
Here is my code i have currently trying to see if it registers that the value has changed but it did not display any of the message boxes i added so i have no idea if im doing something wrong. Any help or guidance would be appreciated.
private void DataElement_ValueChanged(object sender, EventArgs e)
{
// Add some debugging code to verify that the function is being called
MessageBox.Show("DataElement_ValueChanged function called");
// Check if the sender is the correct DataElement object
DataElement de = sender as DataElement;
if (de != null)
{
MessageBox.Show("DataElement value changed to: " + de.Value);
}
// Call the CheckMachineStop function
CheckMachineStop();
}
private void CheckMachineStop()
{
// Read the data element value using ReadDataElement method
MethodReturnInfo mri = MyConnection.ReadDataElement("RS27_Tags.Digital.MACHINERUN.rawValue");
// Get the DataElementCollection object from the MethodReturnInfo object
DataElementCollection collectionReturned = mri.ReturnObject as DataElementCollection;
// Check if the collection contains the data element
if (collectionReturned.Contains("RS27_Tags.Digital.MACHINERUN.rawValue"))
{
// Get the DataElement object from the collection
DataElement de = collectionReturned["RS27_Tags.Digital.MACHINERUN.rawValue"];
// Check if the element's value is 0
if (Convert.ToInt32(de.Value) == 0)
{
// Shows A message to the Operator that the machine has stopped
MessageBox.Show("Machine is Stopped");
}
}
}