public void WriteRam(string filename) { try { if (!IsConnected) { throw new InvalidOperationException("Failed to write ram : Serial is not connected."); } if (IsApiBusy) { throw new InvalidOperationException("Failed to write ram : API is not ready."); } if (!File.Exists(filename)) { throw new FileNotFoundException($"Failed to write ram : {filename} does not exist."); } fileHandler.OpenFile(filename, FileMode.Open); API_Mode = APIMode.WriteRam; //send command! serialInterface.Write($"{GB_API_Protocol.API_WRITE_RAM}\n"); } catch (Exception e) { _throwException(e); return; } }
public void ReadRam() { try { if (!IsConnected) { throw new InvalidOperationException("Failed to read ram : Serial is not connected"); } if (IsApiBusy) { throw new InvalidOperationException("Failed to read ram : API is not ready"); } API_Mode = APIMode.ReadRam; //send command! serialInterface.Write($"{GB_API_Protocol.API_READ_RAM}\n"); } catch (Exception e) { _throwException(e); return; } }
// IpcSetGlobalProperty() - http://msdn.microsoft.com/en-us/library/windows/desktop/hh535270(v=vs.85).aspx public static void IpcSetAPIMode(APIMode securityMode) { int hr = 0; IntPtr propertyPtr = Marshal.AllocHGlobal(sizeof(uint)); try { Marshal.WriteInt32(propertyPtr, (int)securityMode); hr = UnsafeNativeMethods.IpcSetGlobalProperty(Convert.ToUInt32(EnvironmentInformationType.SecurityMode), propertyPtr); ThrowOnErrorCode(hr); } finally { Marshal.FreeHGlobal(propertyPtr); } }