コード例 #1
0
        //工件计数
        private static long GetMacro(string deviceAddress, short num, out string error)
        {
            error = "";
            Focas1.IODBMR macror = new Focas1.IODBMR();
            ushort        m_handle;
            short         nRet       = Focas1.cnc_allclibhndl3(deviceAddress, 8193, 2, out m_handle);
            short         s_number   = num;
            short         e_number   = num;
            short         length     = 100;
            long          MacroValue = 0;

            if (nRet == Focas1.EW_OK)
            {
                nRet = Focas1.cnc_rdmacror(m_handle, s_number, e_number, length, macror);
            }

            if (nRet == Focas1.EW_OK)
            {
                MacroValue = macror.data.data1.mcr_val;
                for (int i = 0; i < macror.data.data1.dec_val; i++)
                {
                    MacroValue = MacroValue / 10;
                }

                Focas1.cnc_freelibhndl(m_handle); //释放连接
                return(MacroValue);
            }

            error = "连接失败";
            return(0);
        }
コード例 #2
0
        //工件计数  num = 3901 工件数   3902 总工件数
        private long GetMacro(ushort handle, short num, out string error)
        {
            error = "";
            Focas1.IODBMR macror   = new Focas1.IODBMR();
            short         s_number = num;
            short         e_number = num;
            short         length   = 100;

            long  MacroValue = 0;
            short nRet       = Focas1.cnc_rdmacror(handle, s_number, e_number, length, macror);

            //short nRet2 = Focas1.cnc_rdparam(handle, 6712, -1, 4 + Focas1.MAX_AXIS, Param);

            if (nRet == Focas1.EW_OK)
            {
                MacroValue = macror.data.data1.mcr_val;
                for (int i = 0; i < macror.data.data1.dec_val; i++)
                {
                    MacroValue = MacroValue / 10;
                }
            }

            if ((MacroValue == 0) && (num == 3902))
            {
                //方法二工件总数
                Focas1.IODBPSD_1 Param = new Focas1.IODBPSD_1();
                nRet = Focas1.cnc_rdparam(handle, 6712, -1, 4 + Focas1.MAX_AXIS, Param);
                if (nRet == Focas1.EW_OK)
                {
                    MacroValue = Param.ldata;
                }
            }

            if (nRet != Focas1.EW_OK)
            {
                error = $"读取错误!错误代号[{nRet}]";
            }

            return(MacroValue);
        }