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();
        }
        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]);
        }
        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 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 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();
            short ret = FocasLib.pmc_rdpmcrng(handle, addType, 1, startingAddress, endingAddress, (ushort)(8 + ((endingAddress - startingAddress)) * 2), f);

            if (ret != 0)
            {
                return(short.MinValue);
            }
            return(f.idata[0]);
        }
 public static List <short> ReadPMCDataTableWord(ushort handle, ushort startingAddress, ushort endingAddress)
 {
     FocasLibBase.IODBPMC1 f = new FocasLibBase.IODBPMC1();
     FocasLib.pmc_rdpmcrng(handle, 9, 1, startingAddress, endingAddress, 8 + (10 * 2), f);
     return(f.idata.ToList());
 }