async Task <string> BeginRead() { string err; string Title = ""; if (!service.OpenDevice(out err)) { Debug.WriteLine(err); return(err); } //service.LightOff(out err); Thread.Sleep(1000); if (!service.LightOn(out err)) { Debug.WriteLine(err); return(err); } int n = 0; string result = null; await Task.Run(() => { while (true) { n++; result = service.MessageRead(out err); if (!string.IsNullOrEmpty(err)) { Debug.WriteLine(err); return(err); } if (result != null) { service.LightOff(out err); Debug.WriteLine(result); return(result); } Thread.Sleep(100); } }); return(result); }
/// <summary> 初始化 </summary> public bool Init(out string err) { err = string.Empty; if (!service.OpenDevice(out err)) { Debug.WriteLine(err); return false; } Thread.Sleep(1000); if (!service.LightOn(out err)) { Debug.WriteLine(err); return false; } return true; }
string BeginRead(out string err) { int n = 0; string Title = ""; VGuangService service = new VGuangService(); service.OpenDevice(out err); //service.LightOff(out err); Thread.Sleep(1000); //var t = new Thread(() => //{ Debug.WriteLine(err); service.LightOn(out err); Debug.WriteLine(err); while (true) { n++; var item = service.MessageRead(out err); Debug.WriteLine(err); Title = item ?? err; if (item != null) { //service.LightOff(out err); //Debug.WriteLine(item); return(item); //break; } Thread.Sleep(100); //Debug.WriteLine(n); } }
/// <summary> 内存循环读取 </summary> public void TestMethod3() { // Message:存在问题是读了一段时间后就不再读取了 string err; int n = 0; string Title = ""; VGuangService service = new VGuangService(); service.OpenDevice(out err); //service.LightOff(out err); Thread.Sleep(1000); Debug.WriteLine(err); service.LightOn(out err); Debug.WriteLine(err); while (true) { n++; var item = service.MessageRead(out err); Debug.WriteLine(err); Title = item ?? err; if (item != null) { //service.LightOff(out err); Debug.WriteLine(item); //break; } Thread.Sleep(100); Debug.WriteLine(n); } }