示例#1
0
        /// <summary>
        /// currently only supports max 10 macro location read at a time
        /// </summary>
        /// <param name="startLoc"></param>
        /// <param name="EndLoc"></param>
        /// <returns>List of macro values</returns>
        public static List <int> ReadMacroRange(ushort handle, short startLoc, short EndLoc)
        {
            List <int> values = new List <int>();

            FocasLibBase.IODBMR odbmr = new FocasLibBase.IODBMR();
            //int ret = FocasLib.cnc_rdmacroRange(711, 720, 8 + (8 * 10), odbmr);
            int ret = FocasLib.cnc_rdmacror(handle, startLoc, EndLoc, 8 + (8 * 14), odbmr);

            if (ret == 0)
            {
                values.Add(GetMacroValue(odbmr.data.data1));
                values.Add(GetMacroValue(odbmr.data.data2));
                values.Add(GetMacroValue(odbmr.data.data3));
                values.Add(GetMacroValue(odbmr.data.data4));
                values.Add(GetMacroValue(odbmr.data.data5));
                values.Add(GetMacroValue(odbmr.data.data6));
                values.Add(GetMacroValue(odbmr.data.data7));
                values.Add(GetMacroValue(odbmr.data.data8));
                values.Add(GetMacroValue(odbmr.data.data9));
                values.Add(GetMacroValue(odbmr.data.data10));
                values.Add(GetMacroValue(odbmr.data.data11));
                values.Add(GetMacroValue(odbmr.data.data12));
                values.Add(GetMacroValue(odbmr.data.data13));
                values.Add(GetMacroValue(odbmr.data.data14));
            }
            else
            {
                Logger.WriteErrorLog("cnc_rdmacror() failed. return value is = " + ret);
            }
            return(values);
        }
示例#2
0
        public static short WriteMacro(ushort handle, short macroLocation, decimal value)
        {
            short decimalPlaces = BitConverter.GetBytes(decimal.GetBits(value)[3])[2];
            short intValue      = Convert.ToInt16(value * (decimal)Math.Pow(10, decimalPlaces));

            return(FocasLib.cnc_wrmacro(handle, macroLocation, 10, intValue, decimalPlaces));
        }
示例#3
0
        public static int ReadServoMotorTemp(ushort handle, short axisNo)
        {
            FocasLibBase.ODBDGN_1 obj = new FocasLibBase.ODBDGN_1();
            short ret = FocasLib.cnc_diagnoss(handle, 308, axisNo, 8, obj);//temp spindle motor 408

            return(obj.ldata);
        }
