Exemple #1
0
        private int _Mcp2221Write(byte devAddr, byte regAddr, byte length, byte[] data)
        {
            byte[] buf = new byte[length + 1];

            buf[0] = regAddr;
            Array.Copy(data, 0, buf, 1, length);

            Mcp2221Api.Mcp2221I2cWriteApi(ipHandler, Convert.ToUInt32(length + 1), devAddr, 1, buf);

            return(0);
        }
Exemple #2
0
        private int _Mcp2221Read(byte devAddr, byte regAddr, byte length, byte[] data)
        {
            byte[] reg = { regAddr };
            int    result;

            result = Mcp2221Api.Mcp2221I2cWriteApi(ipHandler, 1, devAddr, 1, reg);
            if (result < 0)
            {
                return(result);
            }

            result = Mcp2221Api.Mcp2221I2cReadApi(ipHandler, length, devAddr, 1, data);
            if (result < 0)
            {
                return(-3);
            }

            return(length);
        }
Exemple #3
0
        private int _AardvarkRead16(byte devAddr, byte[] regAddr, byte length, byte[] data)
        {
            byte[] reg = { regAddr[0], regAddr[1] };
            int    result;

            result = Mcp2221Api.Mcp2221I2cWriteApi(ipHandler, 2, devAddr, 1, reg);
            if (result < 0)
            {
                return(-1);
            }

            result = Mcp2221Api.Mcp2221I2cReadApi(ipHandler, length, devAddr, 1, data);
            if (result < 0)
            {
                return(-1);
            }

            return(length);
        }
Exemple #4
0
        public int WriteRawApi(byte devAddr, byte length, byte[] data)
        {
            switch (as_atAdapterType)
            {
            case AdapterSelector.AdapterType.AS_AT_DUMMY:
                break;

            case AdapterSelector.AdapterType.AS_AT_AARDVARK:
                if (iHandler <= 0)
                {
                    if (ConnectApi() < 0)
                    {
                        MessageBox.Show("I2cMasterConnectApi() fail!!");
                    }
                    return(-1);
                }
                AardvarkApi.aa_i2c_write(iHandler, devAddr, AardvarkI2cFlags.AA_I2C_NO_FLAGS, length, data);
                AardvarkApi.aa_sleep_ms(100);
                return(0);

            case AdapterSelector.AdapterType.AS_AT_MCP2221:
                if (ipHandler == IntPtr.Zero)
                {
                    if (ConnectApi() < 0)
                    {
                        MessageBox.Show("I2cMasterConnectApi() fail!!");
                    }
                    return(-1);
                }
                Mcp2221Api.Mcp2221I2cWriteApi(ipHandler, Convert.ToUInt32(length), devAddr, 1, data);
                return(0);

            default:
                break;
            }

            return(0);
        }