public override DetectData receiveData(int extension, int group) { DetectData resultData = new DetectData(); LogHelper.WriteLog4("开始获取数据", LogType.Info); LogHelper.WriteLog4("获取温湿度", LogType.Info); var humiStr = sendCommand(getHumiCommand(extension), getHumiTimeOut); resultData.humiData = humiStr; LogHelper.WriteLog4("获取温度", LogType.Info); string tempStr = ""; for (int i = 1; i <= group; i++) { int detectCount = 0; string groupCommand = getTempCommand(extension, i); var groupTemp = "_"; LogHelper.WriteLog4($"获取第{i}间温度", LogType.Info); while (detectCount <= 3) { var groupTemps = sendCommand(groupCommand, getTempTimeOut);; if (!string.IsNullOrEmpty(groupTemps) && groupTemps.Length > 18) { groupTemp = groupTemps; break; } detectCount++; } tempStr += groupTemp + ","; } resultData.tempData = tempStr; return(resultData); }
public DetectController() : base("/detect") { Get["/{providerName}/{extension}/{group}"] = p => DetectService(p.providerName, p.extension, p.group); Get["/test"] = p => { //return RequestOK("成功"); DetectData d1 = new DetectData(); d1.humiData = "abc"; d1.tempData = "345"; return(RequestOK(d1)); }; Get["/test2"] = p => { //return RequestOK("成功"); TestData d1 = new TestData(); d1.humi = new Dictionary <int, string>(); d1.humi.Add(1, "humi1"); d1.humi.Add(2, "humi2"); return(RequestOK(d1)); }; }