public static void FreeRunRead(string port) { AdapterProtocol ap = new AdapterProtocol(port); Task.Run(() => { Console.WriteLine("press any key to cancel..."); Console.ReadKey(); ap.Cancel(); }); try { ap.Open(); while (true) { byte data = ap.GetByte(0); // no timeout Console.WriteLine("0x{0:X2}", data); } } catch (Exception ex) { Console.WriteLine("fatal error: {0}", ex.Message); } finally { Console.WriteLine("closed serial port"); ap.Close(); } }
public void InitSession() { // send ready req opcode List <byte> cmd = new List <byte>(); cmd.Add(READY_REQ_OPCODE); //Console.WriteLine("kfd: ready req"); //Console.WriteLine("kfd -> mr: 0x{0:X2}", temp); Protocol.SendData(cmd); // receive ready general mode opcode //Console.WriteLine("mr: ready general mode"); byte rsp = Protocol.GetByte(TWI_TIMEOUT); //Console.WriteLine("mr -> kfd: 0x{0:X2}", temp); if (rsp != READY_GENERAL_MODE_OPCODE) { throw new Exception("mr: unexpected opcode"); } }
public void InitSession() { // send ready req opcode List <byte> cmd = new List <byte>(); cmd.Add(OPCODE_READY_REQ); Log.Debug("kfd: ready req"); Log.Debug("kfd -> mr: {0}", Utility.DataFormat(cmd)); Protocol.SendData(cmd); // receive ready general mode opcode Log.Debug("mr: ready general mode"); byte rsp = Protocol.GetByte(TIMEOUT_STD); Log.Debug("kfd -> mr: {0}", Utility.DataFormat(rsp)); if (rsp != OPCODE_READY_GENERAL_MODE) { throw new Exception("mr: unexpected opcode"); } }