Exemple #1
0
        //private void button14_Click(object sender, EventArgs e)
        //{
        //    UInt32 T = 0;//UInt32 值类型表示值介于 0 和 4,294,967,295 之间的无符号整数。
        //    bool R;
        //    if (CommPort.IsOpen == false)
        //    {
        //        COMM_UpdateMsg("失败", 0, "通讯端口未打开!", 0);
        //        return;
        //    }
        //    R = CommToDevice(0x04, 0, ref T);
        //    if (R == false)
        //    {
        //        COMM_UpdateMsg("", 0, "通讯错误!", 0);
        //        //MessageBox.Show("通讯错误!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //    }
        //    else
        //    {
        //        COMM_UpdateMsg("", 100, "操作成功!", 1);
        //        //MessageBox.Show("操作成功!", "消息", MessageBoxButtons.OK, MessageBoxIcon.None);
        //    }
        //}
        #endregion

        #region 加载默认参数到控件的函数
        private void LoadDefaultParams(SysConfig.ConfigParams Config)
        {
            tb3.Text           = Config.BaseLevel.ToString();
            Increaselevel.Text = Config.IncreaseLevel.ToString();

            if (Config.InterTimeSet.ToString() == "24")
            {
                cb5.SelectedIndex = 4;
            }
            if (Config.InterTimeSet.ToString() == "1")
            {
                cb5.SelectedIndex = 0;
            }
            if (Config.InterTimeSet.ToString() == "2")
            {
                cb5.SelectedIndex = 1;
            }
            if (Config.InterTimeSet.ToString() == "4")
            {
                cb5.SelectedIndex = 2;
            }
            if (Config.InterTimeSet.ToString() == "8")
            {
                cb5.SelectedIndex = 3;
            }

            tb1.Text          = Config.DevNumber.ToString();
            tb2.Text          = Config.PasswordCode.ToString();
            tb5.Text          = Config.CompName.ToString();
            tb6.Text          = Config.StationName.ToString();
            checkBox1.Checked = Config.WarnEnable;
            tb7.Text          = Config.WarningLevel.ToString("F1");
            cb3.SelectedValue = Config.WarnInterval;
            cb4.SelectedValue = Config.TelCount;
            tbtel1.Text       = Config.TelNum1.ToString();
            tbtel2.Text       = Config.TelNum2.ToString();
            tbtel3.Text       = Config.TelNum3.ToString();
            tbtel4.Text       = Config.TelNum4.ToString();
            tbtel5.Text       = Config.TelNum5.ToString();
            IP1.Text          = Config.IpAddr1.ToString();
            IP2.Text          = Config.IpAddr2.ToString();
            IP3.Text          = Config.IpAddr3.ToString();
            Port1.Text        = Config.IpPort1.ToString();
            Port2.Text        = Config.IpPort2.ToString();
            Port3.Text        = Config.IpPort3.ToString();

            IP4.Text   = Config.IpAddr4.ToString();
            IP5.Text   = Config.IpAddr5.ToString();
            Port4.Text = Config.IpPort4.ToString();
            Port5.Text = Config.IpPort5.ToString();
            tbold.Text = Config.Authcode.ToString();
        }
Exemple #2
0
        private void button7_Click(object sender, EventArgs e)
        {
            COMM_UpdateMsg("从设备读取配置参数 [0x" + CurConfig.Config.Address.ToString("X2") + "]", 0, " ", 1);
            byte[] ConfigDatas = new byte[320];
            int    Length      = 108 * 2 + 5;
            bool   R           = CommByRS232.ReadPacket(CurConfig.Config.Address, 2004, 108, ref ConfigDatas, ref Length);//2004指的寄存器地址

            COMM_UpdateMsg("", 80, "", 1);
            if (R == true)
            {
                SysConfig.ConfigParams DevConfig = new SysConfig.ConfigParams();
                //DevConfig.ProductDate = ModbusPacket_GetData32(ConfigDatas, 0);
                DevConfig.DevNumber    = ModbusPacket_GetData32(ConfigDatas, 4);                           //偏移量,是指的字节的偏移量
                DevConfig.PasswordCode = ModbusPacket_GetData32(ConfigDatas, 8);

                DevConfig.CompName    = ModbusPacket_GetString(ConfigDatas, 12, 16);
                DevConfig.StationName = ModbusPacket_GetString(ConfigDatas, 28, 16);

                DevConfig.WarningLevel = ModbusPacket_GetData32(ConfigDatas, 44);
                DevConfig.WarnInterval = ModbusPacket_GetData(ConfigDatas, 48);
                DevConfig.WarnEnable   = (ModbusPacket_GetData(ConfigDatas, 50) > 0)?true:false;

                DevConfig.BaseLevel     = ModbusPacket_GetData32(ConfigDatas, 52);
                DevConfig.IncreaseLevel = ModbusPacket_GetData32(ConfigDatas, 56);
                DevConfig.InterTimeSet  = ModbusPacket_GetData(ConfigDatas, 60);//指的是字节数ModbusPacket_GetData

                DevConfig.TelCount = ModbusPacket_GetData(ConfigDatas, 62);
                DevConfig.TelNum1  = ModbusPacket_GetString(ConfigDatas, 64, 16);
                DevConfig.TelNum2  = ModbusPacket_GetString(ConfigDatas, 80, 16);
                DevConfig.TelNum3  = ModbusPacket_GetString(ConfigDatas, 96, 16);
                DevConfig.TelNum4  = ModbusPacket_GetString(ConfigDatas, 112, 16);
                DevConfig.TelNum5  = ModbusPacket_GetString(ConfigDatas, 128, 16);

                DevConfig.IpAddr1 = ModbusPacket_GetString(ConfigDatas, 144, 16);
                DevConfig.IpPort1 = ModbusPacket_GetString(ConfigDatas, 160, 8);

                DevConfig.IpAddr2 = ModbusPacket_GetString(ConfigDatas, 168, 16);
                DevConfig.IpPort2 = ModbusPacket_GetString(ConfigDatas, 184, 8);

                DevConfig.IpAddr3 = ModbusPacket_GetString(ConfigDatas, 192, 16);
                DevConfig.IpPort3 = ModbusPacket_GetString(ConfigDatas, 208, 8);//220


                Length = 26 * 2 + 5;
                byte[] ConfigDatas1 = new byte[80];
                R = CommByRS232.ReadPacket(CurConfig.Config.Address, 2112, 26, ref ConfigDatas1, ref Length);//指的是寄存器个数
                if (R == true)
                {
                    DevConfig.IpAddr4 = ModbusPacket_GetString(ConfigDatas1, 0, 16);
                    DevConfig.IpPort4 = ModbusPacket_GetString(ConfigDatas1, 16, 8);

                    DevConfig.IpAddr5 = ModbusPacket_GetString(ConfigDatas1, 24, 16);
                    DevConfig.IpPort5 = ModbusPacket_GetString(ConfigDatas1, 40, 8);

                    DevConfig.Authcode = ModbusPacket_GetData32(ConfigDatas1, 48);


                    LoadDefaultParams(DevConfig);

                    COMM_UpdateMsg("", 100, "成功!", 1);
                    tbnew.Text  = "";
                    tbnew2.Text = "";
                }
            }
            else
            {
                COMM_UpdateMsg("", 100, "失败!", 0);
            }
        }