Exemple #1
0
        private bool IsValidGateway(string i_szGateway, ref AdamInformation adamObject)
        {
            int iCnt, iNum;

            string[] szIPs;

            szIPs = i_szGateway.Split(new Char[] { '.' });
            if (szIPs.Length == 4)
            {
                for (iCnt = 0; iCnt < 4; iCnt++)
                {
                    if (szIPs[iCnt].Length > 0 && szIPs[iCnt].Length <= 3)
                    {
                        iNum = Convert.ToInt32(szIPs[iCnt]);
                        if (iNum >= 0 && iNum <= 255)
                        {
                            adamObject.Gateway[iCnt] = Convert.ToByte(iNum);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemple #2
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;
        }
Exemple #3
0
        private bool IsValidSubnet(string i_szSubnet, ref AdamInformation adamObject)
        {
            int iCnt, iNum;

            string[] szIPs;
            bool     bIsNotContinueMask = false;

            szIPs = i_szSubnet.Split(new Char[] { '.' });
            if (szIPs.Length == 4)
            {
                for (iCnt = 0; iCnt < 4; iCnt++)
                {
                    if (szIPs[iCnt].Length > 0 && szIPs[iCnt].Length <= 3)
                    {
                        iNum = Convert.ToInt32(szIPs[iCnt]);
                        if (iNum >= 0 && iNum <= 255)
                        {
                            if (iCnt == 3 && iNum == 255)
                            {
                                return(false);
                            }
                            adamObject.Subnet[iCnt] = Convert.ToByte(iNum);

                            //Check mask continue
                            for (int i = 0; i < 8; i++)
                            {
                                if (((iNum >> (7 - i)) & 0x01) > 0)
                                {
                                    if (bIsNotContinueMask)
                                    {
                                        return(false);
                                    }
                                }
                                else
                                {
                                    bIsNotContinueMask = true;
                                }
                            }
                            ////
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemple #4
0
        private void btnSystemRestart_Click(object sender, EventArgs e)
        {
            FormWait        frmWait;
            AdamInformation adamOld = (AdamInformation)adamList[m_iIndex];

            Cursor.Current = Cursors.WaitCursor;

            // reset module
            SetAdamInformationEx(AdamInfoType.AdamReset, m_iTimeout, adamOld);
            frmWait = new FormWait("Waiting", "Reset module", m_iResetMilliSecond);
            frmWait.ShowDialog();
            frmWait.Dispose();
            frmWait = null;

            Cursor.Current = Cursors.Default;
        }
Exemple #5
0
        private void InsertNode(int i_iIndex, AdamInformation adamObject)
        {
            string ipStr;

            byte[]   byTemp, byAdamIP, bySubnet, byLocalIP;
            int      iLan, iIdx;
            TreeNode tcpNode, lanNode, moduleNode;


            byAdamIP = adamObject.IP;
            bySubnet = adamObject.Subnet;
            ipStr    = string.Format("{0}.{1}.{2}.{3}", byAdamIP[0], byAdamIP[1], byAdamIP[2], byAdamIP[3]);
            tcpNode  = tcpTree.Nodes[0]; // TCP root
            iLan     = tcpNode.Nodes.Count;
            for (iIdx = 0; iIdx < iLan - 1; iIdx++)
            {
                byLocalIP = IPAddress.Parse(tcpNode.Nodes[iIdx].Text).GetAddressBytes();
                // check is in the same subnet
                if (((byAdamIP[0] & bySubnet[0]) == (byLocalIP[0] & bySubnet[0])) &&
                    ((byAdamIP[1] & bySubnet[1]) == (byLocalIP[1] & bySubnet[1])) &&
                    ((byAdamIP[2] & bySubnet[2]) == (byLocalIP[2] & bySubnet[2])) &&
                    ((byAdamIP[3] & bySubnet[3]) == (byLocalIP[3] & bySubnet[3])))
                {
                    break;
                }
            }
            lanNode = tcpNode.Nodes[iIdx];
            tcpTree.BeginUpdate();
            moduleNode = new TreeNode(ipStr + "-[" + adamObject.DeviceName + "]");
            byTemp     = adamObject.DeviceID;
            if ((byTemp[0] == 0x36) || (byTemp[0] == 0x50)) // 5000 TCP
            {
                moduleNode.ImageIndex         = 1;
                moduleNode.SelectedImageIndex = 2;
            }
            else
            {
                moduleNode.ImageIndex         = 3;
                moduleNode.SelectedImageIndex = 4;
            }
            moduleNode.Tag = i_iIndex; // remember the ADAM index in ArrayList
            lanNode.Nodes.Add(moduleNode);
            lanNode.Expand();
            tcpTree.EndUpdate();
        }
Exemple #6
0
        private bool IsValidIdle(string i_szIdleTime, ref AdamInformation adamObject)
        {
            int i_iIdleTime;

            if (i_szIdleTime.Length > 0)
            {
                i_iIdleTime = Convert.ToInt32(i_szIdleTime);
                if (adamObject.HardwareType[1] == 1 && i_iIdleTime >= 2 && i_iIdleTime <= 4095) // ODM ADAM-6066
                {
                    adamObject.HostIdleTime = i_iIdleTime;
                    return(true);
                }
                else if (adamObject.HardwareType[1] == 2 && adamObject.HardwareType[0] == 0 && i_iIdleTime >= 10 && i_iIdleTime <= 255) // ADAM-6000W
                {
                    adamObject.HostIdleTime = i_iIdleTime;
                    return(true);
                }
                else if (adamObject.HardwareType[1] == 2 && adamObject.HardwareType[0] == 0x41 && i_iIdleTime >= 0 && i_iIdleTime <= 4095) // WISE
                {
                    adamObject.HostIdleTime = i_iIdleTime;
                    return(true);
                }
                else if (adamObject.HardwareType[1] == 100 && i_iIdleTime >= 2 && i_iIdleTime <= 4095) //[Tim] ADAM-6000
                {
                    adamObject.HostIdleTime = i_iIdleTime;
                    return(true);
                }
                else if (adamObject.HardwareType[1] == 0x42 && i_iIdleTime >= 2 && i_iIdleTime <= 4095) // ADAM-6200
                {
                    adamObject.HostIdleTime = i_iIdleTime;
                    return(true);
                }
                else if (i_iIdleTime >= 5 && i_iIdleTime <= 4095) //Others
                {
                    adamObject.HostIdleTime = i_iIdleTime;
                    return(true);
                }
            }
            return(false);
        }
Exemple #7
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            int             iIndex;
            int             iCount = 0;
            AdamInformation adamObject;

            string[] szLocalIPs;
            adamList = new ArrayList();

            Cursor.Current = Cursors.WaitCursor;
            ClearNodes();

            if (AdamSocket.GetLocalNetwork(out szLocalIPs))
            {
                foreach (string szLocalIP in szLocalIPs)
                {
                    ArrayList adamCarryList;
                    AdamSocket.GetAdamDeviceList(m_iTimeout, szLocalIP, out adamCarryList);

                    if (adamCarryList.Count > 0)
                    {
                        for (iIndex = 0; iIndex < adamCarryList.Count; iIndex++)
                        {
                            adamObject = new AdamInformation();
                            adamObject = (AdamInformation)adamCarryList[iIndex];

                            if (adamList.Contains(adamObject) == false)
                            {
                                adamList.Add(adamObject); //Add Device to list
                                InsertNode(iCount, adamObject);
                                iCount = iCount + 1;
                            }
                        }
                    }
                }
            }

            Cursor.Current = Cursors.Default;
        }
Exemple #8
0
        /// <summary>
        /// Init APAX controller information
        /// </summary>
        /// <returns></returns>
        public bool RefreshConfiguration()
        {
            //Query device information and network informations
            if (AdamSocket.GetAdamDeviceList("255.255.255.255", 2000, out m_adamList_Group))
            {
                for (int i = 0; i < m_adamList_Group.Count; i++)
                {
                    m_adamObject = (AdamInformation)m_adamList_Group[i];
                    string tmpIP = string.Format("{0}.{1}.{2}.{3}", m_adamObject.IP[0], m_adamObject.IP[1], m_adamObject.IP[2], m_adamObject.IP[3]);
                    if (string.Compare(m_szIP, tmpIP) == 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("Get module information failed!", "Error");
                return(true);
            }
            //APAX Coupler Information
            this.labModuleName.Text = "APAX-PAC";
            this.txtFwVer.Text      = string.Format("{0:X2}.{1:X2}", m_adamObject.FwVer[0], m_adamObject.FwVer[1]); //Firmware Version
            if (m_sDSPFWVer != "")
            {
                this.txtFwVer2.Text = m_sDSPFWVer.Substring(0, 4).Insert(2, ".");                               //Kernel Firmware Version
            }
            if (adamType == AdamType.Apax5070)
            {
                if (m_adamModbusSocket.Connect(adamType, m_szIP, ProtocolType.Udp)) //FPGA Firmware Version (Should use udp to get FPGA version)
                {
                    uint o_dwVer;
                    if (m_adamModbusSocket.Configuration().GetFpgaVersion(out o_dwVer))
                    {
                        this.txtFpgaFwVer.Text = o_dwVer.ToString("X4").Insert(2, ".");
                    }
                }

                if ((Array.IndexOf(m_szSlotInfo, APAX_5090_STR) == -1) || (m_adamObject.HardwareType[0] == 0x01 && m_adamObject.HardwareType[1] == 0x01))
                {
                    if (tabControl1.TabPages.Contains(tabSerial))
                    {
                        tabControl1.TabPages.RemoveAt(tabControl1.TabPages.Count - 1);
                    }
                }
                else
                {
                    if (!tabControl1.TabPages.Contains(tabSerial))
                    {
                        tabControl1.TabPages.Add(tabSerial);
                    }

                    m_listIndexOfApax5090 = new List <int>();

                    for (int idx = 0; idx < m_szSlotInfo.Length; idx++)
                    {
                        if ((m_szSlotInfo[idx] != null) && (m_szSlotInfo[idx].IndexOf(APAX_5090_STR) > -1))
                        {
                            m_listIndexOfApax5090.Add(idx);
                        }
                    }
                    m_iApax5090TcpPorVals = new int[AdamControl.APAX_MaxSlot][];
                    RefreshSerialModulesComPortSetting();
                }
            }
            else
            {
                if (m_adamModbusSocket.Connect(m_szIP, ProtocolType.Udp, portNum)) //FPGA Firmware Version (Should use udp to get FPGA version)
                {
                    uint o_dwVer;
                    if (m_adamModbusSocket.Configuration().GetFpgaVersion(out o_dwVer))
                    {
                        this.txtFpgaFwVer.Text = o_dwVer.ToString("X4").Insert(2, ".");
                    }
                }
            }
            m_adamModbusSocket.Disconnect();
            txtDeviceName.Text = m_adamObject.DeviceName;
            txtDeviceDesc.Text = m_adamObject.Description;
            RefreshCurrentModuleInfo();                                                           //Current modules information
            //Network information
            txtMacAddress.Text = string.Format("{0:X02}-{1:X02}-{2:X02}-{3:X02}-{4:X02}-{5:X02}", //MAC address
                                               m_adamObject.Mac[0], m_adamObject.Mac[1],
                                               m_adamObject.Mac[2], m_adamObject.Mac[3],
                                               m_adamObject.Mac[4], m_adamObject.Mac[5]);
            txtIPAddress.Text = string.Format("{0}.{1}.{2}.{3}",      //IP address
                                              m_adamObject.IP[0], m_adamObject.IP[1], m_adamObject.IP[2], m_adamObject.IP[3]);
            txtSubnetAddress.Text = string.Format("{0}.{1}.{2}.{3}",  //subnet mask
                                                  m_adamObject.Subnet[0], m_adamObject.Subnet[1], m_adamObject.Subnet[2], m_adamObject.Subnet[3]);
            txtDefaultGateway.Text = string.Format("{0}.{1}.{2}.{3}", //default gateway
                                                   m_adamObject.Gateway[0], m_adamObject.Gateway[1], m_adamObject.Gateway[2], m_adamObject.Gateway[3]);
            numHostIdle.Text = m_adamObject.HostIdleTime.ToString();

            // Refresh Modbus address mapping
            RefreshModbusAddressSetting();
            // Refresh FSV settings
            RefreshFSVSettingInfo();

            return(true);
        }
Exemple #9
0
        public static bool SetAdamInformationEx(AdamInfoType i_infoType, int i_iTimeout, AdamInformation i_adamObject)
        {
            string[] szLocalIPs;
            bool     bRet = false;

            if (AdamSocket.GetLocalNetwork(out szLocalIPs))
            {
                foreach (string szLocalIP in szLocalIPs)
                {
                    if (AdamSocket.SetAdamInformation(i_infoType, i_iTimeout, i_adamObject, szLocalIP))
                    {
                        bRet = true;
                        break;
                    }
                }
            }

            return(bRet);
        }
Exemple #10
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);
        }