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); }
public static int DLN2Connect() { DiolanU2C.DlnConnect("localhost", (ushort)9656); uint pDeviceCount = 0; int deviceCount = (int)DiolanU2C.DlnGetDeviceCount(ref pDeviceCount); return(pDeviceCount < 1U ? 0 : 1); }
public static bool DLN2Write( byte slaveaddr, string device, byte[] tbuffer, byte nMemoryAddrLength) { DiolanU2C.addrSlave = slaveaddr; return(DiolanU2C.DLN2Write(device, tbuffer, nMemoryAddrLength)); }
public static int DiolanInit(ulong sn) { if (DiolanU2C.sm_EepromTypes == null) { DiolanU2C.sm_EepromTypes = new DiolanU2C.EepromTypes[12]; DiolanU2C.sm_EepromTypes[0] = new DiolanU2C.EepromTypes("ATMEL AT24C01", 128U, (ushort)4, (byte)1, (byte)7); DiolanU2C.sm_EepromTypes[1] = new DiolanU2C.EepromTypes("ATMEL AT24C02", 256U, (ushort)8, (byte)1, (byte)8); DiolanU2C.sm_EepromTypes[2] = new DiolanU2C.EepromTypes("ATMEL AT24C04", 512U, (ushort)16, (byte)1, (byte)9); DiolanU2C.sm_EepromTypes[3] = new DiolanU2C.EepromTypes("ATMEL AT24C08", 1024U, (ushort)16, (byte)1, (byte)10); DiolanU2C.sm_EepromTypes[4] = new DiolanU2C.EepromTypes("ATMEL AT24C16", 2048U, (ushort)16, (byte)1, (byte)11); DiolanU2C.sm_EepromTypes[5] = new DiolanU2C.EepromTypes("ATMEL AT24C32", 4096U, (ushort)32, (byte)2, (byte)12); DiolanU2C.sm_EepromTypes[6] = new DiolanU2C.EepromTypes("ATMEL AT24C64", 8192U, (ushort)32, (byte)2, (byte)13); DiolanU2C.sm_EepromTypes[7] = new DiolanU2C.EepromTypes("ATMEL AT24C128", 16384U, (ushort)64, (byte)2, (byte)14); DiolanU2C.sm_EepromTypes[8] = new DiolanU2C.EepromTypes("ATMEL AT24C256", 32768U, (ushort)64, (byte)2, (byte)15); DiolanU2C.sm_EepromTypes[9] = new DiolanU2C.EepromTypes("ATMEL AT24C512", 65536U, (ushort)128, (byte)2, (byte)16); DiolanU2C.sm_EepromTypes[10] = new DiolanU2C.EepromTypes("ATMEL AT24C1024", 131072U, (ushort)256, (byte)2, (byte)17); DiolanU2C.sm_EepromTypes[11] = new DiolanU2C.EepromTypes("ATMEL ATTINY84", 4096U, (ushort)16, (byte)2, (byte)16); } for (int index = 0; index < 3; ++index) { DiolanU2C.hDiolan = DiolanU2C.U2C_OpenDeviceBySerialNum(sn); if (DiolanU2C.U2C_IsHandleValid(DiolanU2C.hDiolan) == 0) { DiolanU2C.U2C_SLAVE_ADDR_LIST pList = new DiolanU2C.U2C_SLAVE_ADDR_LIST(); if (DiolanU2C.U2C_ScanDevices(DiolanU2C.hDiolan, ref pList) == 0) { if (pList.nDeviceNumber != (byte)0) { return((int)(DiolanU2C.addrSlave = pList.List[(int)pList.nDeviceNumber - 1])); } DiolanU2C.U2C_CloseDevice(DiolanU2C.hDiolan); return(0); } } Thread.Sleep(500); try { Process process = new Process() { StartInfo = new ProcessStartInfo("devcon.exe") }; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.Arguments = "rescan"; process.Start(); process.WaitForExit(); Thread.Sleep(100); Debug.WriteLine("rescan [" + index.ToString() + "] " + (object)sn); } catch (Exception ex) { Debug.WriteLine("devcon: " + ex.Message); return(0); } } return(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); }
public static bool DLN2Write(string device, byte[] tbuffer, byte nMemoryAddrLength) { 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 = nMemoryAddrLength; ushort num; for (int index = 0; index < tbuffer.Length; index += (int)num) { if (nMemoryAddrLength == (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); if (index <= tbuffer.Length - (int)num) { Array.Copy((Array)tbuffer, index, (Array)Transaction.Buffer, 0, (int)num); } else { Array.Copy((Array)tbuffer, index, (Array)Transaction.Buffer, 0, tbuffer.Length - index); } DiolanU2C.DlnI2cMasterWrite(DiolanU2C.hDLN2, 0U, Transaction.nSlaveDeviceAddress, Transaction.nMemoryAddressLength, Transaction.nMemoryAddress, Transaction.nBufferLength, Transaction.Buffer); Thread.Sleep(30); } return(true); }
public static bool DLN2WriteByte(byte slaveaddr, int addr, byte val, byte addrmode) { DiolanU2C.DLN2_TRANSACTION dlN2Transaction = new DiolanU2C.DLN2_TRANSACTION(); dlN2Transaction.Buffer = new byte[256]; dlN2Transaction.Buffer[0] = val; 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.DlnI2cMasterWrite(DiolanU2C.hDLN2, 0U, dlN2Transaction.nSlaveDeviceAddress, dlN2Transaction.nMemoryAddressLength, dlN2Transaction.nMemoryAddress, dlN2Transaction.nBufferLength, dlN2Transaction.Buffer); Thread.Sleep(30); return(true); }
public static void DiolanClose() { DiolanU2C.U2C_CloseDevice(DiolanU2C.hDiolan); }
public static void DLN2Close() { int num1 = (int)DiolanU2C.DlnI2cMasterDisable(DiolanU2C.hDLN2, (byte)0, 1U); int num2 = (int)DiolanU2C.DlnCloseHandle(DiolanU2C.hDLN2); }
public static void DLN2Disconnect() { int num = (int)DiolanU2C.DlnDisconnect("localhost", (ushort)9656); }
public static bool DiolanWrite(byte slaveaddr, string device, byte[] tbuffer) { DiolanU2C.addrSlave = slaveaddr; return(DiolanU2C.DiolanWrite(device, tbuffer)); }
public static int DLN2InitDell(ulong sn) { if (DiolanU2C.sm_EepromTypes == null) { DiolanU2C.sm_EepromTypes = new DiolanU2C.EepromTypes[12]; DiolanU2C.sm_EepromTypes[0] = new DiolanU2C.EepromTypes("ATMEL AT24C01", 128U, (ushort)4, (byte)1, (byte)7); DiolanU2C.sm_EepromTypes[1] = new DiolanU2C.EepromTypes("ATMEL AT24C02", 256U, (ushort)8, (byte)1, (byte)8); DiolanU2C.sm_EepromTypes[2] = new DiolanU2C.EepromTypes("ATMEL AT24C04", 512U, (ushort)16, (byte)1, (byte)9); DiolanU2C.sm_EepromTypes[3] = new DiolanU2C.EepromTypes("ATMEL AT24C08", 1024U, (ushort)16, (byte)1, (byte)10); DiolanU2C.sm_EepromTypes[4] = new DiolanU2C.EepromTypes("ATMEL AT24C16", 2048U, (ushort)16, (byte)1, (byte)11); DiolanU2C.sm_EepromTypes[5] = new DiolanU2C.EepromTypes("ATMEL AT24C32", 4096U, (ushort)32, (byte)2, (byte)12); DiolanU2C.sm_EepromTypes[6] = new DiolanU2C.EepromTypes("ATMEL AT24C64", 8192U, (ushort)32, (byte)2, (byte)13); DiolanU2C.sm_EepromTypes[7] = new DiolanU2C.EepromTypes("ATMEL AT24C128", 16384U, (ushort)64, (byte)2, (byte)14); DiolanU2C.sm_EepromTypes[8] = new DiolanU2C.EepromTypes("ATMEL AT24C256", 32768U, (ushort)64, (byte)2, (byte)15); DiolanU2C.sm_EepromTypes[9] = new DiolanU2C.EepromTypes("ATMEL AT24C512", 65536U, (ushort)128, (byte)2, (byte)16); DiolanU2C.sm_EepromTypes[10] = new DiolanU2C.EepromTypes("ATMEL AT24C1024", 131072U, (ushort)256, (byte)2, (byte)17); DiolanU2C.sm_EepromTypes[11] = new DiolanU2C.EepromTypes("ATMEL ATTINY84", 4096U, (ushort)16, (byte)2, (byte)16); } for (int index = 0; index < 3; ++index) { uint num = DiolanU2C.DlnOpenDeviceBySn((uint)sn, ref DiolanU2C.hDLN2); if (DiolanU2C.hDLN2 < (ushort)1) { return(0); } byte nPortCount = 0; num = DiolanU2C.DlnI2cMasterGetPortCount(DiolanU2C.hDLN2, ref nPortCount); if (nPortCount < (byte)1) { return(0); } byte bEnabled = 0; num = DiolanU2C.DlnI2cMasterIsEnabled(DiolanU2C.hDLN2, (byte)0, ref bEnabled); if (bEnabled == (byte)0) { ushort nConflict = 0; num = DiolanU2C.DlnI2cMasterEnable(DiolanU2C.hDLN2, 0U, ref nConflict); num = DiolanU2C.DlnI2cMasterIsEnabled(DiolanU2C.hDLN2, (byte)0, ref bEnabled); } if (bEnabled == (byte)1) { return(1); } Thread.Sleep(500); try { Process process = new Process() { StartInfo = new ProcessStartInfo("devcon.exe") }; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.Arguments = "rescan"; process.Start(); process.WaitForExit(); Thread.Sleep(100); Debug.WriteLine("rescan [" + index.ToString() + "] " + (object)sn); } catch (Exception ex) { Debug.WriteLine("devcon: " + ex.Message); return(0); } } return(0); }