Commit 35da02e8 authored by 潘栩锋's avatar 潘栩锋 🚴

优化 AD盒参数保存在电脑,每次connect成功,写参数到设备

parent 3cb0dbf0
...@@ -10,6 +10,7 @@ using System.IO; ...@@ -10,6 +10,7 @@ using System.IO;
using Misc; using Misc;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using Newtonsoft.Json;
namespace FlyADBase namespace FlyADBase
{ {
...@@ -74,6 +75,11 @@ namespace FlyADBase ...@@ -74,6 +75,11 @@ namespace FlyADBase
bool isReadyGetIO = false; bool isReadyGetIO = false;
static FlyAD7()
{
propertyName_save = FlyAD7JsonDb.GetMemberNames();
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -191,6 +197,11 @@ namespace FlyADBase ...@@ -191,6 +197,11 @@ namespace FlyADBase
conn.HasCRC = HasCRC; conn.HasCRC = HasCRC;
} }
/// <summary> /// <summary>
/// 只要connect成功,获取systick被复位,都会从AD盒设备读取参数;
/// 否则, 设置参数 到 AD盒
/// </summary>
public bool IsReadParamFromDev { get; set; }
/// <summary>
/// 已经从AD盒获取全部当前数据 /// 已经从AD盒获取全部当前数据
/// </summary> /// </summary>
public bool IsReady { get; protected set; } public bool IsReady { get; protected set; }
...@@ -355,7 +366,48 @@ namespace FlyADBase ...@@ -355,7 +366,48 @@ namespace FlyADBase
ID, ID,
0xffffffff, 0xffffffff,
SENSE_CONFIG.ADD); SENSE_CONFIG.ADD);
UpdateParam(); if (IsReadParamFromDev)
{
//读取全部参数!!!!!
//OBJ_SYS_DATA
CurrObjSys.GetValueEx(
conn,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_SYSPARAM);
CurrObjSys.GetValueEx(
conn,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_ZERO_POS);
//DRIVE_MAN
CurrObjSys.GetValueEx(
conn,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.GET_DRIVEPARAM);
}
else
{
//参数不保存在设备中, 保存在电脑。
//参数写入到设备。
NotifyPropertyChanged(nameof(MotorType));
NotifyPropertyChanged(nameof(PosOfGrid));
NotifyPropertyChanged(nameof(Ratio01));
NotifyPropertyChanged(nameof(Ratio02));
NotifyPropertyChanged(nameof(PosOffset));
NotifyPropertyChanged(nameof(JogVelocity));
}
CurrObjSys.GetValueEx(
conn,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_SYSINFO);
isReadyGetState = false; isReadyGetState = false;
isReadyGetPos1AD1 = false; isReadyGetPos1AD1 = false;
...@@ -1050,6 +1102,7 @@ namespace FlyADBase ...@@ -1050,6 +1102,7 @@ namespace FlyADBase
/// </summary> /// </summary>
public void UpdateParam() public void UpdateParam()
{ {
//OBJ_SYS_DATA //OBJ_SYS_DATA
CurrObjSys.GetValueEx( CurrObjSys.GetValueEx(
conn, conn,
...@@ -1063,11 +1116,7 @@ namespace FlyADBase ...@@ -1063,11 +1116,7 @@ namespace FlyADBase
ID, ID,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_ZERO_POS); FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_ZERO_POS);
CurrObjSys.GetValueEx(
conn,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_SYSINFO);
//DRIVE_MAN //DRIVE_MAN
CurrObjSys.GetValueEx( CurrObjSys.GetValueEx(
...@@ -1075,6 +1124,13 @@ namespace FlyADBase ...@@ -1075,6 +1124,13 @@ namespace FlyADBase
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.ID, FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.ID,
ID, ID,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.GET_DRIVEPARAM); FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.GET_DRIVEPARAM);
CurrObjSys.GetValueEx(
conn,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_SYSINFO);
} }
#region 运动参数 #region 运动参数
...@@ -1734,9 +1790,8 @@ namespace FlyADBase ...@@ -1734,9 +1790,8 @@ namespace FlyADBase
#endregion #endregion
#endregion #endregion
private static string[] propertyName_save = new string[] { private static string[] propertyName_save;
"LocalEP","HasCRC","GridSmooth","IsCalSpeed"
};
string defaultPath = "flyad.json"; string defaultPath = "flyad.json";
private string jsonDbPath; private string jsonDbPath;
public bool Load() { public bool Load() {
...@@ -1747,30 +1802,12 @@ namespace FlyADBase ...@@ -1747,30 +1802,12 @@ namespace FlyADBase
this.jsonDbPath = jsonDbPath; this.jsonDbPath = jsonDbPath;
this.PropertyChanged -= FlyAD7_PropertyChanged2; this.PropertyChanged -= FlyAD7_PropertyChanged2;
bool ret = Load2(); bool ret = FlyAD7JsonDb.Load(jsonDbPath, this);
this.PropertyChanged += FlyAD7_PropertyChanged2; this.PropertyChanged += FlyAD7_PropertyChanged2;
return ret; return ret;
} }
bool Load2() {
if (!File.Exists(jsonDbPath))
return false;
string json = File.ReadAllText(jsonDbPath);
try
{
var db = Newtonsoft.Json.JsonConvert.DeserializeObject<FlyAD7JsonDb>(json);
this.LocalEP = Misc.StringConverter.ToIPEndPoint(db.LocalEP);
this.GridSmooth = db.GridSmooth;
this.HasCRC = db.HasCRC;
this.IsCalSpeed = db.IsCalSpeed;
}
catch(Exception e) {
return false;
}
return true;
}
private void FlyAD7_PropertyChanged2(object sender, PropertyChangedEventArgs e) private void FlyAD7_PropertyChanged2(object sender, PropertyChangedEventArgs e)
{ {
if (propertyName_save.Contains(e.PropertyName)) { if (propertyName_save.Contains(e.PropertyName)) {
...@@ -1781,31 +1818,96 @@ namespace FlyADBase ...@@ -1781,31 +1818,96 @@ namespace FlyADBase
} }
} }
void Save() { bool Save() {
if (string.IsNullOrEmpty(jsonDbPath)) return FlyAD7JsonDb.Save(jsonDbPath, this);
return; }
FlyAD7JsonDb db = new FlyAD7JsonDb()
}
public class FlyAD7JsonDb
{
public static bool Save(string jsonDbPath, FlyAD7 src)
{ {
LocalEP = LocalEP.ToString(), if (string.IsNullOrEmpty(jsonDbPath))
GridSmooth = GridSmooth, return false;
HasCRC = HasCRC, FlyAD7JsonDb jsonDb = new FlyAD7JsonDb()
IsCalSpeed = IsCalSpeed {
LocalEP = src.LocalEP.ToString(),
GridSmooth = src.GridSmooth,
HasCRC = src.HasCRC,
IsCalSpeed = src.IsCalSpeed,
MotorType = src.MotorType,
PosOfGrid = src.PosOfGrid,
Ratio01 = src.Ratio01,
Ratio02 = src.Ratio02,
PosOffset = src.PosOffset,
JogVelocity = src.JogVelocity
}; };
try
{
File.WriteAllText(jsonDbPath, JsonConvert.SerializeObject(jsonDb, Formatting.Indented));
return true;
}
catch
{
//异常,没有json 编码失败
return false;
}
}
public static bool Load(string jsonDbPath, FlyAD7 src)
{
if (string.IsNullOrEmpty(jsonDbPath))
return false;
try
{
if (File.Exists(jsonDbPath))
{
string json = File.ReadAllText(jsonDbPath);
var jsonDb = JsonConvert.DeserializeObject<FlyAD7JsonDb>(json);
src.LocalEP = Misc.StringConverter.ToIPEndPoint(jsonDb.LocalEP);
src.GridSmooth = jsonDb.GridSmooth;
src.HasCRC = jsonDb.HasCRC;
src.IsCalSpeed = jsonDb.IsCalSpeed;
src.MotorType = jsonDb.MotorType;
src.PosOfGrid = jsonDb.PosOfGrid;
src.Ratio01 = jsonDb.Ratio01;
src.Ratio02 = jsonDb.Ratio02;
src.PosOffset = jsonDb.PosOffset;
src.JogVelocity = jsonDb.JogVelocity;
string json= Newtonsoft.Json.JsonConvert.SerializeObject(db); return true;
File.WriteAllText(jsonDbPath, json);
} }
}
catch
{
//异常,没有json 解码失败
}
return false;
} }
public class FlyAD7JsonDb public static string[] GetMemberNames()
{ {
var type = typeof(FlyAD7JsonDb);
return type.GetMembers().Select(mi => mi.Name).ToArray();
}
public string LocalEP = "192.168.251.10:20006"; public string LocalEP = "192.168.251.10:20006";
public bool HasCRC = false; public bool HasCRC = false;
public int GridSmooth = 0; public int GridSmooth = 0;
public bool IsCalSpeed = true; public bool IsCalSpeed = true;
//非常必要的参数
public MOTORTYPE MotorType = MOTORTYPE.SERVO;
public UInt16 PosOfGrid = 10;
public UInt16 Ratio01 = 4;
public UInt16 Ratio02 = 1;
public Int16 PosOffset = 0;
public UInt32 JogVelocity = 1000;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment