//扫描从站
        private void button1_Click(object sender, EventArgs e)
        {
            ethercat.getDevice();//然后就可以用ethercat.devices来进行操作了

            TreeNode rootNode = new TreeNode("Devices");

            treeView1.Nodes.Add(rootNode);
            TreeNode[] typeNode = new TreeNode[4];
            for (int i = 0; i < 4; i++)
            {
                typeNode[i] = new TreeNode(type[i]);
            }

            rootNode.Nodes.AddRange(typeNode);

            for (int i = 0; i < EtherCAT.devices.Length; i++)
            {
                IOdevice device    = EtherCAT.devices[i];
                TreeNode slave     = new TreeNode(device.name);
                int      slaveType = device.type;
                typeNode[slaveType - 1].Nodes.Add(slave);
                for (int channel = 0; channel < device.channelNum; channel++)
                {
                    TreeNode ch = new TreeNode("channel" + (channel + 1));
                    slave.Nodes.Add(ch);
                }
            }
        }
Esempio n. 2
0
        //将info中的list<list<>>变为TreeNode
        public TreeNode ListToTree(Config config)
        {
            List <List <IOdevice> > deviceList = config.DeviceInfo.DeviceList;

            TreeNode deviceTree = new TreeNode("DEVICE");

            int deviceNum = 0, channelNum = 0;

            foreach (List <IOdevice> deviceGroup in deviceList)
            {
                if (deviceGroup == null)
                {
                    break;
                }
                //For the first, we need to select coupler out.
                IOdevice coupler     = deviceGroup[0];
                TreeNode couplerNode = new TreeNode(coupler.name);
                channelNum += coupler.channelNum;   //If servo, neet to count channel.
                deviceNum  += deviceGroup.Count;    //add to deviceNum.
                for (int i = 1; i < deviceGroup.Count; i++)
                {
                    //For others, we need to add them to the coupler Node one-by-one.
                    IOdevice device     = deviceGroup[i];
                    TreeNode deviceNode = new TreeNode(device.name);
                    for (int channel = 0; channel < device.channelNum; channel++)
                    {
                        //For each channel, we add them auto-ly.
                        TreeNode ch = new TreeNode("Channel" + (channel + 1));
                        deviceNode.Nodes.Add(ch);
                    }
                    channelNum += device.channelNum;
                    couplerNode.Nodes.Add(deviceNode);
                }
                deviceTree.Nodes.Add(couplerNode);
            }

            /* TODO: Refresh deviceNum & channelNum. but if you haven't click scan_butten,
             * this will not work. So we should find solution to get these two params before
             * running.*/
            config.DeviceInfo.DeviceNum       = deviceNum;
            config.DeviceInfo.AllChannelCount = channelNum;

            return(deviceTree);
        }
Esempio n. 3
0
        public IOdevice[] getDevice()
        {
            int slaveNum = CppConnect.getSlaveNum();

            deviceNum = slaveNum;
            for (int i = 0; i < slaveNum; i++)
            {
                IOdevice tmpSlave = new IOdevice();
                int      err      = CppConnect.getSlaveInfo(ref tmpSlave, i);
                if (err == SAFECODE)
                {
                    devices[i] = tmpSlave;
                }
                else//有错误
                {
                    throw new Exception();
                }
            }
            return(devices);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取设备列表
        /// </summary>
        public List <List <IOdevice> > GetDevice()
        {
            BuildConnection();
            int slaveNum = ConnectionContext.deviceNum;

            List <List <IOdevice> > deviceContiner = new List <List <IOdevice> >(); //全部device
            List <IOdevice>         devGroup       = null;                          //一个device组
            IOdevice tmpDevice = null;

            for (int i = 1; i < slaveNum + 2; i++)
            {
                HtEcEntity    tmpSlave     = new HtEcEntity();
                StringBuilder tmpSlaveName = new StringBuilder();
                tmpSlaveName.Capacity = 128;

                int err = HtEcConnector.getSlaveInfo(tmpSlaveName, ref tmpSlave, i);

                if (tmpSlave.type == 10 || tmpSlave.type == 20) //耦合器或驱动器
                {
                    if (devGroup != null)
                    {
                        deviceContiner.Add(devGroup);
                    }
                    devGroup = new List <IOdevice>();
                }

                tmpDevice = new IOdevice(tmpSlave.id, DeviceType.NULL, tmpSlaveName.ToString(), tmpSlave.channelNum);
                //type
                switch (tmpSlave.type)
                {
                case 1:
                    tmpDevice.type = DeviceType.DI;
                    break;

                case 2:
                    tmpDevice.type = DeviceType.DO;
                    break;

                case 3:
                    tmpDevice.type = DeviceType.AI;
                    break;

                case 4:
                    tmpDevice.type = DeviceType.AO;
                    break;

                case 10:
                    tmpDevice.type = DeviceType.COUPLER;
                    break;

                case 20:
                    tmpDevice.type = DeviceType.SOLVER;
                    break;

                default:
                    break;
                }

                devGroup.Add(tmpDevice);
                tmpSlaveName.Clear();
            }
            deviceContiner.Add(devGroup);
            return(deviceContiner);
        }
Esempio n. 5
0
 public static extern int getSlaveInfo(ref IOdevice slaveInfo, int id);