Beispiel #1
0
 public bool OpenDevice()
 {
     m_adamSocket = new AdamSocket(m_adamType);
     m_adamSocket.SetTimeout(m_iTimeout[0], m_iTimeout[1], m_iTimeout[2]);
     if (m_adamSocket.Connect(m_szIP, protoType, portNum))
     {
         if (!m_adamSocket.Configuration().GetSlotInfo(out m_szSlots))
         {
             this.StatusBar_IO.Text = "GetSlotInfo() Failed! ";
             return(false);
         }
     }
     return(true);
 }
Beispiel #2
0
        /// <summary>
        /// Used for change I/O module
        /// </summary>
        /// <returns></returns>
        public bool FreeResource()
        {
            if (m_bStartFlag)
            {
                m_bStartFlag             = false;
                this.tabControl1.Enabled = false;
                this.tabControl1.Visible = false;
                timer1.Enabled           = false;

                m_adamSocket.Configuration().SYS_SetLocateModule(m_idxID, 0);
                m_adamSocket.Disconnect();
                m_adamSocket = null;
            }
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Refresh I/O modules of this controller and show controller information
        /// </summary>
        /// <param name="e"></param>
        private void AfterSelect_CouplerDevice(TreeNode e)
        {
            TreeNode adamNode;

            m_adamModbusSocket = new AdamSocket(adamType);
            m_adamModbusSocket.SetTimeout(m_iTimeout[0], m_iTimeout[1], m_iTimeout[2]);
            if (m_adamModbusSocket.Connect(m_szIP, protoType, portNum))
            {
                if (m_adamModbusSocket.RefreshIOInfo())
                {
                    Thread waitThread = new Thread(ShowWaitMsg);
                    waitThread.Start();
                    m_adamModbusSocket.Configuration().GetSlotInfo(out m_szSlotInfo);
                    //
                    treeView1.BeginUpdate();
                    e.Nodes.Clear();
                    for (int iCnt = 0; iCnt < m_szSlotInfo.Length; iCnt++)
                    {
                        if (m_szSlotInfo[iCnt] != null)
                        {
                            adamNode     = new TreeNode(m_szSlotInfo[iCnt] + "(S" + iCnt.ToString() + ")");
                            adamNode.Tag = (byte)iCnt;
                            e.Nodes.Add(adamNode);
                        }
                    }
                    e.ExpandAll();
                    treeView1.EndUpdate();
                    m_adamModbusSocket.GetDSPFWVer(ref m_sDSPFWVer);
                    m_adamModbusSocket.Disconnect();
                }
            }
            else
            {
                MessageBox.Show("Connection error ( Err : " + m_adamModbusSocket.LastError.ToString() + " ). Please check the network setting.", "Error");
                m_adamModbusSocket.Disconnect();
                m_adamModbusSocket = null;
                return;
            }

            RefreshConfiguration();
            m_adamModbusSocket = null;
        }
Beispiel #4
0
        private bool GetSerialComPortTcpPortMapping(int i_intSlotId, out int[] o_tcpPortMappingAry)
        {
            AdamSocket adamSocket = new AdamSocket(AdamType.Apax5070);
            bool       bRet       = false;

            o_tcpPortMappingAry = new int[4];

            if (adamSocket.Connect(m_szIP, ProtocolType.Udp, ASCII_CMD_UDP_PORT))
            {
                adamSocket.SetTimeout(m_iTimeout[0], m_iTimeout[1], m_iTimeout[2]);
                bRet = adamSocket.Configuration().GetModuleCOMTcpPortMapping(i_intSlotId, out o_tcpPortMappingAry);
            }
            else
            {
                //MessageBox.Show("Failed to connect module!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                bRet = false;
            }

            adamSocket.Disconnect();
            adamSocket = null;
            return(bRet);
        }
        public AdamRetriever(int sensorNum)
        {
            sensorStatus = "false";
            sensorNumber = sensorNum;
            m_bStart     = false;                    // the action stops at the beginning
            m_szIP       = "192.168.10.10";          // modbus slave IP address
            m_iPort      = 502;                      // modbus TCP port is 502
            adamModbus   = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP
            adamUDP = new AdamSocket();
            adamUDP.SetTimeout(1000, 1000, 1000);    // set timeout for UDP

            m_Adam6000Type = Adam6000Type.Adam6015;  // the sample is for ADAM-6015

            adamUDP.Connect(AdamType.Adam6000, m_szIP, ProtocolType.Udp);
            if (adamUDP.Configuration().GetFirmwareVer(out m_szFwVersion))
            {
                m_DeviceFwVer = int.Parse(m_szFwVersion.Trim().Substring(0, 1));
            }
            adamUDP.Disconnect();

            m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type);
            m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type);

            //txtModule.Text = m_Adam6000Type.ToString();
            m_bChEnabled = new bool[m_iAiTotal];

            //firmware version
            //fwversion.Text = m_DeviceFwVer.ToString();

            if (m_DeviceFwVer > m_Adam6000NewerFwVer)
            {
                m_usRange = new ushort[m_iAiTotal];
            }

            // start the retrieving datas and save to db;
            startRetrieving();
        }
