Ejemplo n.º 1
0
        private CP2112_DLL.HID_SMBUS_STATUS Read2(byte slaveAddress, ushort numBytesToRead,
                                                  byte OffsetAddr, ref byte[] readBytes)
        {
            CP2112_DLL.HID_SMBUS_STATUS ret = CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_ERROR;
            byte[] BufTmp        = new byte[64];
            byte[] targetAddress = new byte[16];
            byte   ReadStatus    = 0;
            byte   numBytesRead  = 0;

            Array.Clear(readBytes, 0, numBytesToRead);

            if (!isOpened())
            {
                return(CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_ERROR);
            }
            //if (!cancel()) return CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_INVALID_DEVICE_OBJECT;

            targetAddress[0] = OffsetAddr;
            ret = CP2112_DLL.HidSmbus_AddressReadRequest(m_hidSmbus, slaveAddress, numBytesToRead, 1, targetAddress);
            if (ret != CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_SUCCESS)
            {
                return(ret);
            }
            ushort readCont = 0;

            do
            {
                ret = CP2112_DLL.HidSmbus_ForceReadResponse(m_hidSmbus, numBytesToRead);
                if (ret != CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_SUCCESS)
                {
                    return(ret);
                }


                ret = CP2112_DLL.HidSmbus_GetReadResponse(m_hidSmbus, ref ReadStatus,
                                                          BufTmp, 64, ref numBytesRead);

                // CP2112_DLL.HidSmbus_CancelTransfer(m_hidSmbus);
                if (ret != CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_SUCCESS)
                {
                    break;
                }
                if (ReadStatus != (byte)CP2112_DLL.HID_SMBUS_TRANSFER_S0.HID_SMBUS_S0_ERROR)
                {
                    Array.Copy(BufTmp, 0, readBytes, readCont, numBytesRead);
                    readCont += numBytesRead;
                }

                else
                {
                    return(CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_ERROR);
                }
            }while ((ReadStatus == (byte)CP2112_DLL.HID_SMBUS_TRANSFER_S0.HID_SMBUS_S0_BUSY)
                    );


            return(ret);
        }
Ejemplo n.º 2
0
        private CP2112_DLL.HID_SMBUS_STATUS Read3(byte slaveAddress, ushort numBytesToRead,
                                                  byte OffsetAddr, ref byte[] readBytes)
        {
            byte[] targetAddress = new byte[1];
            targetAddress[0] = OffsetAddr;
            byte[] BufTmp = new byte[255];

            byte   ReadStatus   = 0;
            byte   numBytesRead = 0;
            ushort readCont     = 0;

            CP2112_DLL.HID_SMBUS_STATUS ret = CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_ERROR;
            if (!isOpened())
            {
                return(CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_ERROR);
            }
            ret = CP2112_DLL.HidSmbus_SetTimeouts(m_hidSmbus, 100);
            if (ret != CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_SUCCESS)
            {
                return(ret);
            }

            ret = CP2112_DLL.HidSmbus_AddressReadRequest(m_hidSmbus, slaveAddress, numBytesToRead, 1, targetAddress);
            Util.Delay(50);

            ret = CP2112_DLL.HidSmbus_ForceReadResponse(m_hidSmbus, numBytesToRead);
            if (ret != CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_SUCCESS)
            {
                return(ret);
            }
            Util.Delay(20);

            do
            {
                ret = CP2112_DLL.HidSmbus_GetReadResponse(m_hidSmbus, ref ReadStatus,
                                                          BufTmp, 64, ref numBytesRead);

                // CP2112_DLL.HidSmbus_CancelTransfer(m_hidSmbus);
                if (ret != CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_SUCCESS)
                {
                    break;
                }
                if (ReadStatus != (byte)CP2112_DLL.HID_SMBUS_TRANSFER_S0.HID_SMBUS_S0_ERROR)
                {
                    Array.Copy(BufTmp, 0, readBytes, readCont, numBytesRead);
                    readCont += numBytesRead;
                }

                else
                {
                    return(CP2112_DLL.HID_SMBUS_STATUS.HID_SMBUS_ERROR);
                }
            }while (readCont < numBytesToRead);


            //ret = CP2112_DLL.HidSmbus_GetReadResponse(m_hidSmbus, ref ReadStatus,
            //                                  BufTmp, 255, ref numBytesRead);

            //Array.Copy(BufTmp, 0, readBytes, 0, numBytesRead);

            CP2112_DLL.HidSmbus_CancelTransfer(m_hidSmbus);
            return(ret);
        }