private SensorAcqResult RequestGprsSensor(Sensor si, IDtuConnection conn, int timeout) { var r = new SensorAcqResult { DtuCode = conn.DtuID, Sensor = si, Request = null, Response = null, Data = null, ErrorCode = (int)Errors.ERR_DEFAULT }; this.SendSensorCollectMsg(CollectState.Request, r); var senadapter = this._adapterManager.GetAdapter(si.ProtocolType); //var senadapter = _adapterManager.GetSensorAdapter(si.ProtocolType); if (senadapter == null) { return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_UNKNOW_PROTOCOL, "Sensor has no ProtocolCode")); } try { //senadapter.Request(ref r); var mp = new object[] { r }; object[] cp = null; CrossDomainCompiler.Call(senadapter.ScriptPath, typeof(ISensorAdapter), senadapter.ClassName, "Request", ref cp, ref mp); r = mp[0] as SensorAcqResult; } catch (Exception ex) { log.ErrorFormat("dtu{0} sensor:{1} create cmd error {2}", conn.DtuID, si.SensorID, ex.Message); return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_COMPILED, "internal error: SensorAdapter ERROR")); } if (r == null) { return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_CREATE_CMD, "create cmd error: SensorAdapter ERROR")); } r.RequestTime = DateTime.Now; if (r.ErrorCode != (int)Errors.SUCCESS) { return(CreateAcqResult(conn.DtuID, si, r.ErrorCode, "Sensor has no SensorAdapter")); } // send if (r.ErrorCode == (int)Errors.SUCCESS && r.Request != null) { DtuMsg msg = conn.Ssend(r.Request, timeout); if (msg == null) { return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_NULL_RECEIVED_DATA, "Receive buff is null !")); } r.ResponseTime = msg.Refreshtime; // 若结果错误, 该时间无意义。 // Parse if (msg.IsOK()) { try { r.Response = msg.Databuffer; if (r.Response != null) { //senadapter.ParseResult(ref r); var mp = new object[] { r }; object[] cp = null; CrossDomainCompiler.Call(senadapter.ScriptPath, typeof(ISensorAdapter), senadapter.ClassName, "ParseResult", ref cp, ref mp); r = mp[0] as SensorAcqResult; } else { log.ErrorFormat("sensor:{0}, error Received buff is null", r.Sensor.SensorID); } } catch (Exception ex) { log.ErrorFormat("dtu:{0},s[sid:{2}-m:{3}-c:{4}] , ERR_COMPILED {1}", conn.DtuID, ex.Message, si.SensorID, si.ModuleNo, si.ChannelNo); return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_COMPILED, "internal error: COMPILED ERROR")); } if (r == null) { return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_DATA_PARSEFAILED, "internal error: SensorAdapter ERROR")); } r.ErrorMsg = r.ErrorCode == (int)Errors.SUCCESS ? "OK!" : ValueHelper.CreateJsonResultStr(si.SensorID, EnumHelper.GetDescription((Errors)r.ErrorCode)); } else { r.ErrorCode = msg.ErrorCode; r.ErrorMsg = msg.ErrorMsg; } r.Elapsed = msg.Elapsed; } else { if (r.ErrorCode == (int)Errors.ERR_DEFAULT) { r.ErrorCode = (int)Errors.ERR_UNKNOW; } r.ErrorMsg = "create cmd error"; } if (r.ErrorCode != (int)Errors.SUCCESS) { r.Data = new SensorErrorData(r.Sensor.SensorID, r.ErrorCode); } this.SendSensorCollectMsg(CollectState.Response, r); return(r); }
public SensorErrorData(uint sensorId, int errorcode) { this._themsValues = null; this.JsonResultData = ValueHelper.CreateJsonResultStr(sensorId, EnumHelper.GetDescription((Errors)errorcode)); }