Beispiel #6
0
 private void buttonStart_Click(object sender, EventArgs e)
 {
     if (m_bStart) // was started
     {
         panelDIO.Enabled = false;
         m_bStart         = false;
         timer1.Enabled   = false;
         adamSocket.Disconnect();
         buttonStart.Text = "Start";
     }
     else
     {
         adamSocket.SetTimeout(1000, 1000, 1000);
         if (adamSocket.Connect(m_szIP, ProtocolType.Udp, m_Port))
         {
             // *******************************************
             adamSocket.AdamSeriesType = AdamType.Adam4000; // you have to set this properity to make the command working properly
             // *******************************************
             m_iCount = 0;                                  // reset the reading counter
             // get module config
             if (!adamSocket.Configuration(m_iAddr).GetModuleConfig(out m_adamConfig))
             {
                 adamSocket.Disconnect();
                 MessageBox.Show("Failed to get module config!", "Error");
                 return;
             }
             //
             panelDIO.Enabled = true;
             timer1.Enabled   = true; // enable timer
             buttonStart.Text = "Stop";
             m_bStart         = true; // starting flag
         }
         else
         {
             MessageBox.Show("Failed to connect!", "Error");
         }
     }
 }
Beispiel #7
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);
        }
Beispiel #8
0
        private ushort[] m_usRange; //for newer version

        public Form1()
        {
            InitializeComponent();

            m_bStart   = false;                      // the action stops at the beginning
            m_szIP     = "172.18.3.222";             // modbus slave IP address
            m_iPort    = 502;                        // modbus TCP port is 502
            adamModbus = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP
            adamUDP = new AdamSocket();
            adamUDP.SetTimeout(1000, 1000, 1000);    // set timeout for UDP

            m_Adam6000Type = Adam6000Type.Adam6015;  // the sample is for ADAM-6015
            //m_Adam6000Type = Adam6000Type.Adam6017; // the sample is for ADAM-6017
            //m_Adam6000Type = Adam6000Type.Adam6018; // the sample is for ADAM-6018

            adamUDP.Connect(AdamType.Adam6000, m_szIP, ProtocolType.Udp);
            if (adamUDP.Configuration().GetFirmwareVer(out m_szFwVersion))
            {
                m_DeviceFwVer = int.Parse(m_szFwVersion.Trim().Substring(0, 1));
            }
            adamUDP.Disconnect();

            m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type);
            m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type);

            txtModule.Text = m_Adam6000Type.ToString();
            m_bChEnabled   = new bool[m_iAiTotal];

            if (m_DeviceFwVer < m_Adam6000NewerFwVer)
            {
                m_byRange = new byte[m_iAiTotal];
            }
            else
            {
                //for newer version Adam6017
                m_usRange = new ushort[m_iAiTotal];
            }

            // arrange channel text box

            if (m_Adam6000Type == Adam6000Type.Adam6015)
            {
                // Channel
                chkboxCh7.Visible   = false;
                txtAIValue7.Visible = false;
                // DO
                panelDO.Visible = false;
            }
            else if (m_Adam6000Type == Adam6000Type.Adam6017)
            {
                // DO
                btnCh2.Visible = false;
                txtCh2.Visible = false;
                btnCh3.Visible = false;
                txtCh3.Visible = false;
                btnCh4.Visible = false;
                txtCh4.Visible = false;
                btnCh5.Visible = false;
                txtCh5.Visible = false;
                btnCh6.Visible = false;
                txtCh6.Visible = false;
                btnCh7.Visible = false;
                txtCh7.Visible = false;
            }
            else  //Adam6018
            {
                ;
            }
        }