public static int DLN2Init(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) { byte nSlaveCount = 0; DiolanU2C.DLN2_SLAVE_ADDR_LIST pList = new DiolanU2C.DLN2_SLAVE_ADDR_LIST(); num = DiolanU2C.DlnI2cMasterScanDevices(DiolanU2C.hDLN2, (byte)0, ref nSlaveCount, ref pList); if (nSlaveCount != (byte)0) { return((int)(DiolanU2C.addrSlave = pList.List[(int)nSlaveCount - 1])); } DiolanU2C.DLN2Close(); 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); }