コード例 #1
0
        private void slaveModuleInitialize()
        {
            uint mask = 0x00000001;

            uint[] deviceTable = new uint[2];
            CCMNet.CS_mnet_reset_ring(RingNoOfMNet);
            I16 retOfGetTable = CCMNet.CS_mnet_get_ring_active_table(RingNoOfMNet, deviceTable);

            if (retOfGetTable != 0)
            {
                throw new Exception("Error occur when get device table !!! \n func = [_mnet_get_ring_active_table]");
            }
            if ((deviceTable[0] == 0) && (deviceTable[1] == 0))
            {
                throw new Exception("Can't find slave M1X1, there is not any device !!! \n func = [_mnet_get_ring_active_table, deviceTable=0]");
            }

            for (int i = 0; i < 64; i++)
            {
                if (axisPara.SlaveIP > 63)
                {
                    throw new Exception("Wrong SlaveIP, SlaveIP must less than 63!!!");
                }

                if (axisPara.SlaveIP == i)
                {
                    if (i < 32)
                    {
                        if ((deviceTable[0] & mask) == 0)
                        {
                            throw new Exception("Have not found M1X1 !!!\n" + "SlaveIP = " + axisPara.SlaveIP);
                        }
                    }
                    else
                    {
                        if (i == 32)
                        {
                            mask = 0x00000001;
                        }
                        if ((deviceTable[1] & mask) == 0)
                        {
                            throw new Exception("Have not found M1X1 !!!\n" + "SlaveIP = " + axisPara.SlaveIP);
                        }
                    }
                }
                mask = mask << 1;
            }

            I16 retOfStartRing = CCMNet.CS_mnet_start_ring(RingNoOfMNet);

            if (retOfStartRing != 0)
            {
                throw new Exception("Error occur when start ring !!! \n func = [_mnet_start_ring]");
            }

            U8  slaveType         = 0;
            I16 retOfGetSlaveType = CCMNet.CS_mnet_get_slave_type(RingNoOfMNet, axisPara.SlaveIP, ref slaveType);

            if (retOfGetSlaveType == 0)
            {
                if (slaveType != 0xA3)
                {
                    throw new Exception("deviec type is not M1X1!!!\n" + "SlaveIP = " + axisPara.SlaveIP);
                }
            }
            else
            {
                throw new Exception("Error occur when get device type !!! \n func = [_mnet_get_slave_type]");
            }

            I16 retOfInitial = CCMNet.CS_mnet_m1_initial(RingNoOfMNet, axisPara.SlaveIP);

            if (retOfInitial != 0)
            {
                throw new Exception("Error occur when M1X1 module initial !!! \n func = [_mnet_m1_initial]");
            }
        }