Pass value two textbox's from one variable value

68 views Asked by At

I have an encoder connected from Siemens PLC with data block "DB1.DBD56".

My problem is, the two textbox has the same result or value.

Scenario:

Read Before 1seconds and Read After 1seconds

I want the result like this:

[For reference] (https://i.stack.imgur.com/HK9zU.png)

[PLC Ladder] (https://i.stack.imgur.com/kGN62.png)

#region EVENT TO START READING THE ENCODER

    private void timer_anvilState_Tick(object sender, EventArgs e)
    {
        try
        {
            Edata_convertion();
            read_lastweld_result();

            bool anvilState = (bool)plc_s7_1200.Read("DB1.DBX68.4");

            if (plc_s7_1200.IsConnected)
            {
                if (anvilState == true)
                {
                    timer_OneCycleProcess.Start(); //STATE MACHINE TIMER
                }
                else
                {
                    timer_OneCycleProcess.Stop();
                    command = "IDLE";
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Please check between PC and PLC connection " + "\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

    #region READ BEFORE
    public void Read_Before()
    {
        if (plc_s7_1200.IsConnected)
        {
            bool anvilState = (bool)plc_s7_1200.Read("DB1.DBX68.4");

            if (anvilState == true)
            {
                string Edata = string.Format("{0:0.0}", convertTomm);
                txtbefore.Text = Edata;
            }
        }
    }
    #endregion

    #region READ AFTER
    public void Read_After()
    {
        bool gen_US_on = (bool)plc_s7_1200.Read("DB1.DBX78.2");
        if (gen_US_on == true)
        {
            string Edata = string.Format("{0:0.0}", convertTomm);
            txtafterWeld.Text = Edata;
        }
    }
    #endregion
1

There are 1 answers

0
GMK On

Here's my solution.

Only revised the PLC ladder as stated my replied at comment section.

https://i.stack.imgur.com/GUBtg.png

My C# program nothing changes.

Sharing my basic state machine code

#region ONE CYCLE PROCESS
private void timer_OneCycleProcess_Tick(object sender, EventArgs e)
{
    switch (command)
    {
        case "IDLE":
            command = "BEFORE";
            break;

        case "BEFORE":
            before();
            command = "AFTER";
            break;
        case "AFTER":

            after();

            prev_result();

            read_maintenanceCounter();

            read_outputCounter();

            command = "SAVE";
            break;

        case "SAVE":

            command = "STOP";

            save();

            save_history();
            break;
        case "STOP":
            timer_OneCycleProcess.Stop();
            plc_s7_1200.Write("DB1.DBX38.0", 0);
            break;

        default:
            break;
    }
}
#endregion