public void UpdateCurrentMemRegConfig(string path) { SafeFileHandle asyncWriteHandle = CreateFile(path, Win32HardwareIOSupport.GENERIC_WRITE, Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero); if (asyncWriteHandle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } SafeFileHandle asyncReadHandle = CreateFile(path, Win32HardwareIOSupport.GENERIC_READ, Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero); if (asyncReadHandle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } uint wrBytes; if (!WriteFile(asyncWriteHandle, QueryDeviceReq.getCommandPacket(), 65, out wrBytes, IntPtr.Zero)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } byte[] respdata = new byte[65]; if (!ReadFile(asyncReadHandle, respdata, 65, out wrBytes, IntPtr.Zero)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } }
public virtual void UpdateCurrentMemRegConfig(FileStream hardwareFileStream) { Thread th = new Thread( delegate() { hardwareFileStream.Write(QueryDeviceReq.getCommandPacket(), 0, 65); } ); th.Start(); if (!th.Join(TIME_OUT)) { th.Abort(); new Exception("Attached hardware not answer"); } //hardwareFileStream.Write(QueryDeviceReq.getCommandPacket(), 0, 65); byte[] respdata = new byte[65]; th = new Thread( delegate() { hardwareFileStream.Read(respdata, 0, 65); } ); th.Start(); if (!th.Join(TIME_OUT)) { th.Abort(); new Exception("Attached hardware not answer"); } //hardwareFileStream.Read(respdata, 0, 65); QueryResultsResp response = QueryResultsResp.getQueryResultsResp(respdata); _currentMemoryRegionsConfig = response.MemoryRegionsInfo; _bytesPerPacket = (uint)response.BytesPerPacket; }