/// <summary> /// 读取配置信息 /// </summary> /// <param name="path"></param> public void GetParaJson(string path) { //string [] json =File .ReadAllLines (Application .StartupPath +@"\ParameterSet.ini"); string [] json = File.ReadAllLines(path); ParameterClass item = JsonConvert.DeserializeObject <ParameterClass>(json[0]); Para.LidarIP = item.LidarIP; Para.WathchDogTimeOut = item.WathchDogTimeOut; Para.PackType = item.PackType; Para.TheoryPointNum = item.TheoryPointNum; Para.XYERROR = item.XYERROR; Para.LENERROR = item.LENERROR; Para.ANGLEFILTER = item.ANGLEFILTER; Para.MAXDISTANCE = item.MAXDISTANCE; Para.FilterType = item.FilterType; Para.FilterWidth = item.FilterWidth; Para.TIMETOLERANCE = item.TIMETOLERANCE; if (Para.FilterType == "remission") { Para.AngleResolution = (float )1.600; //用于获取滤波后的定位数据 LidarMode.IsNavicationMode = true; } else if (Para.FilterType == "none") { Para.AngleResolution = (float )0.100; //用于获取未进行滤波的轮廓数据 LidarMode.IsNavicationMode = false; } float tem = 360 / Para.AngleResolution; Para.PackageNum = (int )tem; }
/// <summary> /// 设置信息 /// </summary> /// <param name="strjson"></param> /// <returns></returns> public bool WritePara(ParameterClass strjson) { try { FileStream file = new FileStream(Application.StartupPath + @"\ParameterSet.ini", FileMode.Create); string str = JsonConvert.SerializeObject(strjson); byte [] data = System.Text.ASCIIEncoding.Default.GetBytes(str); file.Write(data, 0, data.Length); file.Flush(); file.Close(); } catch (Exception ex) { return(false); } return(true); }
void Button2Click(object sender, EventArgs e) { if (ip.Text == "") { MessageBox.Show("请输入激光雷达IP地址"); return; } if (packagetype.Text == "") { MessageBox.Show("请输入激光雷达的数据输出类型!"); return; } if (watchdogtimeout.Text == "") { MessageBox.Show("请输入看门狗超时时间间隔!"); return; } if (maxpointnum.Text == "") { MessageBox.Show("请输入理论输出点的最大数量!"); return; } if (xyerror.Text == "") { MessageBox.Show("请输入识别阀值1!"); return; } if (lenerror.Text == "") { MessageBox.Show("请输入识别阀值2!"); return; } if (filtererror.Text == "") { MessageBox.Show("请输入滤波阀值!"); return; } if (maxdistance.Text == "") { MessageBox.Show("请输入激光识别的最大距离!"); return; } if (filtertype.Text == "") { MessageBox.Show("请选择滤波类型!"); return; } if (filterwidth.Text == "") { MessageBox.Show("请输入滤波宽度!"); return; } if (timetorance.Text == "") { MessageBox.Show("请输入反光柱识别是将容差!"); return; } ParameterClass item = new ParameterClass(); item.LidarIP = ip.Text; item.WathchDogTimeOut = Convert.ToInt32(watchdogtimeout.Text); item.PackType = packagetype.Text; item.MAXDISTANCE = Convert.ToInt32(maxdistance.Text); item.TheoryPointNum = Convert.ToInt32(maxpointnum.Text); item.XYERROR = Convert.ToInt32(xyerror.Text); item.LENERROR = Convert.ToInt32(lenerror.Text); item.ANGLEFILTER = Convert.ToInt32(filtererror.Text); item.FilterType = filtertype.Text; item.FilterWidth = Convert.ToInt32(filterwidth.Text); item.TIMETOLERANCE = Convert.ToInt32(timetorance.Text); if (item.WritePara(item)) { string path = Application.StartupPath + @"\ParameterSet.ini"; // item .GetParaJson(path ); MessageBox.Show("参数设置成功!"); return; } else { MessageBox.Show("参数设置失败!"); } }