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); }