Commit b8520ac4 authored by 潘栩锋's avatar 潘栩锋 🚴

修复 AD盒的参数,自动绑定Save,导致了经常写入参数文件。文件出错。

parent 91269545
...@@ -47,13 +47,6 @@ namespace FlyADBase ...@@ -47,13 +47,6 @@ namespace FlyADBase
/// </summary> /// </summary>
public int ConnectCnt { get; private set; } public int ConnectCnt { get; private set; }
/// <summary>
/// CRC
/// </summary>
public bool HasCRC { get; set; }
/// <summary> /// <summary>
/// 已经从AD盒获取全部当前数据 /// 已经从AD盒获取全部当前数据
/// </summary> /// </summary>
...@@ -504,11 +497,6 @@ namespace FlyADBase ...@@ -504,11 +497,6 @@ namespace FlyADBase
void FlyAD7_PropertyChanged(object sender, PropertyChangedEventArgs e) void FlyAD7_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == nameof(HasCRC))
{
if (conn != null)
conn.HasCRC = HasCRC;
}
if (bShieldSetValueEx) if (bShieldSetValueEx)
return; return;
...@@ -1334,7 +1322,7 @@ namespace FlyADBase ...@@ -1334,7 +1322,7 @@ namespace FlyADBase
} }
conn = CurrObjSys.Connect_to_Another_OBJSys(LocalEP, ID); conn = CurrObjSys.Connect_to_Another_OBJSys(LocalEP, ID);
conn.HasCRC = HasCRC; conn.HasCRC = false;
} }
/// <summary> /// <summary>
...@@ -1349,7 +1337,7 @@ namespace FlyADBase ...@@ -1349,7 +1337,7 @@ namespace FlyADBase
} }
conn = CurrObjSys.Connect_to_Another_OBJSys(LocalEP, ID); conn = CurrObjSys.Connect_to_Another_OBJSys(LocalEP, ID);
conn.HasCRC = HasCRC; conn.HasCRC = false;
} }
#endregion #endregion
...@@ -1761,19 +1749,34 @@ namespace FlyADBase ...@@ -1761,19 +1749,34 @@ namespace FlyADBase
class FlyAD7JsonDb class FlyAD7JsonDb
{ {
static Mapper Mapper { get; } = new AutoMapper.Mapper(new MapperConfiguration(c =>
{
c.CreateMap<FlyAD7, FlyAD7JsonDb>().ReverseMap();
}));
public static void Save(string jsonDbPath, FlyAD7 src) public static void Save(string jsonDbPath, FlyAD7 src)
{ {
if (string.IsNullOrEmpty(jsonDbPath)) if (string.IsNullOrEmpty(jsonDbPath))
return; return;
var p = FlyAD7JsonDb.Mapper.Map<FlyAD7JsonDb>(src); FlyAD7JsonDb jsonDb = new FlyAD7JsonDb()
{
Addr = src.Addr,
GridSmooth = src.GridSmooth,
ADLag = src.ADLag,
PosMin = src.PosMin,
PosMax = src.PosMax,
HasPosMaxMin = src.HasPosMaxMin,
HardwareVersion = src.HardwareVersion,
IsDevParamValid = src.IsDevParamValid,
MotorType = src.MotorType,
PosOfGrid = src.PosOfGrid,
Ratio01 = src.Ratio01,
Ratio02 = src.Ratio02,
PosOffset = src.PosOffset,
JogVelocity = src.JogVelocity
};
try try
{ {
File.WriteAllText(jsonDbPath, JsonConvert.SerializeObject(p, Formatting.Indented)); File.WriteAllText(jsonDbPath, JsonConvert.SerializeObject(jsonDb, Formatting.Indented));
} }
catch catch
{ {
...@@ -1790,8 +1793,24 @@ namespace FlyADBase ...@@ -1790,8 +1793,24 @@ namespace FlyADBase
if (File.Exists(jsonDbPath)) if (File.Exists(jsonDbPath))
{ {
string json = File.ReadAllText(jsonDbPath); string json = File.ReadAllText(jsonDbPath);
var p = JsonConvert.DeserializeObject<FlyAD7JsonDb>(json); FlyAD7JsonDb jsonDb = JsonConvert.DeserializeObject<FlyAD7JsonDb>(json);
Mapper.Map(p, src); src.Addr = jsonDb.Addr;
src.GridSmooth = jsonDb.GridSmooth;
src.ADLag = jsonDb.ADLag;
src.PosMin = jsonDb.PosMin;
src.PosMax = jsonDb.PosMax;
src.HasPosMaxMin = jsonDb.HasPosMaxMin;
src.HardwareVersion = jsonDb.HardwareVersion;
src.IsDevParamValid = jsonDb.IsDevParamValid;
src.MotorType = jsonDb.MotorType;
src.PosOfGrid = jsonDb.PosOfGrid;
src.Ratio01 = jsonDb.Ratio01;
src.Ratio02 = jsonDb.Ratio02;
src.PosOffset = jsonDb.PosOffset;
src.JogVelocity = jsonDb.JogVelocity;
return true; return true;
} }
} }
...@@ -1802,7 +1821,6 @@ namespace FlyADBase ...@@ -1802,7 +1821,6 @@ namespace FlyADBase
return false; return false;
} }
public string Addr = "192.168.251.10:20006"; public string Addr = "192.168.251.10:20006";
public bool HasCRC = false;
public int GridSmooth = 0; public int GridSmooth = 0;
public int ADLag = 0; public int ADLag = 0;
public int PosMin = 0; public int PosMin = 0;
...@@ -1846,7 +1864,7 @@ namespace FlyADBase ...@@ -1846,7 +1864,7 @@ namespace FlyADBase
/// </summary> /// </summary>
class SysTickContext class SysTickContext
{ {
Int32 systick_1st = 0; int systick_1st = 0;
DateTime dt_1st = DateTime.MinValue; DateTime dt_1st = DateTime.MinValue;
public event Action BeReseted; public event Action BeReseted;
public void Reset() public void Reset()
...@@ -1872,30 +1890,20 @@ namespace FlyADBase ...@@ -1872,30 +1890,20 @@ namespace FlyADBase
} }
int ms = systick - systick_1st; int ms = systick - systick_1st;
if ((ms < -1000) ||//时间被提前 if (Math.Abs(ms) > 2000)
(ms > 1000 * 60 * 3))//记录与新的timemark 相差3分钟,太大了,重新生成 timemark 与 dt 的关系
{ {
//时间偏差太大,重新生成 timemark 与 dt 的关系
//被复位了 //被复位了
BeReseted?.Invoke(); BeReseted?.Invoke();
dt_1st = DateTime.Now; Reset();
//毫秒级别取整 return ToDateTime(systick);
long tick = dt_1st.Ticks % TimeSpan.TicksPerMillisecond;
dt_1st -= TimeSpan.FromTicks(tick);
systick_1st = systick;
return dt_1st;
} }
DateTime dt = dt_1st.AddMilliseconds(ms); DateTime dt = dt_1st.AddMilliseconds(ms);
systick_1st = systick; systick_1st = systick;
dt_1st = dt; dt_1st = dt;
//if (Math.Abs((DateTime.Now-dt).TotalSeconds) > 5000)//滞后5s,异常
//{
// //修正
// dt = DateTime.Now;
// dt_1st = dt;
//}
return dt; return dt;
} }
} }
......
...@@ -22,11 +22,6 @@ namespace FlyADBase ...@@ -22,11 +22,6 @@ namespace FlyADBase
/// </summary> /// </summary>
int ConnectCnt { get; } int ConnectCnt { get; }
/// <summary>
/// CRC 校正
/// </summary>
bool HasCRC { get; set; }
/// <summary> /// <summary>
/// 连接 /// 连接
/// </summary> /// </summary>
......
...@@ -56,7 +56,6 @@ namespace FLY.Thick.Base.UI ...@@ -56,7 +56,6 @@ namespace FLY.Thick.Base.UI
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
#region 参数 #region 参数
public bool HasCRC { get; set; }
public IPEndPoint EP { get; set; } public IPEndPoint EP { get; set; }
public UInt16 PosOfGrid { get; set; } public UInt16 PosOfGrid { get; set; }
public MOTORTYPE MotorType { set; get; } public MOTORTYPE MotorType { set; get; }
...@@ -168,7 +167,6 @@ namespace FLY.Thick.Base.UI ...@@ -168,7 +167,6 @@ namespace FLY.Thick.Base.UI
//下面全部event保存在bindingConexts //下面全部event保存在bindingConexts
Misc.BindingOperations.StartMarkdownEvents(bindingConexts); Misc.BindingOperations.StartMarkdownEvents(bindingConexts);
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.HasCRC), this, nameof(HasCRC));
Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.Addr), this, () => Misc.BindingOperations.SetBinding(this.flyAdService, nameof(this.flyAdService.Addr), this, () =>
{ {
EP = Misc.StringConverter.ToIPEndPoint(this.flyAdService.Addr); EP = Misc.StringConverter.ToIPEndPoint(this.flyAdService.Addr);
...@@ -228,7 +226,6 @@ namespace FLY.Thick.Base.UI ...@@ -228,7 +226,6 @@ namespace FLY.Thick.Base.UI
if (!WdPassword.Authorize("FlyAd")) if (!WdPassword.Authorize("FlyAd"))
return; return;
flyAdService.HasCRC = this.HasCRC;
flyAdService.Addr = this.EP.ToString(); flyAdService.Addr = this.EP.ToString();
flyAdService.PosOfGrid = this.PosOfGrid; flyAdService.PosOfGrid = this.PosOfGrid;
flyAdService.MotorType = this.MotorType; flyAdService.MotorType = this.MotorType;
...@@ -244,7 +241,7 @@ namespace FLY.Thick.Base.UI ...@@ -244,7 +241,7 @@ namespace FLY.Thick.Base.UI
flyAdService.PosMax = this.PosMax; flyAdService.PosMax = this.PosMax;
flyAdService.HardwareVersion = HardwareVersion; flyAdService.HardwareVersion = HardwareVersion;
flyAdService.Apply();
{ {
string tit = (string)Application.Current.TryFindResource("str.PgFlyAd.ApplySuccessfully"); string tit = (string)Application.Current.TryFindResource("str.PgFlyAd.ApplySuccessfully");
FLY.ControlLibrary.Window_Tip.Show(tit, null, TimeSpan.FromSeconds(2)); FLY.ControlLibrary.Window_Tip.Show(tit, null, TimeSpan.FromSeconds(2));
......
...@@ -14,7 +14,6 @@ namespace FLY.Thick.Base.IService ...@@ -14,7 +14,6 @@ namespace FLY.Thick.Base.IService
public interface IFlyADService : INotifyPropertyChanged public interface IFlyADService : INotifyPropertyChanged
{ {
#region 参数 #region 参数
bool HasCRC { get; set; }
string Addr { get; set; } string Addr { get; set; }
UInt16 PosOfGrid { get; set; } UInt16 PosOfGrid { get; set; }
int PosLen { get; } int PosLen { get; }
...@@ -32,6 +31,12 @@ namespace FLY.Thick.Base.IService ...@@ -32,6 +31,12 @@ namespace FLY.Thick.Base.IService
int Verson { get; } int Verson { get; }
int HardwareVersion { get; set; } int HardwareVersion { get; set; }
/// <summary>
/// 参数保存
/// </summary>
void Apply();
/// <summary> /// <summary>
/// 获取序列码 /// 获取序列码
/// </summary> /// </summary>
......
...@@ -21,15 +21,6 @@ namespace FLY.Thick.Base.Server ...@@ -21,15 +21,6 @@ namespace FLY.Thick.Base.Server
const int MARKNO_PUSH_ACCESS = 2; const int MARKNO_PUSH_ACCESS = 2;
#endregion #endregion
public bool HasCRC {
get {
return flyad.HasCRC;
}
set
{
flyad.HasCRC = value;
}
}
public string Addr public string Addr
{ {
get get
...@@ -132,7 +123,7 @@ namespace FLY.Thick.Base.Server ...@@ -132,7 +123,7 @@ namespace FLY.Thick.Base.Server
} }
} }
public int ADLag public int ADLag
{ {
get { return flyad.ADLag; } get { return flyad.ADLag; }
set { set {
...@@ -164,7 +155,7 @@ namespace FLY.Thick.Base.Server ...@@ -164,7 +155,7 @@ namespace FLY.Thick.Base.Server
} }
} }
public int Verson public int Verson
{ {
get { return flyad.Version; } get { return flyad.Version; }
} }
...@@ -180,7 +171,7 @@ namespace FLY.Thick.Base.Server ...@@ -180,7 +171,7 @@ namespace FLY.Thick.Base.Server
{ {
} }
public void Init(IFlyADClientAdv flyad, AD2ThkHandler func_Ad2Thk) public void Init(IFlyADClientAdv flyad, AD2ThkHandler func_Ad2Thk)
{ {
ad2thk = func_Ad2Thk; ad2thk = func_Ad2Thk;
...@@ -195,7 +186,13 @@ namespace FLY.Thick.Base.Server ...@@ -195,7 +186,13 @@ namespace FLY.Thick.Base.Server
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(e.PropertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(e.PropertyName));
} }
} }
/// <summary>
/// 保存参数
/// </summary>
public void Apply()
{
flyad.Save();
}
/// <summary> /// <summary>
/// 获取序列码 /// 获取序列码
/// </summary> /// </summary>
......
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