Пример #1
0
        private void btnDeviceInfoSetting_Click(object sender, EventArgs e)
        {
            AdamInformation adamOld = (AdamInformation)adamList[m_iIndex];
            AdamInformation adamNew = new AdamInformation();

            adamOld.CopyTo(ref adamNew);

            Cursor.Current = Cursors.WaitCursor;

            adamNew.DeviceName  = txtName.Text;
            adamNew.Description = txtDescription.Text;
            if (SetAdamInformationEx(AdamInfoType.AdamDeviceInfo, m_iTimeout, adamNew))
            {
                MessageBox.Show("Change device information done!", "Information");
                if (adamNew.DeviceName != adamOld.DeviceName)
                {
                    tcpTree.SelectedNode.Text = string.Format("{0}.{1}.{2}.{3}-[{4}]",
                                                              adamNew.IP[0], adamNew.IP[1], adamNew.IP[2], adamNew.IP[3], adamNew.DeviceName);
                }
                adamNew.CopyTo(ref adamOld);
            }
            else
            {
                MessageBox.Show("Change device information failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            Cursor.Current = Cursors.Default;
            adamNew        = null;
        }
Пример #2
0
        private bool ApplyNetwork(string strIP, string strSubnet, string strGateway, string strHostIdle)
        {
            FormWait        frmWait;
            AdamInformation adamOld = (AdamInformation)adamList[m_iIndex];
            AdamInformation adamNew = new AdamInformation();

            string[] szMACs = txtMac.Text.Split(new Char[] { '-' });
            string   szIP;
            bool     bRet = true;

            adamOld.CopyTo(ref adamNew);
            szIP = strIP;
            if (!IsValidIP(strIP, ref adamNew))
            {
                MessageBox.Show("The IP address is invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                bRet = false;
            }
            if (!IsValidSubnet(strSubnet, ref adamNew))
            {
                MessageBox.Show("The subnet address is invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                bRet = false;
            }

            if (((adamOld.DeviceID[0] == 0x50) && (adamOld.DeviceID[1] == 0x00)) ||
                ((adamOld.DeviceID[0] == 0x60) && (adamOld.DeviceID[1] == 0x22)) ||
                ((adamOld.DeviceID[0] == 0x60) && (adamOld.DeviceID[1] == 0x24)))
            {
                if (bRet && !IsValidIPClass(strIP, strSubnet))
                {
                    bRet = false;
                }
            }

            if (!IsValidGateway(strGateway, ref adamNew))
            {
                MessageBox.Show("The default gateway is invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                bRet = false;
            }

            if (!IsValidIdle(strHostIdle, ref adamNew))
            {
                if (adamNew.HardwareType[1] == 2)     // ADAM-6000W
                {
                    if (adamNew.HardwareType[0] == 0) // ADAM-6000W
                    {
                        MessageBox.Show("The host idle time must be between 10~255!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }
                    else
                    {
                        MessageBox.Show("The host idle time must be between 0~4095!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }
                }
                else
                {
                    MessageBox.Show("The host idle time must be between 2~4095!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                bRet = false;
            }

            if (bRet)
            {
                Cursor.Current = Cursors.WaitCursor;
                //
                if (SetAdamInformationEx(AdamInfoType.AdamNetConfig, m_iTimeout, adamNew))
                {
                    // reset module
                    SetAdamInformationEx(AdamInfoType.AdamReset, m_iTimeout, adamNew);
                    frmWait = new FormWait("Waiting", "Reset module", m_iResetMilliSecond);
                    frmWait.ShowDialog();
                    frmWait.Dispose();
                    frmWait = null;

                    // refresh tree if IP is modified
                    MessageBox.Show("Change network done!", "Information");
                    if ((adamNew.IP[0] != adamOld.IP[0]) || (adamNew.IP[1] != adamOld.IP[1]) ||
                        (adamNew.IP[2] != adamOld.IP[2]) || (adamNew.IP[3] != adamOld.IP[3]))
                    {
                        adamNew.CopyTo(ref adamOld);
                        // refresh tree
                        tcpTree.BeginUpdate();
                        tcpTree.SelectedNode.Text = string.Format("{0}.{1}.{2}.{3}-[{4}]",
                                                                  adamNew.IP[0], adamNew.IP[1], adamNew.IP[2], adamNew.IP[3], adamNew.DeviceName);
                        tcpTree.EndUpdate();
                    }
                    else
                    {
                        adamNew.CopyTo(ref adamOld);
                    }
                }
                else
                {
                    MessageBox.Show("Change network failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                Cursor.Current = Cursors.Default;
            }
            adamNew = null;

            return(bRet);
        }