protected UInt32 OnWriteWord(byte reg, UInt16 val)
        {
            UInt16 DataOutLen = 0;

            byte[] sendbuf    = new byte[5];
            byte[] receivebuf = new byte[2];
            UInt32 ret        = LibErrorCode.IDS_ERR_SUCCESSFUL;

            try
            {
                sendbuf[0] = (byte)parent.m_busoption.GetOptionsByGuid(BusOptions.I2CAddress_GUID).SelectLocation.Code;
            }
            catch (System.Exception ex)
            {
                return(ret = LibErrorCode.IDS_ERR_DEM_LOST_PARAMETER);
            }
            sendbuf[1] = reg;
            sendbuf[3] = SharedFormula.HiByte(val);
            sendbuf[2] = SharedFormula.LoByte(val);
            for (int i = 0; i < ElementDefine.RETRY_COUNTER; i++)
            {
                if (m_Interface.WriteDevice(sendbuf, ref receivebuf, ref DataOutLen, 2))
                {
                    ret = LibErrorCode.IDS_ERR_SUCCESSFUL;
                    break;
                }
                ret = LibErrorCode.IDS_ERR_DEM_FUN_TIMEOUT;
                Thread.Sleep(10);
            }
            return(ret);
        }
        protected byte calc_crc_write(byte slave_addr, byte reg_addr, UInt16 data)
        {
            byte[] pdata = new byte[4];

            pdata[0] = slave_addr;;
            pdata[1] = reg_addr;
            pdata[2] = SharedFormula.HiByte(data);
            pdata[3] = SharedFormula.LoByte(data);

            return(crc8_calc(ref pdata, 4));
        }
        protected byte calc_crc_read(byte slave_addr, byte reg_addr, UInt16 data)
        {
            byte[] pdata = new byte[5];

            pdata[0] = slave_addr;
            pdata[1] = reg_addr;
            pdata[2] = (byte)(slave_addr | 0x01);
            pdata[3] = SharedFormula.HiByte(data);
            pdata[4] = SharedFormula.LoByte(data);

            return(crc8_calc(ref pdata, 5));
        }
        protected UInt32 OnWriteWord(byte reg, UInt16 val)
        {
#if debug
            UInt32 ret = LibErrorCode.IDS_ERR_SUCCESSFUL;
#if functiontimeout
            ret = LibErrorCode.IDS_ERR_DEM_FUN_TIMEOUT;
#else
#if pec
            ret = LibErrorCode.IDS_ERR_BUS_DATA_PEC_ERROR;
#endif
#endif
            return(ret);
#else
            UInt16 DataOutLen = 0;
            byte[] sendbuf    = new byte[5];
            byte[] receivebuf = new byte[2];
            UInt32 ret        = LibErrorCode.IDS_ERR_SUCCESSFUL;

            try
            {
                sendbuf[0] = (byte)parent.m_busoption.GetOptionsByGuid(BusOptions.I2CAddress_GUID).SelectLocation.Code;
            }
            catch (System.Exception ex)
            {
                return(ret = LibErrorCode.IDS_ERR_DEM_LOST_PARAMETER);
            }
            sendbuf[1] = reg;
            sendbuf[2] = SharedFormula.HiByte(val);
            sendbuf[3] = SharedFormula.LoByte(val);
            sendbuf[4] = calc_crc_write(sendbuf[0], sendbuf[1], val);
            for (int i = 0; i < ElementDefine.RETRY_COUNTER; i++)
            {
                if (parent.m_Interface.WriteDevice(sendbuf, ref receivebuf, ref DataOutLen, 3))
                {
                    ret = LibErrorCode.IDS_ERR_SUCCESSFUL;
                    break;
                }
                ret = LibErrorCode.IDS_ERR_DEM_FUN_TIMEOUT;
                Thread.Sleep(10);
            }
            //m_Interface.GetLastErrorCode(ref ret);
            return(ret);
#endif
        }