/// <summary> /// 获取板实际温度 /// </summary> /// <param name="num">0,1</param> /// <returns></returns> public double GetTemperature(int num, int sensor_num = -1) { if (!connected) { throw new Exception("服务器未连接,尝试连接至服务器"); } uint address = 0xff71 + (uint)num; var re = WriteReadReg(address); if (sensor_num == -1) { return(TEMPERATUE.cal(BitConverter.ToUInt32(re.data, 8))); } else { var sensor = sensors.Find(delegate(Sensor s) { return(s.sensor_num == sensor_num); }); if (sensor == null) { throw new Exception("未在配置文件中找到编号为" + sensor_num.ToString() + "的Sensor,请检查config文件和填写的传感器编号"); } return(TEMPERATUE.cal_by_pts(BitConverter.ToUInt32(re.data, 8), sensor.temperature_paras)); } }
//读取配置文件 public void read_config(string file) { FileStream fs = new FileStream(file, FileMode.Open); StreamReader sr = new StreamReader(fs); string line; Sensor s = new Sensor(); while ((line = sr.ReadLine()) != null) { if (line.Replace(" ", "") == "")//除去空行 { continue; } if (line[0] == '#') { continue; } else if (line[0] == '@') { s = new Sensor(); try { s.sensor_num = int.Parse(line.Substring(1)); } catch (Exception ex) { Console.WriteLine(ex.Message); } sensors.Add(s); } else { try { string[] xy = line.Split(new char[] { ' ' }); s.temperature_points.Add(new PointF(float.Parse(xy[0]), float.Parse(xy[1]))); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } sr.Close(); fs.Close(); for (int i = 0; i < sensors.Count; i++) { if (sensors[i].temperature_points.Count < 2) { throw new Exception("传感器(编号:" + sensors[i].sensor_num.ToString() + ")没有足够的数据点,请检查config文件"); } sensors[i].temperature_paras = TEMPERATUE.cal_line(sensors[i].temperature_points); } return; }
/// <summary> /// 获取/设置板设定温度 /// </summary> /// <param name="num">0,1</param> /// <param name="set"></param> /// <param name="temperature">Unit:℃</param> /// <returns></returns> public double GetSetTemperature(int num, bool set = false, double temperature = -20) { if (!connected) { throw new Exception("服务器未连接,尝试连接至服务器,尝试连接至服务器"); } uint address = 0xff73 + (uint)num; Client.ReceiveEventArgs re; if (set) { re = WriteReadReg(address, false, (uint)TEMPERATUE.cal_inv(temperature)); } else { re = WriteReadReg(address); } return(TEMPERATUE.cal(BitConverter.ToUInt32(re.data, 8))); }