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

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

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