示例#4
0
        public static AlarmHistoryDTO ReadCurrentAlarm(ushort handle)
        {
            int             ret         = 0;
            AlarmHistoryDTO latestAlarm = new AlarmHistoryDTO();

            try
            {
                ret = FocasLib.cnc_stopophis(handle);

                ushort totalAlarms        = 0;
                FocasLibBase.ODBAHIS5 obj = new FocasLibBase.ODBAHIS5();
                ret = FocasLib.cnc_rdalmhisno(handle, out totalAlarms);

                ret = FocasLib.cnc_rdalmhistry5(handle, totalAlarms, totalAlarms, (ushort)Marshal.SizeOf(obj), obj);
                if (ret == 0 && obj != null)
                {
                    latestAlarm.AlarmNo      = obj.alm_his.data1.alm_no;
                    latestAlarm.AlarmGroupNo = obj.alm_his.data1.alm_grp;
                    latestAlarm.AlarmMessage = obj.alm_his.data1.alm_msg;
                    latestAlarm.AlarmTime    = Utility.ConvertToDate(obj.alm_his.data1);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                ret = FocasLib.cnc_startophis(handle);
            }
            return(latestAlarm);
        }
        public static void GetCoolantLubricantLevel(ushort handle, ushort startingLocation, ushort endLocation, out short coolentLevel, out short lubOilLevel)
        {
            /*
             *  R0200,..,R0209(It is assumed the byte type) is read.
             *  adr_type 5
             *  data_type 0
             *  s_number 200
             *  e_number 209
             *  length 8+1×10 (=18)
             *  buf.u.cdata[0]
             *   ,..,buf.u.cdata[9] The contents of R0200,..,R0209 are stored.
             * FWLIBAPI short WINAPI pmc_rdpmcrng(unsigned short FlibHndl, short adr_type, short data_type, short s_number, short e_number, short length, IODBPMC *buf);
             */
            FocasLibBase.IODBPMC1 f = new FocasLibBase.IODBPMC1();
            short ret = short.MinValue;

            coolentLevel = 0;
            lubOilLevel  = 0;
            ret          = FocasLib.pmc_rdpmcrng(handle, 5, 0, startingLocation, endLocation, (8 + 2 * 2), f);
            if (ret != 0)
            {
                ret = FocasLib.pmc_rdpmcrng(handle, 5, 0, 662, 665, (8 + 2 * 2), f);
                Logger.WriteErrorLog("pmc_rdpmcrng() failed. return value is = " + ret);
                return;
            }
            coolentLevel = f.idata[1];
            lubOilLevel  = f.idata[0];
            // return "Coolent = " + ((f.idata[0] / 4095.0 ) * 100.0).ToString();
        }
示例#6
0
 public static string ReadMachineStatus(ushort handle)
 {
     Utility.CncMachineState _cncMachineState = Utility.CncMachineState.Unknown;
     FocasLibBase.ODBST      a = new FocasLibBase.ODBST();
     FocasLib.cnc_statinfo(handle, a);
     return(Utility.GetMachineStatus(out _cncMachineState, a));
 }
 public static string GetTPMTrakFlagStatus(ushort handle)
 {
     FocasLibBase.IODBPMC0 f = new FocasLibBase.IODBPMC0();
     FocasLib.pmc_rdpmcrng(handle, 5, 0, 600, 600, 9, f);
     //Use the  first byte f.cdata[0] to check the pm trak flag on CNC machine and update it
     return(f.cdata[0].ToString());
 }
示例#8
0
        public static int ReadSpindleSpeed(ushort handle)
        {
            FocasLibBase.ODBACT obj = new FocasLibBase.ODBACT();
            short ret = FocasLib.cnc_acts(handle, obj);

            return(obj.data);
        }
示例#9
0
        public static int ReadServoMotorTempY2(ushort handle)
        {
            FocasLibBase.ODBDGN_1 obj1 = new FocasLibBase.ODBDGN_1();
            short ret = FocasLib.cnc_diagnoss(handle, 403, 2, 8, obj1);//temp spindle motor 403

            return(obj1.ldata);
        }
示例#10
0
        public static short ReadSpindleLoad(ushort handle)
        {
            FocasLibBase.ODBDGN_1 obj = new FocasLibBase.ODBDGN_1();
            short ret = FocasLib.cnc_diagnoss(handle, 410, 1, 8, obj);

            return(obj.idata);
        }
        public static ProgramDTO ReadOneProgram(ushort focasLibHandle, int progromToRead, short programDetailType = 1)
        {
            ProgramDTO program       = new ProgramDTO();
            int        topProgram    = progromToRead;
            short      prgromsToRead = 1;
            short      ret           = 0;

            ret = 0;
            FocasLibBase.PRGDIR3 d = new FocasLibBase.PRGDIR3();
            try
            {
                ret = FocasLib.cnc_rdprogdir3(focasLibHandle, programDetailType, ref topProgram, ref prgromsToRead, d);

                if (ret != 0)
                {
                    Logger.WriteErrorLog("cnc_rdprogdir3() failed. return value is = " + ret);
                }
                else
                {
                    if (prgromsToRead > 0)
                    {
                        if (topProgram == progromToRead)
                        {
                            program.ProgramNo = d.dir1.number;
                            program.Comment   = d.dir1.comment;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(ex.ToString());
            }
            return(program);
        }
示例#12
0
        public static FocasLibBase.ODBDY2_1 cnc_rddynamic2(ushort handle)
        {
            FocasLibBase.ODBDY2_1 obj = new FocasLibBase.ODBDY2_1();
            int ret = FocasLib.cnc_rddynamic2(handle, 4, 540, obj);

            return(obj);
        }
示例#13
0
        public static int ReadSpindleMotorTemp(ushort handle)
        {
            FocasLibBase.ODBDGN_1 obj = new FocasLibBase.ODBDGN_1();
            short ret = FocasLib.cnc_diagnoss(handle, 403, 1, 8, obj);//temp spindle motor 408

            return(obj.ldata);
        }
        public static string GetRapidTraverseOverride(ushort handle)
        {
            string str = string.Empty;

            FocasLibBase.IODBPMC0 f        = new FocasLibBase.IODBPMC0();
            FocasLibBase.IODBPMC0 iodbpmc2 = new FocasLibBase.IODBPMC0();
            FocasLib.pmc_rdpmcrng(handle, 0, 0, 14, 15, 10, f);         //pmc_rdpmcrng(0, 0, 14, 15, 10, f);
            FocasLib.pmc_rdpmcrng(handle, 0, 0, 96, 103, 16, iodbpmc2); //pmc_rdpmcrng(0, 0, 0x60, 0x67, 0x10, iodbpmc2);
            if ((iodbpmc2.cdata[0] & 128) == 128)
            {
                return(iodbpmc2.cdata[0].ToString());
            }
            switch (f.cdata[0])
            {
            case 0:
                return("100%");

            case 1:
                return("50%");

            case 2:
                return("25%");

            case 3:
                return("Slow");
            }
            return(str);
        }
        public static double ReadModalA(ushort handle)
        {
            double prograamdFeedRate = 0;

            FocasLibBase.ODBMDL_4 para = new FocasLibBase.ODBMDL_4();
            short ret = FocasLib.cnc_modal(handle, -2, 0, para);

            if (ret == 0)
            {
                var feed  = para.raux1.data4.aux_data;
                var flag1 = para.raux1.data4.flag1;
                var flag2 = para.raux1.data4.flag2;

                double num = ((double)(flag2 & 7));
                if (num == 0.0)
                {
                    return(feed);
                }
                else
                {
                    prograamdFeedRate = (double)feed / Math.Pow(10.0, num);
                }
                //partsCount = para.ldata;
            }
            else
            {
                // Logger.WriteErrorLog(string.Format("Parameter : {0} - cnc_rdparam() failed. return value is = {1}", parameter, ret));
            }
            return(prograamdFeedRate);
        }
示例#16
0
        public static int ReadSpindleAxisSpeed(ushort handle)
        {
            int   a   = 0;
            short ret = FocasLib.cnc_rdsrvspeed(handle, out a);

            return(a);
        }
示例#17
0
 /// <summary>
 /// Get Active and Main program No
 /// </summary>
 /// <param name="Main Program"></param>
 /// <returns>ActiveProgramNo</returns>
 public static short ReadActiveMainProgramNo(ushort handle, out short mainProgram)
 {
     FocasLibBase.ODBPRO odbpro = new FocasLibBase.ODBPRO();
     FocasLib.cnc_rdprgnum(handle, odbpro);
     mainProgram = odbpro.mdata;
     return(odbpro.data);
 }
示例#18
0
        /// <summary>
        /// ReadServo Load and Current Details on All axis
        /// </summary>
        /// <param name="current">Current in Amp</param>
        /// <returns>Servo Load</returns>
        public static string ReadServoLoadCurrentDetails(ushort handle, out string current)
        {
            current = string.Empty;
            string buff = "";
            //string sb = "";
            string DL = "#";

            short[] types = { 0, 1, 2 };

            /*
             * cls = 2 (Servo)
             * type = 0 : Servo load meter
             *      1 : Load current (% unit)
             *      2 : Load current (Ampere unit)
             */

            short MAX_AXIS = FocasLibBase.MAX_AXIS;
            short len      = MAX_AXIS;

            FocasLibBase.ODBAXDT odbaxdt = new FocasLibBase.ODBAXDT();

            List <string> pos = new List <string>();
            //1st parameter - Position(=1), Servo(=2), Spindle(=3)
            //4th parameter - After execution, "(*len)" will have the actual number of axes.
            short ret = FocasLib.cnc_rdaxisdata(handle, 2, types, (short)types.Length, ref len, odbaxdt);

            if (ret == 0)
            {
                MAX_AXIS = len;
                get_actual_axis_value(odbaxdt, ref pos, len, types.Length);

                int i;
                //Servo load meter
                for (i = 0 * MAX_AXIS; i < 0 * MAX_AXIS + len; i++)
                {
                    buff += pos[i];
                    buff += ",";
                }
                buff += DL;

                // Load current (% unit)
                for (i = 1 * MAX_AXIS; i < 1 * MAX_AXIS + len; i++)
                {
                    buff += pos[i];
                    buff += ",";
                }
                buff += DL;

                //Load current (Ampere unit)
                for (i = 2 * MAX_AXIS; i < 2 * MAX_AXIS + len; i++)
                {
                    buff    += pos[i];
                    buff    += ",";
                    current += pos[i];
                    current += ",";
                }
            }
            return(buff);
        }
示例#19
0
        public static int ReadAxixServoMotorTempX(ushort handle)
        {
            FocasLibBase.ODBDGN_1 obj = new FocasLibBase.ODBDGN_1();
            short ret = FocasLib.cnc_diagnoss(handle, 308, 1, 8, obj);//temp spindle motor 308

            Debug.WriteLine("AXIS X temp=" + obj.ldata);
            return(obj.ldata);
        }
        public static List <byte> ReadPMCDataTableChar(ushort handle, ushort startingAddress, ushort endingAddress)
        {
            FocasLibBase.IODBPMC0 f = new FocasLibBase.IODBPMC0();
            FocasLib.pmc_rdpmcrng(handle, 9, 1, startingAddress, endingAddress, 8 + (10 * 1), f);
            string str = string.Empty;

            return(f.cdata.ToList());
        }
        public static string ReadFullProgramPathRunningProgram(ushort handle)
        {
            char[]        buf = new char[256 + 1];
            short         ret = FocasLib.cnc_pdf_rdmain(handle, buf);
            StringBuilder str = new StringBuilder();

            str.Append(buf);
            return(str.ToString().Trim('\0'));
        }
 // (unsigned short FlibHndl, short adr_type, short data_type, unsigned short s_number, unsigned short e_number, unsigned short length, IODBPMC *buf)
 public static List <byte> ReadPMCRangeByte(ushort handle, short addType, ushort startingAddress, ushort endingAddress, out int ret)
 {
     //3 = X adr_type , 2 = Y adr_type
     //data_type byte = 0
     //pmc_rdpmcrng(unsigned short FlibHndl, short adr_type, short data_type, short s_number, short e_number, short length, IODBPMC *buf);
     FocasLibBase.IODBPMC0 f = new FocasLibBase.IODBPMC0();
     ret = FocasLib.pmc_rdpmcrng(handle, addType, 0, startingAddress, endingAddress, (ushort)(8 + (endingAddress - startingAddress) + 1), f);
     //if (ret != 0) throw new DivideByZeroException();
     return(f.cdata.ToList <byte>());
 }
        //Read PMC alarm messages
        public static List <string> ReadPMCAlarmMessage(ushort handle)
        {
            List <string> msgs = new List <string>();

            FocasLibBase.ODBPMCALM message = new FocasLibBase.ODBPMCALM();
            short recordsExists            = 0;
            short s_number = 1;
            short read_num = 10;
            int   ret      = FocasLib.pmc_rdalmmsg(handle, s_number, ref read_num, out recordsExists, message);

            if (ret == 0)
            {
                if (message.msg1.almmsg != string.Empty)
                {
                    msgs.Add(message.msg1.almmsg);
                }
                if (message.msg2.almmsg != string.Empty)
                {
                    msgs.Add(message.msg2.almmsg);
                }
                if (message.msg3.almmsg != string.Empty)
                {
                    msgs.Add(message.msg3.almmsg);
                }
                if (message.msg4.almmsg != string.Empty)
                {
                    msgs.Add(message.msg4.almmsg);
                }
                if (message.msg5.almmsg != string.Empty)
                {
                    msgs.Add(message.msg5.almmsg);
                }
                if (message.msg6.almmsg != string.Empty)
                {
                    msgs.Add(message.msg6.almmsg);
                }
                if (message.msg7.almmsg != string.Empty)
                {
                    msgs.Add(message.msg7.almmsg);
                }
                if (message.msg8.almmsg != string.Empty)
                {
                    msgs.Add(message.msg8.almmsg);
                }
                if (message.msg9.almmsg != string.Empty)
                {
                    msgs.Add(message.msg9.almmsg);
                }
                if (message.msg10.almmsg != string.Empty)
                {
                    msgs.Add(message.msg10.almmsg);
                }
            }
            return(msgs);
        }
        public static short ReadPMCOneWord(ushort handle, short addType, ushort startingAddress, ushort endingAddress)
        {
            //3 = X adr_type , 2 = Y adr_type
            //data_type byte = 0
            //pmc_rdpmcrng(unsigned short FlibHndl, short adr_type, short data_type, short s_number, short e_number, short length, IODBPMC *buf);
            FocasLibBase.IODBPMC1 f = new FocasLibBase.IODBPMC1();
            int ret = FocasLib.pmc_rdpmcrng(handle, addType, 1, startingAddress, endingAddress, (ushort)(8 + (endingAddress - startingAddress) * 2), f);

            //if (ret != 0) throw new DivideByZeroException();
            return(f.idata[0]);
        }
示例#25
0
        public static List <LiveAlarm> ReadLiveAlarms(ushort handle)
        {
            List <LiveAlarm> alarms = new List <LiveAlarm>();

            FocasLibBase.ODBALMMSG obj = new FocasLibBase.ODBALMMSG();
            short num = 10;
            short ret = FocasLib.cnc_rdalmmsg(handle, -1, ref num, obj);

            if (ret == 0)
            {
                if (obj.msg1.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg1));
                }
                if (obj.msg2.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg2));
                }
                if (obj.msg3.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg3));
                }
                if (obj.msg4.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg4));
                }
                if (obj.msg5.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg5));
                }
                if (obj.msg6.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg6));
                }
                if (obj.msg7.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg7));
                }
                if (obj.msg8.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg8));
                }
                if (obj.msg9.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg9));
                }
                if (obj.msg10.alm_no > 0)
                {
                    alarms.Add(AssignLiveAlarm(obj.msg10));
                }
            }
            return(alarms);
        }
        public static void GetPredictiveMaintenanceTargetCurrent(ushort handle, ushort startingLocation, ushort endLocation, out int targetValue, out int currentValue, string MTB = "ACE")
        {
            /*
             *  R0200,..,R0209(It is assumed the byte type) is read.
             *  adr_type 5
             *  data_type 0
             *  s_number 200
             *  e_number 209
             *  length 8+1×10 (=18)
             *  buf.u.cdata[0]
             *   ,..,buf.u.cdata[9] The contents of R0200,..,R0209 are stored.
             * FWLIBAPI short WINAPI pmc_rdpmcrng(unsigned short FlibHndl, short adr_type, short data_type, short s_number, short e_number, short length, IODBPMC *buf);
             */
            FocasLibBase.IODBPMC1 f = new FocasLibBase.IODBPMC1();
            short ret = short.MinValue;

            targetValue  = int.MaxValue;
            currentValue = int.MaxValue;

            if (MTB.Equals("ACE", StringComparison.OrdinalIgnoreCase))
            {
                ret = FocasLib.pmc_rdpmcrng(handle, 9, 1, startingLocation, endLocation, (8 + 2 * 2), f);
                if (ret != 0)
                {
                    Logger.WriteErrorLog(string.Format("pmc_rdpmcrng() failed. return value is = {0} . Read D parameters {1} - {2}", ret, startingLocation, endLocation));
                    return;
                }
                targetValue  = f.idata[0];
                currentValue = f.idata[1];
            }
            else if (MTB.Equals("AMS", StringComparison.OrdinalIgnoreCase))
            {
                ushort tempEndLocation = (ushort)(startingLocation + 2);
                ret = FocasLib.pmc_rdpmcrng(handle, 9, 1, startingLocation, tempEndLocation, (8 + 2 * 2), f);
                if (ret != 0)
                {
                    Logger.WriteErrorLog(string.Format("pmc_rdpmcrng() failed. return value is = {1} . read D parameter {0}  ", startingLocation, ret));
                    return;
                }
                targetValue = f.idata[0];

                tempEndLocation = (ushort)(endLocation + 2);
                ret             = FocasLib.pmc_rdpmcrng(handle, 9, 1, endLocation, tempEndLocation, (8 + 2 * 2), f);
                if (ret != 0)
                {
                    Logger.WriteErrorLog(string.Format("pmc_rdpmcrng() failed. return value is = {1} . read D parameter {0}  ", endLocation, ret));
                    return;
                }
                currentValue = f.idata[0];
            }
        }
        public static string GetFeedrateOverride(ushort handle)
        {
            FocasLibBase.IODBPMC0 f = new FocasLibBase.IODBPMC0();
            FocasLib.pmc_rdpmcrng(handle, 1, 0, 3, 3, 9, f);
            if (f.cdata[0] < 8)
            {
                return("Manual Mode");
            }
            f = new FocasLibBase.IODBPMC0();
            FocasLib.pmc_rdpmcrng(handle, 0, 0, 12, 19, 16, f);
            int num = 0xff - f.cdata[0];

            return(num.ToString() + "%");
        }
 public static void WritePMCDataTableInt(ushort handle, ushort startingAddress, ushort endingAddress)
 {
     FocasLibBase.IODBPMC2 f = new FocasLibBase.IODBPMC2();
     f.ldata    = new int[10];
     f.type_a   = 9;
     f.type_d   = 1;
     f.datano_s = (short)startingAddress;
     f.datano_e = (short)endingAddress;
     for (int i = 0; i < 10; i++)
     {
         f.ldata[i] = 0;
     }
     var ret = FocasLib.pmc_wrpmcrng(handle, 8 + (20 * 2), f);
 }
 public static void WritePMCDataTableWord(ushort handle, ushort startingAddress, ushort endingAddress) // to write spindle load 0
 {
     FocasLibBase.IODBPMC1 f = new FocasLibBase.IODBPMC1();
     f.idata    = new short[10];
     f.type_a   = 9;
     f.type_d   = 1;
     f.datano_s = (short)startingAddress;
     f.datano_e = (short)endingAddress;
     for (int i = 0; i < 10; i++)
     {
         f.idata[i] = 0;
     }
     FocasLib.pmc_wrpmcrng(handle, 8 + (10 * 2), f);
 }
        public static void UpdateOperatinHistoryMacroLocation(string ipAddress, ushort portNo, short macroLocation, int value)
        {
            short  ret            = -20;
            ushort focasLibHandle = 0;

            ret = FocasLib.cnc_allclibhndl3(ipAddress, portNo, 10, out focasLibHandle);
            if (ret != 0)
            {
                Logger.WriteErrorLog("cnc_allclibhndl3() failed. return value is = " + ret);
                return;
            }
            FocasData.WriteMacro(focasLibHandle, macroLocation, value);
            FocasLib.cnc_freelibhndl(focasLibHandle);
        }