Beispiel #1
0
        public static bool DLN2ReadByte(byte slaveaddr, int addr, byte[] tBuffer, byte addrmode)
        {
            DiolanU2C.DLN2_TRANSACTION dlN2Transaction = new DiolanU2C.DLN2_TRANSACTION();
            dlN2Transaction.Buffer = new byte[1];
            ushort num = 1;

            dlN2Transaction.nBufferLength        = num;
            dlN2Transaction.nSlaveDeviceAddress  = slaveaddr;
            dlN2Transaction.nMemoryAddressLength = addrmode;
            byte[] bytes = BitConverter.GetBytes(addr);
            dlN2Transaction.nMemoryAddress = (uint)((int)bytes[3] << 24 | (int)bytes[2] << 16 | (int)bytes[1] << 8) | (uint)bytes[0];
            DiolanU2C.DlnI2cMasterRead(DiolanU2C.hDLN2, 0U, dlN2Transaction.nSlaveDeviceAddress, dlN2Transaction.nMemoryAddressLength, dlN2Transaction.nMemoryAddress, dlN2Transaction.nBufferLength, dlN2Transaction.Buffer);
            tBuffer[0] = dlN2Transaction.Buffer[0];
            Thread.Sleep(30);
            return(true);
        }
Beispiel #2
0
        public static bool DLN2Read(string device, byte[] tbuffer, byte nMemoryAddressLength)
        {
            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);
            }
            DiolanU2C.DLN2_TRANSACTION Transaction = new DiolanU2C.DLN2_TRANSACTION();
            Transaction.Buffer = new byte[256];
            Transaction.nSlaveDeviceAddress  = DiolanU2C.addrSlave;
            Transaction.nMemoryAddressLength = nMemoryAddressLength;
            ushort num;

            for (int index = 0; index < tbuffer.Length; index += (int)num)
            {
                if (nMemoryAddressLength == (byte)1)
                {
                    byte[] bytes = BitConverter.GetBytes(index);
                    Transaction.nMemoryAddress = (uint)((int)bytes[3] << 24 | (int)bytes[2] << 16 | (int)bytes[1] << 8) | (uint)bytes[0];
                }
                num = DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_PageSize;
                if (index + (int)num > tbuffer.Length)
                {
                    num = (ushort)(tbuffer.Length - index);
                }
                Transaction.nBufferLength = (ushort)((uint)num & (uint)byte.MaxValue);
                DiolanU2C.prDLN2SetAddress(ref Transaction, index);
                DiolanU2C.DlnI2cMasterRead(DiolanU2C.hDLN2, 0U, Transaction.nSlaveDeviceAddress, Transaction.nMemoryAddressLength, Transaction.nMemoryAddress, Transaction.nBufferLength, Transaction.Buffer);
                if (index <= tbuffer.Length - (int)num)
                {
                    Array.Copy((Array)Transaction.Buffer, 0, (Array)tbuffer, index, (int)num);
                }
                else
                {
                    Array.Copy((Array)Transaction.Buffer, 0, (Array)tbuffer, index, tbuffer.Length - index);
                }
            }
            return(true);
        }