Ejemplo n.º 1
0
        public static bool DiolanWriteByte(byte slaveaddr, int addr, byte val)
        {
            int num = 0;

            num = DiolanU2C.U2C_SetI2cFreq(DiolanU2C.hDiolan, (byte)1);
            DiolanU2C.U2C_TRANSACTION pTransaction = new DiolanU2C.U2C_TRANSACTION();
            pTransaction.Buffer    = new byte[256];
            pTransaction.Buffer[0] = val;
            DiolanU2C.U2C_WORD u2CWord;
            u2CWord.bHi = (byte)0;
            u2CWord.bLo = (byte)1;
            pTransaction.nBufferLength        = u2CWord;
            pTransaction.nSlaveDeviceAddress  = slaveaddr;
            pTransaction.nMemoryAddressLength = (byte)1;
            byte[] bytes = BitConverter.GetBytes(addr);
            pTransaction.nMemoryAddress.b0 = bytes[3];
            pTransaction.nMemoryAddress.b1 = bytes[2];
            pTransaction.nMemoryAddress.b2 = bytes[1];
            pTransaction.nMemoryAddress.b3 = bytes[0];
            if (DiolanU2C.U2C_Write(DiolanU2C.hDiolan, ref pTransaction) != 0)
            {
                return(false);
            }
            Thread.Sleep(30);
            return(true);
        }
Ejemplo n.º 2
0
        public static bool DiolanWrite(string device, byte[] tbuffer)
        {
            DiolanU2C.m_Subtype = -1;
            for (int index = 0; index < DiolanU2C.sm_EepromTypes.Length; ++index)
            {
                if (DiolanU2C.sm_EepromTypes[index].m_Name == device.ToUpper())
                {
                    DiolanU2C.m_Subtype = index;
                    break;
                }
            }
            if (DiolanU2C.m_Subtype == -1)
            {
                return(false);
            }
            int num1 = 0;

            num1 = DiolanU2C.U2C_SetI2cFreq(DiolanU2C.hDiolan, (byte)1);
            DiolanU2C.U2C_TRANSACTION u2CTransaction = new DiolanU2C.U2C_TRANSACTION();
            u2CTransaction.Buffer = new byte[256];
            u2CTransaction.nSlaveDeviceAddress  = DiolanU2C.addrSlave;
            u2CTransaction.nMemoryAddressLength = (byte)2;
            ushort num2;

            for (int index = 0; index < tbuffer.Length; index += (int)num2)
            {
                num2 = DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_PageSize;
                if (index + (int)num2 > tbuffer.Length)
                {
                    num2 = (ushort)(tbuffer.Length - index);
                }
                u2CTransaction.nBufferLength.bLo = (byte)num2;
                DiolanU2C.prSetAddress(ref u2CTransaction, index);
                if (index <= tbuffer.Length - (int)num2)
                {
                    Array.Copy((Array)tbuffer, index, (Array)u2CTransaction.Buffer, 0, (int)num2);
                }
                else
                {
                    Array.Copy((Array)tbuffer, index, (Array)u2CTransaction.Buffer, 0, tbuffer.Length - index);
                }
                if (DiolanU2C.U2C_Write(DiolanU2C.hDiolan, ref u2CTransaction) != 0)
                {
                    return(false);
                }
                Thread.Sleep(30);
            }
            return(true);
        }
Ejemplo n.º 3
0
        private static bool prSetAddress(ref DiolanU2C.U2C_TRANSACTION Transaction, int Addr)
        {
            if ((long)Addr > (long)DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_Size)
            {
                return(false);
            }
            Transaction.nMemoryAddressLength = DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_AddrByteNum;
            int num = (int)DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_AddrByteNum * 8;

            if ((int)DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_AddrBitNum <= num)
            {
                Transaction.nSlaveDeviceAddress = DiolanU2C.addrSlave;
                byte[] bytes = BitConverter.GetBytes(Addr);
                Transaction.nMemoryAddress.b0 = bytes[3];
                Transaction.nMemoryAddress.b1 = bytes[2];
                Transaction.nMemoryAddress.b2 = bytes[1];
                Transaction.nMemoryAddress.b3 = bytes[0];
            }
            return(true);
        }
Ejemplo n.º 4
0
 private static extern int U2C_Write(int hDevice, ref DiolanU2C.U2C_TRANSACTION pTransaction);