private bool ParseText <T>(string Data, string Hash, out EDCResultData <T> Result) { try { var text = TrimData(Data); var hashText = ChecksumHelper.Hash(text); if (hashText != Hash) { Result = null; return(false); } Result = JsonConvert.DeserializeObject <EDCResultData <T> >(text); return(true); } catch { Result = null; return(false); } }
private EDCResultData <T> _SendAndRecieveData <T>(object Data = null) where T : class { try { _isRece = false; if (Data != null) { var json = JsonConvert.SerializeObject(Data, Formatting.None); var sendData = String.Format("00000000^{0}~@^{1}~@^{1}~@^{0}~00000000", ChecksumHelper.Hash(json), json); _SerialPort.Write(sendData); } while (!_isRece && (DateTime.Now - _BeginTime).TotalSeconds < _Timeout) { Thread.Sleep(500); } if (!_isRece) { _isRece = true; return(null); } _isRece = true; var result = _Result as EDCResultData <T>; if (result != null && result.ResCode == -1) { return(_SendAndRecieveData <T>(Data)); } return(result); } catch { _isRece = true; return(null); } }