Exemple #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]");
            }
        }
Exemple #2
0
        private void masterCardInitialize()
        {
            //沒有實際測試過插上兩張L122或是多張MNet版卡
            U16 ringIdxOfMNet    = 8;
            U8  verOfHardware    = 0;
            I16 retOfGetHardware = CPCI_L122.CS_l122_get_hardware_info((U16)Parameter.CardSwitchNo, ref verOfHardware);

            if (retOfGetHardware != 0)
            {
                short lExistCards = 0;
                CPCI_L122.CS_l122_open(ref lExistCards);
                if (lExistCards == 0)
                {
                    throw new Exception("Can't find PCI_L122 !!! \n func = [_l122_open, lExistCards=0]");
                }

                I16 retOfSetRingCfg = CPCI_L122.CS_l122_set_ring_config((U16)Parameter.CardSwitchNo, (U16)Parameter.RingNoOfCard, 3);

                if (retOfSetRingCfg != 0)
                {
                    throw new Exception("Error occur when set ring config !!! \n func = [_l122_set_ring_config]");
                }
                else
                {
                    //取得122卡在MotionNet DLL的起始位置
                    I16 retOfStartRingNum = CPCI_L122.CS_l122_get_start_ring_num((U16)Parameter.CardSwitchNo, ref ringIdxOfMNet);
                    if (retOfStartRingNum == 0)
                    {
                        //MotionNet DLL最多支援8個串列埠
                        if ((ringIdxOfMNet + (U16)Parameter.RingNoOfCard) < 8)
                        {
                            RingNoOfMNet = (U16)(ringIdxOfMNet + (U16)Parameter.RingNoOfCard);
                            uint[] lDevTable = new uint[2];
                            if (DeviceTable == null)
                            {
                                CCMNet.CS_mnet_reset_ring(RingNoOfMNet);
                                short rc = CCMNet.CS_mnet_get_ring_active_table(RingNoOfMNet, lDevTable);
                                DeviceTable = lDevTable;
                                //Console.WriteLine("{0}, {1}", lDevTable[0], lDevTable[1]);
                            }
                            I16 rt = CCMNet.CS_mnet_start_ring(RingNoOfMNet);
                        }
                        else
                        {
                            throw new Exception("Wrong ring number of MotionNet !!! \n func = [_l122_get_start_ring_num] ");
                        }
                    }
                    else
                    {
                        throw new Exception("Error occur when get start ring number !!! \n func = [_l122_get_start_ring_num]");
                    }
                }
            }
            else
            {
                //取得122卡在MotionNet DLL的起始位置
                CPCI_L122.CS_l122_get_start_ring_num((U16)Parameter.CardSwitchNo, ref ringIdxOfMNet);

                //MotionNet DLL最多支援8個串列埠
                if ((ringIdxOfMNet + (U16)Parameter.RingNoOfCard) < 8)
                {
                    RingNoOfMNet = (U16)(ringIdxOfMNet + (U16)Parameter.RingNoOfCard);
                    uint[] lDevTable = new uint[2];
                    if (DeviceTable == null)
                    {
                        CCMNet.CS_mnet_reset_ring(RingNoOfMNet);
                        short rc = CCMNet.CS_mnet_get_ring_active_table(RingNoOfMNet, lDevTable);
                        DeviceTable = lDevTable;
                        Console.WriteLine("{0}, {1}", lDevTable[0], lDevTable[1]);
                    }
                    I16 rt = CCMNet.CS_mnet_start_ring(RingNoOfMNet);
                }
                else
                {
                    throw new Exception("Error occur when get hardware info!!! \n func = [_l122_get_hardware_info]");
                }
            }
        }