Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            CVar              nVar1 = frmMain.staComm.GetVarByStaNameVarName(sListStaName[0], "I_W");
            CVar              nVar2 = frmMain.staComm.GetVarByStaNameVarName(sListStaName[1], "I_W");
            CVar              nVar3 = frmMain.staComm.GetVarByStaNameVarName(sListStaName[2], "I_W");
            CStation          Sta1  = frmMain.staComm.GetStaByStaName(sListStaName[0]);
            CProtcolModbusTCP STCP1 = (CProtcolModbusTCP)Sta1;
            CStation          Sta2  = frmMain.staComm.GetStaByStaName(sListStaName[1]);
            CProtcolModbusTCP STCP2 = (CProtcolModbusTCP)Sta2;
            CStation          Sta3  = frmMain.staComm.GetStaByStaName(sListStaName[2]);
            CProtcolModbusTCP STCP3 = (CProtcolModbusTCP)Sta3;

            double iValue1 = nVar1.GetDoubleValue() + Convert.ToDouble(textBox1.Text);
            int    fSend1  = (int)Math.Round(iValue1 / nVar1.RatioValue);

            STCP1.SendAODO(nVar1.ByteAddr, (int)fSend1, 6);

            double iValue2 = nVar2.GetDoubleValue() + Convert.ToDouble(textBox2.Text);
            int    fSend2  = (int)Math.Round(iValue2 / nVar2.RatioValue);

            STCP2.SendAODO(nVar3.ByteAddr, (int)fSend2, 6);

            double iValue3 = nVar3.GetDoubleValue() + Convert.ToDouble(textBox3.Text);
            int    fSend3  = (int)Math.Round(iValue3 / nVar3.RatioValue);

            STCP3.SendAODO(nVar3.ByteAddr, (int)fSend3, 6);
        }
Пример #2
0
        private void dGV1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex >= 2 && e.RowIndex > 1)
            {
                DataGridView dGV  = (DataGridView)sender;
                int          iSta = e.ColumnIndex - 2;

                CStation          Sta  = frmMain.staComm.GetStaByStaName(sListStaName[iSta]);
                CProtcolModbusTCP STCP = (CProtcolModbusTCP)Sta;
                if (STCP == null)
                {
                    return;
                }
                try
                {
                    int iVar = e.RowIndex;
                    if (iVar < sListVarName.Length)
                    {
                        CVar  nVar   = frmMain.staComm.GetVarByStaNameVarName(sListStaName[iSta], sListVarName[iVar]);
                        float iValue = Convert.ToSingle(dGV1.Rows[iVar].Cells[2 + iSta].Value);
                        int   fSend  = (int)Math.Round(iValue / nVar.RatioValue);
                        STCP.SendAODO(nVar.ByteAddr, fSend, 6);
                    }
                    else if (iVar == sListVarName.Length + 1 || iVar == sListVarName.Length + 2)
                    {
                        int iValue = Convert.ToInt32(dGV1.Rows[iVar].Cells[2 + iSta].Value);
                        int iAdd   = Convert.ToInt32(dGV.Rows[iVar].Cells[1].Value);
                        if (iAdd > 0)
                        {
                            STCP.SendAODO(iAdd, iValue, 6);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }