Example #1
0
        private void bt_Click_Setting(object sender, RoutedEventArgs e)
        {
            CMotionAPI.COM_DEVICE comDevice = new CMotionAPI.COM_DEVICE();
            comDevice.ComDeviceType = (UInt16)CMotionAPI.ApiDefs.COMDEVICETYPE_PCI_MODE;
            comDevice.PortNumber    = 1;
            comDevice.CpuNumber     = UInt16.Parse(CPU.Text);
            comDevice.NetworkNumber = 0;
            comDevice.StationNumber = 0;
            comDevice.UnitNumber    = 0;
            comDevice.IPAddress     = "";
            comDevice.Timeout       = 10000;

            r = CMotionAPI.ymcOpenController(ref comDevice, ref hController);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("打开控制器错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }

            r = CMotionAPI.ymcSetAPITimeoutValue(10000);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("设置超时错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }
        }
Example #2
0
 private void bt_Click_Exit(object sender, RoutedEventArgs e)
 {
     r = CMotionAPI.ymcCloseController(hController);
     if (r != CMotionAPI.MP_SUCCESS)
     {
         MessageBox.Show(String.Format("关闭控制器错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
         return;
     }
     this.Close();
 }
Example #3
0
        int GetRegisterData(int addr, EYMCDataType type, uint RegisterDataNumber, out Int16[] Reg_ShortData, out Int32[] Reg_LongData)
        {
            Debug.Assert(INPUT_ORIGIN <= addr && addr <= OUTPUT_END);
            Reg_ShortData = new Int16[RegisterDataNumber];
            Reg_LongData  = new Int32[RegisterDataNumber];
#if SIMULATION_IO
            return(SUCCESS);
#endif

            uint hDataHandle;
            int  iResult = GetRegisterDataHandle(addr, type, out hDataHandle);
            if (iResult != SUCCESS)
            {
                return(iResult);
            }

            UInt32 ReadDataNumber = 0;                 // Number of obtained registers
            //UInt32 RegisterDataNumber = 1;             // Number of read-in registers
            //Int16[] Reg_ShortData = new Int16[1];      // W or B size register data storage variable
            //Int32[] Reg_LongData = new Int32[1];       // L size register data storage variable
            uint rc;

            if (type == EYMCDataType.B || type == EYMCDataType.W)
            {
                rc = CMotionAPI.ymcGetRegisterData(hDataHandle, RegisterDataNumber, Reg_ShortData, ref ReadDataNumber);
            }
            else
            {
                rc = CMotionAPI.ymcGetRegisterData(hDataHandle, RegisterDataNumber, Reg_LongData, ref ReadDataNumber);
            }

            if (rc != CMotionAPI.MP_SUCCESS)
            {
                string str = $"Error ymcGetRegisterData MB \nErrorCode [ 0x{rc.ToString("X")} ]";
                WriteLog(str, ELogType.Debug, ELogWType.Error, true);
                return(GenerateErrorCode(ERR_YMC_FAIL_GET_DATA));
            }

            return(SUCCESS);
        }
Example #4
0
        private void bt_Click_Set(object sender, RoutedEventArgs e)
        {
            UInt32 hRegisterML01000 = 0x00000000;
            UInt32 hRegisterML01002 = 0x00000000;   //注意,L类型寄存器名只能为偶数!!

            UInt32[] dataML = new UInt32[1];

            r = CMotionAPI.ymcGetRegisterDataHandle("ML01000", ref hRegisterML01000);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("获取寄存器引用错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }

            r = CMotionAPI.ymcGetRegisterDataHandle("ML01002", ref hRegisterML01002);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("获取寄存器引用错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }

            dataML[0] = UInt32.Parse(S_ML01000.Text);

            r = CMotionAPI.ymcSetRegisterData(hRegisterML01000, 1, dataML);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("设置寄存器值错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }

            dataML[0] = UInt32.Parse(S_ML01002.Text);

            r = CMotionAPI.ymcSetRegisterData(hRegisterML01002, 1, dataML);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("设置寄存器值错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }
        }
Example #5
0
        private void bt_Click_Get(object sender, RoutedEventArgs e)
        {
            UInt32 hRegisterML01000 = 0x00000000;
            UInt32 hRegisterML01002 = 0x00000000;

            UInt32[] dataML          = new UInt32[1];
            UInt32   pReadDataNumber = 0;

            r = CMotionAPI.ymcGetRegisterDataHandle("ML01000", ref hRegisterML01000);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("获取寄存器引用错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }
            r = CMotionAPI.ymcGetRegisterDataHandle("ML01002", ref hRegisterML01002);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("获取寄存器引用错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }

            CMotionAPI.ymcGetRegisterData(hRegisterML01000, 1, dataML, ref pReadDataNumber);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("获取寄存器值错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }
            G_ML01000.Text = dataML[0].ToString();
            CMotionAPI.ymcGetRegisterData(hRegisterML01002, 1, dataML, ref pReadDataNumber);
            if (r != CMotionAPI.MP_SUCCESS)
            {
                MessageBox.Show(String.Format("获取寄存器值错误 \n错误码 [ 0x{0} ]", r.ToString("X")));
                return;
            }
            G_ML01002.Text = dataML[0].ToString();
        }
Example #6
0
        int GetRegisterDataHandle(int addr, EYMCDataType type, out uint hDataHandle)
        {
            Debug.Assert(INPUT_ORIGIN <= addr && addr <= OUTPUT_END);
            hDataHandle = 0;
#if SIMULATION_IO
            return(SUCCESS);
#endif

            string registerName;
            // register type
            if (addr < OUTPUT_ORIGIN)
            {
                registerName = EYMCRegisterType.I.ToString();
            }
            else
            {
                registerName = EYMCRegisterType.O.ToString();
            }

            // data type
            registerName += type.ToString();

            // address 계산 부분
            registerName += "0000";

            // get handle
            uint rc = CMotionAPI.ymcGetRegisterDataHandle(registerName, ref hDataHandle);
            if (rc != CMotionAPI.MP_SUCCESS)
            {
                string str = $"Error ymcGetRegisterDataHandle ML \nErrorCode [ 0x{rc.ToString("X")} ]";
                WriteLog(str, ELogType.Debug, ELogWType.Error, true);
                return(GenerateErrorCode(ERR_YMC_FAIL_GET_DATA_HANDLE));
            }

            return(SUCCESS);
        }