public static void Status(IOStatus status) { Console.ForegroundColor = ConsoleColor.White; Console.Write("["); switch (status) { case IOStatus.OK: Console.ForegroundColor = ConsoleColor.Green; break; case IOStatus.ERROR: Console.ForegroundColor = ConsoleColor.Red; break; case IOStatus.WARNING: Console.ForegroundColor = ConsoleColor.Yellow; break; case IOStatus.DEFAULT: default: Console.ForegroundColor = ConsoleColor.White; break; } Console.Write(status.ToString()); Console.ForegroundColor = ConsoleColor.White; Console.Write("]"); }
public void Start() { prevIOStatus = null; touchTracking = false; IsRunning = true; Device.IOStatusChanged += IoStatusChanged; }
public override void Write(byte [] buffer, int offset, int count) { IOStatus status = IOStatus.Again; IntPtr error; int written; if (buffer == null) { throw new ArgumentNullException(); } unsafe { while (status == IOStatus.Again && count > 0) { fixed(byte *data = &buffer[offset]) { status = g_io_channel_write_chars(handle, data, count, out written, out error); } if (error != IntPtr.Zero) { throw new GLib.GException(error); } offset += written; count -= written; } } }
private void IoStatusChanged(object sender, IOStatus e) { Device.RequestIoStatus(); Dispatcher.Invoke(new Action <IOStatus>(status => { IoDisplay.UpdateStatus(status); }), e); }
public void Stop(IOStatus status, string message) { Utils.ClearCurrentLine(); Utils.Status(status); Console.Write($" {message}"); Console.Write("\n"); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="request"></param> /// <param name="status"></param> public IOResponse(IORequest request, IOStatus status) { Contract.Requires<ArgumentNullException>(request != null); this.request = request; this.status = status; this.headers = new Headers(); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="request"></param> /// <param name="status"></param> public IOResponse(IORequest request, IOStatus status) { Contract.Requires <ArgumentNullException>(request != null); this.request = request; this.status = status; this.headers = new Headers(); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="request"></param> /// <param name="status"></param> /// <param name="content"></param> /// <param name="contentType"></param> public IOResponse(IORequest request, IOStatus status, Stream content, MediaRange contentType) : this(request, status) { Contract.Requires <ArgumentNullException>(request != null); Contract.Requires <ArgumentNullException>(content != null); this.content = content; this.contentType = contentType; }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="request"></param> /// <param name="status"></param> /// <param name="content"></param> /// <param name="contentType"></param> public IOResponse(IORequest request, IOStatus status, Stream content, MediaRange contentType) : this(request, status) { Contract.Requires<ArgumentNullException>(request != null); Contract.Requires<ArgumentNullException>(content != null); this.content = content; this.contentType = contentType; }
public void StartNext(IOStatus status, string finishMessage, string message) { this._Paused = true; Utils.ClearCurrentLine(); Utils.Status(status); Console.WriteLine(finishMessage); this.Message = message; this._Paused = false; }
public IOStatus Flush() { IntPtr error; IOStatus ret = (IOStatus)g_io_channel_flush(Handle, out error); if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
public IOStatus ReadUnichar(out uint thechar) { IntPtr error; IOStatus ret = (IOStatus)g_io_channel_read_unichar(Handle, out thechar, out error); if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
public IOStatus SeekPosition(long offset, SeekType type) { IntPtr error; IOStatus ret = (IOStatus)g_io_channel_seek_position(Handle, offset, (int)type, out error); if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
public IOStatus Shutdown(bool flush) { IntPtr error; IOStatus ret = (IOStatus)g_io_channel_shutdown(Handle, flush, out error); if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
public IOStatus WriteUnichar(uint thechar) { IntPtr error; IOStatus ret = (IOStatus)g_io_channel_write_unichar(Handle, thechar, out error); if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
public IOStatus ReadChars(byte[] buf, out ulong bytes_read) { UIntPtr native_bytes_read; IntPtr error; IOStatus ret = (IOStatus)g_io_channel_read_chars(Handle, buf, new UIntPtr((ulong)buf.Length), out native_bytes_read, out error); bytes_read = (ulong)native_bytes_read; if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
public IOStatus WriteChars(byte[] buf, out ulong bytes_written) { UIntPtr native_bytes_written; IntPtr error; IOStatus ret = (IOStatus)g_io_channel_write_chars(Handle, buf, new IntPtr(buf.Length), out native_bytes_written, out error); bytes_written = (ulong)native_bytes_written; if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
public IOStatus GetIOState(int id) { IOStatus state = IOStatus.None; if (_waits.ContainsKey(id)) { state = IOStatus.Wait; } else if (_runing.ContainsKey(id)) { state = IOStatus.Runing; } return(state); }
private void IoStatusChanged(object sender, IOStatus e) { if (prevIOStatus == null) { prevIOStatus = e; return; } string script = GenerateScript(e); if (script != null) { ScriptRecorded.Invoke(this, new ScriptRecordedEventEventArgs(script)); } prevIOStatus = e; }
public IOStatus ReadLine(out string str_return, out ulong terminator_pos) { IntPtr native_string; UIntPtr native_terminator_pos; IntPtr error; IOStatus ret = (IOStatus)g_io_channel_read_line(Handle, out native_string, IntPtr.Zero, out native_terminator_pos, out error); terminator_pos = (ulong)native_terminator_pos; str_return = null; if (ret == IOStatus.Normal) { str_return = Marshaller.PtrToStringGFree(native_string); } if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
public IOStatus WriteChars(string str, out string remainder) { ulong written; System.Text.Encoding enc = System.Text.Encoding.UTF8; byte[] buffer = enc.GetBytes(str); IOStatus ret = WriteChars(buffer, out written); remainder = null; if ((int)written == buffer.Length) { return(ret); } int count = buffer.Length - (int)written; byte[] rem = new byte [count]; Array.Copy(buffer, (int)written, rem, 0, count); remainder = enc.GetString(rem); return(ret); }
private void IoStatusChanged(object sender, IOStatus e) { int[] btn = e.OutputStatus.Outputs; switch (Status) { case RunnerStatus.Stopped: if (btn[PS4Button.L3] == 100) { Wait(); } break; case RunnerStatus.WaitingUser: if (btn[scriptCommands[0].Button] == 100) { Start(); } break; } }
private void UpdateValues(SpektrometrStatus status) { int mainStatus = status.MainStatus; for (int i = 0; i < 6; i++) { StatusIndicator.SetItemCheckState(i, (mainStatus & (1 << i)) != 0 ? CheckState.Checked : CheckState.Unchecked); } int ioStatus = status.IoStatus; for (int i = 0; i < 8; i++) { IOStatus.SetItemCheckState(i, (ioStatus & (1 << i)) != 0 ? CheckState.Checked : CheckState.Unchecked); } AktualneImpulsy1.Value = status.AktualneImpulsy1; AktualneImpulsy2.Value = status.AktualneImpulsy2; lastIoStatus = status.IoStatus; }
public IOStatus ReadToEnd(out string str_return) { IntPtr native_str; UIntPtr native_length; IntPtr error; IOStatus ret = (IOStatus)g_io_channel_read_to_end(Handle, out native_str, out native_length, out error); str_return = null; if (ret == IOStatus.Normal) { byte[] buffer = new byte [(ulong)native_length]; Marshal.Copy(native_str, buffer, 0, (int)(ulong)native_length); str_return = System.Text.Encoding.UTF8.GetString(buffer); } Marshaller.Free(native_str); if (error != IntPtr.Zero) { throw new GException(error); } return(ret); }
unsafe static void Main(string[] args) { IntPtr fileHandle = CreateFile("failas.txt", (uint)FileAccess.FileReadWrite, 0, IntPtr.Zero, 1, 0x40000000, IntPtr.Zero); if (fileHandle == IntPtr.Zero) { throw new Win32Exception(); } Console.WriteLine(fileHandle.ToInt32()); Console.ReadKey(); overlap lapped = new overlap(); ManualResetEvent evente = new ManualResetEvent(false); lapped.EventHandle = evente.SafeWaitHandle.DangerousGetHandle(); //Console.WriteLine(lapped.EventHandle.ToInt32() + '\n'); IOCompletionPort.IOCompletionPort comPort = new IOCompletionPort.IOCompletionPort(fileHandle, 3, 4); ThreadStart action = () => { Console.WriteLine(comPort.Handle.ToInt32()); IOStatus iOStatus = comPort.GetPacket(0); Console.WriteLine(iOStatus.lpCompletionKey + " " + iOStatus.lpNumberOfBytes + " " + iOStatus.EventHandle + '\n'); }; new Thread(action).Start(); byte[] buffer = new byte[] { 34, 2, 100, 200, 45 }; uint numberWritten = 0; IOCompletionPort.IOCompletionPort.WriteFile(fileHandle, buffer, 5, out numberWritten, lapped); Console.WriteLine(numberWritten + '\n'); Console.ReadKey(); }
public List <Message> EndRead(Connection connection, int bytesRead, out IOStatus status) { status = IOStatus.NONE; List <Message> readMessages = new List <Message>(); Socket socket = connection.socket; byte[] messageData; byte[] rbuffer = connection.GetRBuffer(); log.add_to_log(log_vrste.info, String.Format("Handler {0}: buffer={1}", connection.uid, ByteArrayToString(rbuffer)), "InputOutput.cs EndRead()"); log.add_to_log(log_vrste.info, String.Format("Handler {0}: read {1} bytes", connection.uid, bytesRead), "InputOutput.cs EndRead()"); log.add_to_log(log_vrste.info, String.Format("Handler {0}: read {1}", connection.uid, ByteArrayToString(new ArraySegment <byte>(connection.tmp_rbuffer, 0, bytesRead).ToArray())), "InputOutput.cs EndRead()"); if (bytesRead == 0) { throw new Exception("Client disconnected"); } connection.WriteRBuffer(connection.tmp_rbuffer, 0, bytesRead); rbuffer = connection.GetRBuffer(); int length = 0, left, start = 0; byte opcode; while (connection.position < rbuffer.Length) { left = (int)rbuffer.Length - connection.position; log.add_to_log(log_vrste.info, String.Format("Handler {0}: left={1}", connection.uid, left), "InputOutput.cs EndRead()"); if (left >= 5) { length = BitConverter.ToInt32(rbuffer, connection.position); connection.position += INT_SIZE; opcode = rbuffer[connection.position]; connection.position += BYTE_SIZE; if ((left - (FIVE_BYTES)) >= length) { start = FIVE_BYTES; messageData = new ArraySegment <byte>(rbuffer, start, length).ToArray(); connection.position += length; log.add_to_log(log_vrste.info, String.Format("Handler {0}: read message, opcode={1}, length={2}, data={3}", connection.uid, opcode, length, ByteArrayToString(messageData)), "InputOutput.cs EndRead()"); log.add_to_log(log_vrste.info, String.Format("Handler {0}: at position: {1}", connection.uid, connection.position), "InputOutput.cs EndRead()"); readMessages.Add(new Message(opcode, messageData)); if (rbuffer.Length > (length + start)) { log.add_to_log(log_vrste.info, String.Format("Handler {0}: got parts of new message.", connection.uid), "InputOutput.cs EndRead()"); log.add_to_log(log_vrste.info, String.Format("Handler {0}: current buffer={1}", connection.uid, ByteArrayToString(rbuffer)), "InputOutput.cs EndRead()"); byte[] tmp = new ArraySegment <byte>(rbuffer, length + start, rbuffer.Length - (length + start)).ToArray(); connection.ResetRBuffer(); connection.WriteRBuffer(tmp, 0, tmp.Length); rbuffer = connection.GetRBuffer(); connection.position = 0; log.add_to_log(log_vrste.info, String.Format("Handler {0}: current buffer length is {1}", connection.uid, rbuffer.Length), "InputOutput.cs EndRead()"); } else { log.add_to_log(log_vrste.info, String.Format("Handler {0}: reset buffer", connection.uid), "InputOutput.cs EndRead()"); connection.position = 0; connection.ResetRBuffer(); break; } } //nema podataka pa utrpaj ostatak u buffer else { log.add_to_log(log_vrste.info, String.Format("Handler {0}: opcode={1}, length={2}. Whole message not yet received", connection.uid, opcode, length), "InputOutput.cs EndRead()"); log.add_to_log(log_vrste.info, String.Format("Handler {0}: at position: {1}", connection.uid, connection.position), "InputOutput.cs EndRead()"); log.add_to_log(log_vrste.info, String.Format("Handler {0}: message not complete", connection.uid), "InputOutput.cs EndRead()"); status = IOStatus.INCOMPLETE; connection.position = 0; break; } } //nema headera, utrpaj ostatak u buffer else { log.add_to_log(log_vrste.info, String.Format("Handler {0}: message not complete, put received back to buffer", connection.uid), "InputOutput.cs EndRead()"); break; } } log.add_to_log(log_vrste.info, String.Format("Handler {0}: buffer: {1}", connection.uid, ByteArrayToString(rbuffer)), "InputOutput.cs EndRead()"); if (status == IOStatus.NONE) { status = IOStatus.COMPLETE; } connection.tmp_rbuffer = new byte[Connection.RBUFFER_SIZE]; return(readMessages); }
public void UpdateStatus(IOStatus status) { Console.Text = status.Console; Controller.Text = status.Controller; Led1.Text = status.Led1; Led2.Text = status.Led2; Led3.Text = status.Led3; Led4.Text = status.Led4; RumbleA.Text = status.RumbleA; RumbleB.Text = status.RumbleB; RumbleLt.Text = status.RumbleLt; RumbleRt.Text = status.RumbleRt; Slot.Text = status.Slot; Battery.Text = status.Battery; CpuLoad.Text = status.Cpuload; if (_currentController != status.ConnectedController) { _currentController = status.ConnectedController; var names = IOLabels.GetLabels(_currentController); In00.ValueName = names[00]; In01.ValueName = names[01]; In02.ValueName = names[02]; In03.ValueName = names[03]; In04.ValueName = names[04]; In05.ValueName = names[05]; In06.ValueName = names[06]; In07.ValueName = names[07]; In08.ValueName = names[08]; In09.ValueName = names[09]; In10.ValueName = names[10]; In11.ValueName = names[11]; In12.ValueName = names[12]; In13.ValueName = names[13]; In14.ValueName = names[14]; In15.ValueName = names[15]; In16.ValueName = names[16]; In17.ValueName = names[17]; In18.ValueName = names[18]; In19.ValueName = names[19]; In20.ValueName = names[20]; In21.ValueName = names[24]; In22.ValueName = names[25]; In23.ValueName = names[26]; In24.ValueName = names[21]; In25.ValueName = names[22]; In26.ValueName = names[23]; In27.ValueName = names[27]; In28.ValueName = names[28]; In29.ValueName = names[29]; } if (_currentConsole != status.ConnectedConsole) { _currentConsole = status.ConnectedConsole; var names = IOLabels.GetLabels(_currentConsole); Out00.ValueName = names[00]; Out01.ValueName = names[01]; Out02.ValueName = names[02]; Out03.ValueName = names[03]; Out04.ValueName = names[04]; Out05.ValueName = names[05]; Out06.ValueName = names[06]; Out07.ValueName = names[07]; Out08.ValueName = names[08]; Out09.ValueName = names[09]; Out10.ValueName = names[10]; Out11.ValueName = names[11]; Out12.ValueName = names[12]; Out13.ValueName = names[13]; Out14.ValueName = names[14]; Out15.ValueName = names[15]; Out16.ValueName = names[16]; Out17.ValueName = names[17]; Out18.ValueName = names[18]; Out19.ValueName = names[19]; Out20.ValueName = names[20]; Out21.ValueName = names[24]; Out22.ValueName = names[25]; Out23.ValueName = names[26]; Out24.ValueName = names[21]; Out25.ValueName = names[22]; Out26.ValueName = names[23]; Out27.ValueName = names[27]; Out28.ValueName = names[28]; Out29.ValueName = names[29]; } In00.Value = status.InputStatus.Input00; In01.Value = status.InputStatus.Input01; In02.Value = status.InputStatus.Input02; In03.Value = status.InputStatus.Input03; In04.Value = status.InputStatus.Input04; In05.Value = status.InputStatus.Input05; In06.Value = status.InputStatus.Input06; In07.Value = status.InputStatus.Input07; In08.Value = status.InputStatus.Input08; In09.Value = status.InputStatus.Input09; In10.Value = status.InputStatus.Input10; In11.Value = status.InputStatus.Input11; In12.Value = status.InputStatus.Input12; In13.Value = status.InputStatus.Input13; In14.Value = status.InputStatus.Input14; In15.Value = status.InputStatus.Input15; In16.Value = status.InputStatus.Input16; In17.Value = status.InputStatus.Input17; In18.Value = status.InputStatus.Input18; In19.Value = status.InputStatus.Input19; In20.Value = status.InputStatus.Input20; In21.Value = status.InputStatus.Input21; In22.Value = status.InputStatus.Input22; In23.Value = status.InputStatus.Input23; In24.Value = status.InputStatus.Input24; In25.Value = status.InputStatus.Input25; In26.Value = status.InputStatus.Input26; In27.Value = status.InputStatus.Input27; In28.Value = status.InputStatus.Input28; In29.Value = status.InputStatus.Input29; Out00.Value = status.OutputStatus.Output00; Out01.Value = status.OutputStatus.Output01; Out02.Value = status.OutputStatus.Output02; Out03.Value = status.OutputStatus.Output03; Out04.Value = status.OutputStatus.Output04; Out05.Value = status.OutputStatus.Output05; Out06.Value = status.OutputStatus.Output06; Out07.Value = status.OutputStatus.Output07; Out08.Value = status.OutputStatus.Output08; Out09.Value = status.OutputStatus.Output09; Out10.Value = status.OutputStatus.Output10; Out11.Value = status.OutputStatus.Output11; Out12.Value = status.OutputStatus.Output12; Out13.Value = status.OutputStatus.Output13; Out14.Value = status.OutputStatus.Output14; Out15.Value = status.OutputStatus.Output15; Out16.Value = status.OutputStatus.Output16; Out17.Value = status.OutputStatus.Output17; Out18.Value = status.OutputStatus.Output18; Out19.Value = status.OutputStatus.Output19; Out20.Value = status.OutputStatus.Output20; Out21.Value = status.OutputStatus.Output21; Out22.Value = status.OutputStatus.Output22; Out23.Value = status.OutputStatus.Output23; Out24.Value = status.OutputStatus.Output24; Out25.Value = status.OutputStatus.Output25; Out26.Value = status.OutputStatus.Output26; Out27.Value = status.OutputStatus.Output27; Out28.Value = status.OutputStatus.Output28; Out29.Value = status.OutputStatus.Output29; Trace1.Value = status.OutputStatus.Trace1; Trace2.Value = status.OutputStatus.Trace2; Trace3.Value = status.OutputStatus.Trace3; Trace4.Value = status.OutputStatus.Trace4; Trace5.Value = status.OutputStatus.Trace5; Trace6.Value = status.OutputStatus.Trace6; #if DEBUG int cx = status.OutputStatus.Output28, cy = status.OutputStatus.Output29; if (cx != px || cy != py) { Debug.WriteLine("Touch: ({0},{1})", cx, cy); px = cx; py = cy; } #endif }
private string GenerateScript(IOStatus status) { List <ScriptCommand> cmds = new List <ScriptCommand>(); int[] prv = prevIOStatus.OutputStatus.Outputs; int[] cur = status.OutputStatus.Outputs; long delay = timer.ElapsedMilliseconds - elapsedMs; // Track Buttons foreach (var button in trackButtons) { if (prv[button] != cur[button]) { cmds.Add(new ScriptCommand(button, cur[button])); } } // Track Touch if (touchTracking) { if (cmds.Count > 0) { touchTracking = false; cmds.Insert(0, new ScriptCommand("touch", 0)); } else if (delay >= touchDelayNext) { if (touchPX == cur[PS4Button.TouchX] && touchPY == cur[PS4Button.TouchY]) { touchTracking = false; cmds.Add(new ScriptCommand("touch", 0)); } else { touchPX = cur[PS4Button.TouchX]; touchPY = cur[PS4Button.TouchY]; touchDelayNext += 200; } } } else if (cmds.Count == 0 && cur[PS4Button.Touch] == 0) { if (prv[PS4Button.TouchX] != cur[PS4Button.TouchX] || prv[PS4Button.TouchY] != cur[PS4Button.TouchY]) { touchTracking = true; touchPX = cur[PS4Button.TouchX]; touchPY = cur[PS4Button.TouchY]; touchDelayNext = 200; cmds.Add(new ScriptCommand("touch", 100)); } } // Write Script if (cmds.Count > 0) { if (timer.IsRunning) { cmds.Insert(0, new ScriptCommand("delay", (int)delay)); elapsedMs += delay; } else { timer.Restart(); elapsedMs = 0; } } if (cmds.Count > 0) { return(string.Join("\r\n", cmds) + "\r\n"); } else { return(null); } }