public TOOLSTICKHandle(CToolStick handle) { this.hnd = handle; }
public static CToolStick Connect(ushort vid, ushort pid, uint getReportTimeout, uint setReportTimeout) { CToolStick handle = new CToolStick(); lock (singleLock) { StringBuilder str = new StringBuilder(260); StringBuilder builder2 = new StringBuilder(256); bool flag = false; ADTManager manager = ADTManager.instance(); ADTRecord record = new ADTRecord(); IOPortAddress portAddress = new IOPortAddress { portType = PortType.TOOLSTICK }; portAddress.toolstickAddr.PID = pid; portAddress.toolstickAddr.VID = vid; ushort num = 0; ushort num2 = 0; ushort devRelNum = 0; uint numDevices = GetNumDevices(); for (uint i = 0; i < numDevices; i++) { if (GetAttributes(i, ref num, ref num2, ref devRelNum) != 0 || pid != num2 || vid != num || GetString(i, 3, str, 260) != 0 || GetString(i, 4, builder2, 0x100) != 0 || manager.isToolStickDeviceExcluded(builder2.ToString()) ) { continue; } bool flag2 = false; WDS_MainProg.frameWin().DisablePlugAndPlay(); int num7 = 0x4e20; int millisecondsTimeout = 0x7d0; int tickCount = Environment.TickCount; int dwDevices = 0; while (ToolStickDebugUtil.USBDebugDevices(ref dwDevices) != 0 && (Environment.TickCount - tickCount) < num7) { Thread.Sleep(millisecondsTimeout); millisecondsTimeout += 0x3e8; } for (int j = 0; j < dwDevices; j++) { StringBuilder psSerialNum = new StringBuilder(0x80); if ((ToolStickDebugUtil.GetUSBDeviceSN(j, ref psSerialNum) == 0) && (psSerialNum.ToString() == builder2.ToString())) { if (ToolStickDebugUtil.ConnectUSB(psSerialNum, 1, 1, 0) == 0) { flag2 = true; ToolStickDebugUtil.SetTargetGo(); ToolStickDebugUtil.DisconnectUSB(); Thread.Sleep(250); } break; } } WDS_MainProg.frameWin().RestorePlugAndPlay(); if (!flag2) _log.Error("Could not verify the Firmware on the Toolstick!"); if (handle.Open(i) == 0) flag = true; portAddress.toolstickAddr.DeviceString = str.ToString(); portAddress.toolstickAddr.Serial = builder2.ToString(); if (manager.findADTRecord(portAddress) == null) break; } if (!flag) return null; handle.SetTimeouts(getReportTimeout, setReportTimeout); handle.ADT = new ADTRecord(portAddress, new DeviceDescriptor()); handle.ADT.PortAddress.handle = new DeviceHandle(new TOOLSTICKHandle(handle)); str = new StringBuilder(260); if (handle.GetOpenedString(3, str, 260) != 0) return null; handle.ADT.PortAddress.toolstickAddr.DeviceString = str.ToString(); uint maxReadSize = 60; maxReadSize = handle.GetMaxReadSize(); if (maxReadSize != 0) maxReadSize = 120; handle.ReceiveBuffer = new DataBuffer((int) maxReadSize); } return handle; }
public TOOLSTICKHandle() { this.hnd = null; }