Commit 9a3e3595 authored by 潘栩锋's avatar 潘栩锋 🚴

GeneralGommunication 添加调试

FlyAd2021.B2 删除多余的机架修正
parent 0e52555c
...@@ -133,7 +133,7 @@ namespace GeneralGommunication ...@@ -133,7 +133,7 @@ namespace GeneralGommunication
public void RecMsg(byte[] recBuf) public void RecMsg(byte[] recBuf)
{ {
IsConnected = true; //IsConnected = true;
csm.IncRec(recBuf.Count()); csm.IncRec(recBuf.Count());
for (int i = 0; i < recBuf.Count(); i++) for (int i = 0; i < recBuf.Count(); i++)
...@@ -308,40 +308,13 @@ namespace GeneralGommunication ...@@ -308,40 +308,13 @@ namespace GeneralGommunication
ErrCnt++; ErrCnt++;
return; return;
} }
IsConnected = true;
ParsePackAfterCheckCRC8(pack); ParsePackAfterCheckCRC8(pack);
} }
protected abstract void ParsePackAfterCheckCRC8(byte[] buf); protected abstract void ParsePackAfterCheckCRC8(byte[] buf);
public string bytes2hexChar(byte[] pack)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pack.Count(); i++)
{
if (pack[i] >= 0x21 && pack[i] <= 0x7e)
{
//这个字符可以打印
sb.Append($"{pack[i]:X2}({(char)pack[i]}) ");
}
else {
sb.Append($"{pack[i]:X2}( ) ");
}
}
return sb.ToString();
}
public string bytes2hex(byte[] pack)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pack.Count(); i++)
{
sb.Append($"{pack[i]:X2} ");
}
return sb.ToString();
}
/// <summary> /// <summary>
/// 功能包解析 /// 功能包解析
/// </summary> /// </summary>
...@@ -374,7 +347,7 @@ namespace GeneralGommunication ...@@ -374,7 +347,7 @@ namespace GeneralGommunication
if (commReq.ResponseTotalLen + PrefixIndex > pack.Count()) if (commReq.ResponseTotalLen + PrefixIndex > pack.Count())
{ {
//失败,指令长度不对!! //失败,指令长度不对!!
logger.Error($"ACK expect:{commReq.PrefixString} len={commReq.ResponseTotalLen + 1}, but reponse len ={pack.Count()} reponse: {bytes2hexChar(pack)}"); logger.Error($"ACK expect:{commReq.PrefixString} len={commReq.ResponseTotalLen + 1}, but reponse len ={pack.Count()} reponse: {pack.ToString_Bytes2HexAndAscii()}");
ErrCnt++; ErrCnt++;
return false; return false;
} }
...@@ -384,7 +357,7 @@ namespace GeneralGommunication ...@@ -384,7 +357,7 @@ namespace GeneralGommunication
if (!commReq.IsMatch(commReq, pack, PrefixIndex, commReq.IsMatchContext, ref retData)) if (!commReq.IsMatch(commReq, pack, PrefixIndex, commReq.IsMatchContext, ref retData))
{ {
//回复对不上请求 //回复对不上请求
logger.Error($"ACK expect:{commReq.PrefixString} len={commReq.ResponseTotalLen + 1}, but reponse len ={pack.Count()} reponse: {bytes2hexChar(pack)}"); logger.Error($"ACK expect:{commReq.PrefixString} len={commReq.ResponseTotalLen + 1}, but reponse len ={pack.Count()} reponse: {pack.ToString_Bytes2HexAndAscii()}");
ErrCnt++; ErrCnt++;
return false; return false;
} }
...@@ -394,7 +367,7 @@ namespace GeneralGommunication ...@@ -394,7 +367,7 @@ namespace GeneralGommunication
if (!IsMatch(commReq, pack)) if (!IsMatch(commReq, pack))
{ {
//回复对不上请求 //回复对不上请求
logger.Error($"ACK expect:{commReq.PrefixString} len={commReq.ResponseTotalLen + 1}, but reponse len ={pack.Count()} reponse: {bytes2hexChar(pack)}"); logger.Error($"ACK expect:{commReq.PrefixString} len={commReq.ResponseTotalLen + 1}, but reponse len ={pack.Count()} reponse: {pack.ToString_Bytes2HexAndAscii()}");
ErrCnt++; ErrCnt++;
return false; return false;
} }
...@@ -502,7 +475,7 @@ namespace GeneralGommunication ...@@ -502,7 +475,7 @@ namespace GeneralGommunication
if (commReq == null) { if (commReq == null) {
//不能解析 //不能解析
logger.Error($"ACK multi reponse len ={pack.Count()} reponse: {bytes2hexChar(pack)}"); logger.Error($"ACK multi reponse len ={pack.Count()} reponse: {pack.ToString_Bytes2HexAndAscii()}");
ErrCnt++; ErrCnt++;
return false; return false;
} }
......
...@@ -76,6 +76,9 @@ namespace GeneralGommunication ...@@ -76,6 +76,9 @@ namespace GeneralGommunication
/// <param name="recBuf"></param> /// <param name="recBuf"></param>
public void RecMsg(byte[] recBuf) public void RecMsg(byte[] recBuf)
{ {
if (logger.IsDebugEnabled) {
logger.Debug($"REQ {recBuf.ToString_Bytes2Hex()}");
}
csm.IncRec(recBuf.Count()); csm.IncRec(recBuf.Count());
for (int i = 0; i < recBuf.Count(); i++) for (int i = 0; i < recBuf.Count(); i++)
...@@ -110,6 +113,7 @@ namespace GeneralGommunication ...@@ -110,6 +113,7 @@ namespace GeneralGommunication
Transactions.RemoveAt(0); Transactions.RemoveAt(0);
return GetSendPack(tran); return GetSendPack(tran);
} }
protected virtual byte[] GetSendPack(COMMREQInServer_Transaction tran) protected virtual byte[] GetSendPack(COMMREQInServer_Transaction tran)
...@@ -179,37 +183,6 @@ namespace GeneralGommunication ...@@ -179,37 +183,6 @@ namespace GeneralGommunication
} }
protected abstract void ParsePackAfterCheckCRC8(byte[] buf); protected abstract void ParsePackAfterCheckCRC8(byte[] buf);
public string bytes2hexChar(byte[] pack)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pack.Count(); i++)
{
if (pack[i] >= 0x21 && pack[i] <= 0x7e)
{
//这个字符可以打印
sb.Append($"{pack[i]:X2}({(char)pack[i]}) ");
}
else
{
sb.Append($"{pack[i]:X2}( ) ");
}
}
return sb.ToString();
}
public string bytes2hex(byte[] pack)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pack.Count(); i++)
{
sb.Append($"{pack[i]:X2} ");
}
return sb.ToString();
}
/// <summary> /// <summary>
/// 功能包解析 /// 功能包解析
...@@ -222,10 +195,18 @@ namespace GeneralGommunication ...@@ -222,10 +195,18 @@ namespace GeneralGommunication
if (commReq == null) if (commReq == null)
{ {
ErrCnt++; ErrCnt++;
logger.Error($"ACK 收到不支持的请求");
return; return;
} }
//还有B0 //还有B0
var response = commReq.ParseFuncPack(pack, commReq.Prefix.Count() + PrefixIndex); var response = commReq.ParseFuncPack(pack, commReq.Prefix.Count() + PrefixIndex);
if (logger.IsDebugEnabled) {
if(response!=null)
logger.Debug($"ACK {commReq.PrefixString} {response.ToString_Bytes2Hex()}");
else
logger.Debug($"ACK {commReq.PrefixString}");
}
AddTran(new COMMREQInServer_Transaction() AddTran(new COMMREQInServer_Transaction()
{ {
commReq = commReq, commReq = commReq,
......
...@@ -63,13 +63,29 @@ namespace GeneralGommunication ...@@ -63,13 +63,29 @@ namespace GeneralGommunication
public event DeviceConnectEventHander DeviceConnectEvent; public event DeviceConnectEventHander DeviceConnectEvent;
/// <summary>
/// 通讯中
/// </summary>
public bool IsBusy
{
get
{
if (currTran != null)
return true;
if (Transactions.Count() > 0)
return true;
return false;
}
}
System.Timers.Timer timerTimeOut;//等待回复超时 System.Timers.Timer timerTimeOut;//等待回复超时
public ModbusAsciiAsync() public ModbusAsciiAsync()
{ {
Transactions = new List<Modbus_Transaction>(); Transactions = new List<Modbus_Transaction>();
timerTimeOut = new System.Timers.Timer(); timerTimeOut = new System.Timers.Timer();
timerTimeOut.Interval = 500; timerTimeOut.Interval = 100;
timerTimeOut.AutoReset = false; timerTimeOut.AutoReset = false;
timerTimeOut.Elapsed += TimerTimeOut_Elapsed; timerTimeOut.Elapsed += TimerTimeOut_Elapsed;
} }
...@@ -112,6 +128,11 @@ namespace GeneralGommunication ...@@ -112,6 +128,11 @@ namespace GeneralGommunication
currTran = null; currTran = null;
retryCnt = 0; retryCnt = 0;
if (Transactions.Count() != 0) //还要其它需要发送
{
SendMsgEvent?.Invoke(this);
}
return; return;
} }
else else
...@@ -134,8 +155,8 @@ namespace GeneralGommunication ...@@ -134,8 +155,8 @@ namespace GeneralGommunication
if (logger.IsDebugEnabled) if (logger.IsDebugEnabled)
{ {
string msg = recBuf.Bytes2Hex(); string msg = recBuf.ToString_Bytes2Hex();
string msg2 = recBuf.Hex2Ascii(); string msg2 = recBuf.ToString_Bytes2Ascii();
logger.Debug($"ACK {msg} | {msg2}"); logger.Debug($"ACK {msg} | {msg2}");
} }
...@@ -193,8 +214,8 @@ namespace GeneralGommunication ...@@ -193,8 +214,8 @@ namespace GeneralGommunication
//调试: 打印发送信息 //调试: 打印发送信息
if (logger.IsDebugEnabled) if (logger.IsDebugEnabled)
{ {
string msg = tran.sendBuf.Bytes2Hex(); string msg = tran.sendBuf.ToString_Bytes2Hex();
string msg_ascii = tran.sendBuf.Hex2Ascii(); string msg_ascii = tran.sendBuf.ToString_Bytes2Ascii();
if (tran.desription == null) if (tran.desription == null)
logger.Debug($"REQ {msg} | {msg_ascii}"); logger.Debug($"REQ {msg} | {msg_ascii}");
else else
...@@ -239,7 +260,7 @@ namespace GeneralGommunication ...@@ -239,7 +260,7 @@ namespace GeneralGommunication
{ {
if (logger.IsErrorEnabled) if (logger.IsErrorEnabled)
{ {
string msg = currPack.Hex2Ascii(); string msg = currPack.ToString_Bytes2Ascii();
logger.Error($"ACK ID:{currTran.deviceNo} 指令码:{currTran.func:X2} {errMsg} {msg}"); logger.Error($"ACK ID:{currTran.deviceNo} 指令码:{currTran.func:X2} {errMsg} {msg}");
} }
ErrCnt++; ErrCnt++;
......
...@@ -67,6 +67,20 @@ namespace GeneralGommunication ...@@ -67,6 +67,20 @@ namespace GeneralGommunication
public event DeviceConnectEventHander DeviceConnectEvent; public event DeviceConnectEventHander DeviceConnectEvent;
/// <summary>
/// 通讯中
/// </summary>
public bool IsBusy
{
get {
if (currTran != null)
return true;
if (Transactions.Count() > 0)
return true;
return false;
}
}
System.Timers.Timer timer3d5t;//通讯包的 3.5T 时间间隔。 实际只是 15ms定时而已 System.Timers.Timer timer3d5t;//通讯包的 3.5T 时间间隔。 实际只是 15ms定时而已
System.Timers.Timer timerTimeOut;//等待回复超时 System.Timers.Timer timerTimeOut;//等待回复超时
...@@ -75,7 +89,7 @@ namespace GeneralGommunication ...@@ -75,7 +89,7 @@ namespace GeneralGommunication
Transactions = new List<Modbus_Transaction>(); Transactions = new List<Modbus_Transaction>();
timer3d5t = new System.Timers.Timer(); timer3d5t = new System.Timers.Timer();
timer3d5t.Interval = 35;//设得再小也没有用。 它只是用系统的15ms定时器触发而已。 timer3d5t.Interval = 30;//设得再小也没有用。 它只是用系统的15ms定时器触发而已。
timer3d5t.AutoReset = false;//触发一次 timer3d5t.AutoReset = false;//触发一次
timer3d5t.Elapsed += Timer3d5t_Elapsed; timer3d5t.Elapsed += Timer3d5t_Elapsed;
...@@ -93,6 +107,7 @@ namespace GeneralGommunication ...@@ -93,6 +107,7 @@ namespace GeneralGommunication
return false; return false;
} }
private void Timer3d5t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void Timer3d5t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
ParsePack(); ParsePack();
...@@ -102,13 +117,13 @@ namespace GeneralGommunication ...@@ -102,13 +117,13 @@ namespace GeneralGommunication
private void TimerTimeOut_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void TimerTimeOut_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
if (currTran == null)//没有数据需要发送 if (currTran == null)//没有数据需要发送,异常
return; return;
//大于1秒也没回复,异常 //大于1秒也没回复,异常
//重试2次 //重试2次
retryCnt++; retryCnt++;
logger.Error($"TIMEOUT 第{retryCnt}次超时");
if (retryCnt >= 2) if (retryCnt >= 2)
{ {
//已经发送了2次,放弃 //已经发送了2次,放弃
...@@ -127,9 +142,13 @@ namespace GeneralGommunication ...@@ -127,9 +142,13 @@ namespace GeneralGommunication
//删除发送给这个设备的全部指令 //删除发送给这个设备的全部指令
Transactions.RemoveAll(t => t.deviceNo == currTran.deviceNo); Transactions.RemoveAll(t => t.deviceNo == currTran.deviceNo);
currTran = null; currTran = null;
retryCnt = 0; retryCnt = 0;
if (Transactions.Count() != 0) //还要其它需要发送
{
SendMsgEvent?.Invoke(this);
}
return; return;
} }
else else
...@@ -147,16 +166,17 @@ namespace GeneralGommunication ...@@ -147,16 +166,17 @@ namespace GeneralGommunication
{ {
//停止超时检查 //停止超时检查
timerTimeOut.Stop(); timerTimeOut.Stop();
//15ms后再处理。
timer3d5t.Stop();
csm.IncRec(recBuf.Count()); csm.IncRec(recBuf.Count());
currPack.AddRange(recBuf); currPack.AddRange(recBuf);
if (logger.IsDebugEnabled) { if (logger.IsDebugEnabled) {
string msg = bytes2hex(recBuf); string msg = recBuf.ToString_Bytes2Hex();
logger.Debug($"ACK {msg}"); logger.Debug($"ACK {msg}");
} }
//15ms后再处理。
timer3d5t.Stop();
timer3d5t.Start(); timer3d5t.Start();
} }
...@@ -177,6 +197,7 @@ namespace GeneralGommunication ...@@ -177,6 +197,7 @@ namespace GeneralGommunication
currTran = Transactions.First(); currTran = Transactions.First();
Transactions.RemoveAt(0); Transactions.RemoveAt(0);
} }
else else
...@@ -191,7 +212,7 @@ namespace GeneralGommunication ...@@ -191,7 +212,7 @@ namespace GeneralGommunication
//调试: 打印发送信息 //调试: 打印发送信息
if(logger.IsDebugEnabled) if(logger.IsDebugEnabled)
{ {
string msg = bytes2hex(tran.sendBuf); string msg = tran.sendBuf.ToString_Bytes2Hex();
if (tran.desription == null) if (tran.desription == null)
logger.Debug($"REQ {msg}"); logger.Debug($"REQ {msg}");
else else
...@@ -230,16 +251,6 @@ namespace GeneralGommunication ...@@ -230,16 +251,6 @@ namespace GeneralGommunication
} }
} }
string bytes2hex(IEnumerable<byte> pack)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pack.Count(); i++)
{
sb.Append($"{pack.ElementAt(i):X2} ");
}
return sb.ToString();
}
/// <summary> /// <summary>
/// 已经收完一份数据,不会再有更多,包解析 /// 已经收完一份数据,不会再有更多,包解析
/// </summary> /// </summary>
...@@ -273,7 +284,7 @@ namespace GeneralGommunication ...@@ -273,7 +284,7 @@ namespace GeneralGommunication
if (currPack[1] != currTran.func) if (currPack[1] != currTran.func)
{ {
logger.Error($"ACK 错误码:{currPack[1]} 异常码:{currPack[2]}"); logger.Error($"ACK 错误码:{currPack[1]:X2} 异常码:{currPack[2]:X2}");
ErrCnt++; ErrCnt++;
currPack.Clear(); currPack.Clear();
TimerTimeOut_Elapsed(null, null); TimerTimeOut_Elapsed(null, null);
...@@ -294,9 +305,8 @@ namespace GeneralGommunication ...@@ -294,9 +305,8 @@ namespace GeneralGommunication
UInt16 rec_crc = currPack.ToUInt16_Big_Endian(currTran.expRecBytes - 2); UInt16 rec_crc = currPack.ToUInt16_Big_Endian(currTran.expRecBytes - 2);
if (crc != rec_crc) if (crc != rec_crc)
{ {
string errMsg = $"ACK 指令码:{currTran.func:X2} CRC 校验出错 接收:{rec_crc:X4} 计算:{crc:X4}"; logger.Error($"ACK 指令码:{currTran.func:X2} CRC 校验出错 接收:{rec_crc:X4} 计算:{crc:X4}");
logger.Error(errMsg); //DeviceConnectEvent?.Invoke(this, new DeviceConnectEventArgs() { deviceNo = currTran.deviceNo, isConnected = false, errMsg = errMsg });
DeviceConnectEvent?.Invoke(this, new DeviceConnectEventArgs() { deviceNo = currTran.deviceNo, isConnected = false, errMsg = errMsg });
ErrCnt++; ErrCnt++;
currPack.Clear(); currPack.Clear();
TimerTimeOut_Elapsed(null, null); TimerTimeOut_Elapsed(null, null);
......
This diff is collapsed.
...@@ -297,12 +297,13 @@ namespace GeneralGommunication ...@@ -297,12 +297,13 @@ namespace GeneralGommunication
#region 调试输出 #region 调试输出
/// <summary> /// <summary>
/// 调试打印出16进制 例如 3A 30 31 31 30 30 30 /// 调试打印出16进制 例如 3A 30 31 31 30 30 30
/// </summary> /// </summary>
/// <param name="pack"></param> /// <param name="pack"></param>
/// <returns></returns> /// <returns></returns>
public static string Bytes2Hex(this IEnumerable<byte> pack) public static string ToString_Bytes2Hex(this IEnumerable<byte> pack)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < pack.Count(); i++) for (int i = 0; i < pack.Count(); i++)
...@@ -316,7 +317,7 @@ namespace GeneralGommunication ...@@ -316,7 +317,7 @@ namespace GeneralGommunication
/// </summary> /// </summary>
/// <param name="pack"></param> /// <param name="pack"></param>
/// <returns></returns> /// <returns></returns>
public static string Hex2Ascii(this IEnumerable<byte> pack) public static string ToString_Bytes2Ascii(this IEnumerable<byte> pack)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < pack.Count(); i++) for (int i = 0; i < pack.Count(); i++)
...@@ -332,7 +333,26 @@ namespace GeneralGommunication ...@@ -332,7 +333,26 @@ namespace GeneralGommunication
} }
return sb.ToString(); return sb.ToString();
} }
public static string ToString_Bytes2HexAndAscii(this IEnumerable<byte> pack)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pack.Count(); i++)
{
byte b = pack.ElementAt(i);
if (b >= 0x20 && b <= 0x7E)
{
//这个字符可以打印
sb.Append($"{b:X2}({(char)b}) ");
}
else
{
sb.Append($"{b:X2}( ) ");
}
}
return sb.ToString();
}
#endregion #endregion
#region u16 to u32 or u16 to float #region u16 to u32 or u16 to float
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
<!--不合法颜色--> <!--不合法颜色-->
<SolidColorBrush x:Key="Brushes.Highlight" Color="Red"/> <SolidColorBrush x:Key="Brushes.Highlight" Color="Red"/>
<SolidColorBrush x:Key="Brushes.Text.White" Color="White"/>
<SolidColorBrush x:Key="Brushes.Text.Gray" Color="#FFC3C3C3"/>
<!--随机颜色--> <!--随机颜色-->
<x:Array x:Key="Brushes.Random" Type="SolidColorBrush"> <x:Array x:Key="Brushes.Random" Type="SolidColorBrush">
<SolidColorBrush>#2195f2</SolidColorBrush> <SolidColorBrush>#2195f2</SolidColorBrush>
......
...@@ -218,7 +218,7 @@ namespace FlyADBase ...@@ -218,7 +218,7 @@ namespace FlyADBase
/// <summary> /// <summary>
/// 系统剩余时间 /// 系统剩余时间
/// </summary> /// </summary>
public int Surplus { get; private set; } public int Surplus { get; private set; } = 10000;
/// <summary> /// <summary>
/// 系统授权码access[8] /// 系统授权码access[8]
/// </summary> /// </summary>
...@@ -331,7 +331,8 @@ namespace FlyADBase ...@@ -331,7 +331,8 @@ namespace FlyADBase
if (msg == null) if (msg == null)
return; return;
logger.Debug($"W {core.bytes2hex(msg)}"); //if(logger.IsDebugEnabled)
// logger.Debug($"W {msg.ToString_Bytes2HexAndAscii()}");
comm?.Write(msg); comm?.Write(msg);
}; };
...@@ -364,9 +365,6 @@ namespace FlyADBase ...@@ -364,9 +365,6 @@ namespace FlyADBase
PollModule.Current.Poll_Config(core.OnPoll_TimeOut, TimeSpan.FromSeconds(0.5)); PollModule.Current.Poll_Config(core.OnPoll_TimeOut, TimeSpan.FromSeconds(0.5));
core.PropertyChanged += Core_PropertyChanged;
Misc.BindingOperations.SetBinding(core, nameof(core.IsConnected), this, nameof(IsConnected)); Misc.BindingOperations.SetBinding(core, nameof(core.IsConnected), this, nameof(IsConnected));
Misc.BindingOperations.SetBinding(isReadyContext, nameof(isReadyContext.IsReady), this, nameof(IsReady)); Misc.BindingOperations.SetBinding(isReadyContext, nameof(isReadyContext.IsReady), this, nameof(IsReady));
...@@ -516,6 +514,16 @@ namespace FlyADBase ...@@ -516,6 +514,16 @@ namespace FlyADBase
} }
private void FlyAd2021_PropertyChanged(object sender, PropertyChangedEventArgs e) private void FlyAd2021_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == nameof(IsConnected))
{
if (IsConnected)
{
ConnectCnt++;
AfterConnected();
}
return;
}
if (bShieldSetValueEx) if (bShieldSetValueEx)
return; return;
...@@ -648,19 +656,6 @@ namespace FlyADBase ...@@ -648,19 +656,6 @@ namespace FlyADBase
} }
} }
private void Core_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(core.IsConnected))
{
if (core.IsConnected)
{
ConnectCnt++;
AfterConnected();
}
}
}
/// <summary> /// <summary>
/// 连接后初始化 /// 连接后初始化
...@@ -693,14 +688,14 @@ namespace FlyADBase ...@@ -693,14 +688,14 @@ namespace FlyADBase
{ {
//参数不保存在设备中, 保存在电脑。 //参数不保存在设备中, 保存在电脑。
//参数写入到设备。 //参数写入到设备。
core.BuildMultiTrans(() => //core.BuildMultiTrans(() =>
{ //{
core.SetSysParam_MotorType(MotorType, null, null); core.SetSysParam_MotorType(MotorType, null, null);
core.SetSysParam_Ratio01(Ratio01, null, null); core.SetSysParam_Ratio01(Ratio01, null, null);
core.SetSysParam_Ratio02(Ratio02, null, null); core.SetSysParam_Ratio02(Ratio02, null, null);
core.SetSysParam_Zero(PosOffset, null, null); core.SetSysParam_Zero(PosOffset, null, null);
core.SetSysParam_Jog(JogVelocity, null, null); core.SetSysParam_Jog(JogVelocity, null, null);
}); //});
//NotifyPropertyChanged(nameof(MotorType)); //NotifyPropertyChanged(nameof(MotorType));
//NotifyPropertyChanged(nameof(Ratio01)); //NotifyPropertyChanged(nameof(Ratio01));
//NotifyPropertyChanged(nameof(Ratio02)); //NotifyPropertyChanged(nameof(Ratio02));
......
...@@ -54,11 +54,6 @@ namespace FlyADBase ...@@ -54,11 +54,6 @@ namespace FlyADBase
/// </summary> /// </summary>
public bool IsFinish { get; set; } public bool IsFinish { get; set; }
/// <summary>
/// 机架修正
/// </summary>
public CorrectADsHandler CorrectADs { get; set; }
/// <summary> /// <summary>
/// ad滞后修正 单位ms /// ad滞后修正 单位ms
/// </summary> /// </summary>
...@@ -96,12 +91,12 @@ namespace FlyADBase ...@@ -96,12 +91,12 @@ namespace FlyADBase
DateTime lastGridTime; DateTime lastGridTime;
Stopwatch stopwatch_gridTime = new Stopwatch(); Stopwatch stopwatch_gridTime = new Stopwatch();
SGrid fGrid = new SGrid(); SGrid fGrid1 = new SGrid();
SGrid fGrid2 = new SGrid(); SGrid fGrid2 = new SGrid();
void advConstructor() void advConstructor()
{ {
fGrid.SetSize(GridLen); fGrid1.SetSize(GridLen);
fGrid2.SetSize(GridLen); fGrid2.SetSize(GridLen);
mTimeGridAdvHelper.Init(); mTimeGridAdvHelper.Init();
...@@ -143,7 +138,7 @@ namespace FlyADBase ...@@ -143,7 +138,7 @@ namespace FlyADBase
else if ((e.PropertyName == nameof(PosLen)) || else if ((e.PropertyName == nameof(PosLen)) ||
(e.PropertyName == nameof(PosOfGrid))) (e.PropertyName == nameof(PosOfGrid)))
{ {
fGrid.SetSize(GridLen); fGrid1.SetSize(GridLen);
fGrid2.SetSize(GridLen); fGrid2.SetSize(GridLen);
} }
} }
...@@ -223,7 +218,7 @@ namespace FlyADBase ...@@ -223,7 +218,7 @@ namespace FlyADBase
for (int i = 0; i < dat.Length; i++) for (int i = 0; i < dat.Length; i++)
{ {
int grid_num = grid_start + i; int grid_num = grid_start + i;
if (grid_num >= fGrid.data[index].Length) if (grid_num >= fGrid1.data[index].Length)
break; break;
if (GridSmooth > 0) if (GridSmooth > 0)
...@@ -235,11 +230,11 @@ namespace FlyADBase ...@@ -235,11 +230,11 @@ namespace FlyADBase
int idx = grid_num - GridSmooth + j; int idx = grid_num - GridSmooth + j;
if (idx < 0) if (idx < 0)
continue; continue;
if (idx >= fGrid.data[index].Length) if (idx >= fGrid1.data[index].Length)
break; break;
if (Misc.MyBase.ISVALIDATA(fGrid.data[index][idx])) if (Misc.MyBase.ISVALIDATA(fGrid1.data[index][idx]))
{ {
sum += fGrid.data[index][idx]; sum += fGrid1.data[index][idx];
cnt++; cnt++;
} }
} }
...@@ -250,11 +245,10 @@ namespace FlyADBase ...@@ -250,11 +245,10 @@ namespace FlyADBase
} }
else else
{ {
dat[i] = fGrid.data[index][grid_num]; dat[i] = fGrid1.data[index][grid_num];
} }
} }
CorrectADs?.Invoke(direction, grid_start, dat);
return; return;
} }
...@@ -265,7 +259,7 @@ namespace FlyADBase ...@@ -265,7 +259,7 @@ namespace FlyADBase
/// <param name="dat">grid 数据</param> /// <param name="dat">grid 数据</param>
public void GetGrid(Misc.DIRECTION direction, out int[] dat, out int[] dat2) public void GetGrid(Misc.DIRECTION direction, out int[] dat, out int[] dat2)
{ {
GetGrid(direction, 0, fGrid.data[0].Length, out dat, out dat2); GetGrid(direction, 0, fGrid1.data[0].Length, out dat, out dat2);
} }
#endregion #endregion
...@@ -314,7 +308,7 @@ namespace FlyADBase ...@@ -314,7 +308,7 @@ namespace FlyADBase
/// <summary> /// <summary>
/// <para>ScanMotion 使用。</para> /// <para>ScanMotion 使用。</para>
/// <para>给定按扫描的时间点。当探头停下来后,获取数据。</para> /// <para>给定按扫描的时间点。当探头停下来后,获取数据。</para>
/// <para>数据带机架修正,滞后修正,带运动方向。</para> /// <para>数据带滞后修正,带运动方向。</para>
/// </summary> /// </summary>
/// <param name="beginTime"></param> /// <param name="beginTime"></param>
/// <returns></returns> /// <returns></returns>
...@@ -341,22 +335,7 @@ namespace FlyADBase ...@@ -341,22 +335,7 @@ namespace FlyADBase
//数据滞后 //数据滞后
TimeGridAdvHelperExt.AdLagCorr(dataList, ref endTime, ADLag, AD2Lag); TimeGridAdvHelperExt.AdLagCorr(dataList, ref endTime, ADLag, AD2Lag);
//机架修正
if (CorrectADs != null)
{
for (int i = 0;i<dataList.Count();i++)
{
int index = i;
int gridIdx = dataList[index].pos / PosOfGrid;
var data = dataList[index];
data.ad = CorrectAD(direction, gridIdx, data.ad);
data.ad2 = CorrectAD(direction, gridIdx, data.ad2);
dataList[index] = data;
}
}
TimeGridAdv2EventArgs eventArgs = new TimeGridAdv2EventArgs(); TimeGridAdv2EventArgs eventArgs = new TimeGridAdv2EventArgs();
eventArgs.Direction = direction; eventArgs.Direction = direction;
...@@ -470,13 +449,6 @@ namespace FlyADBase ...@@ -470,13 +449,6 @@ namespace FlyADBase
if (grid_start >= GridLen) if (grid_start >= GridLen)
return; return;
//机架修正
if (CorrectADs != null)
{
CorrectADs(direction, grid_start, gridsOfAd1);
CorrectADs(direction, grid_start, gridsOfAd2);
}
int index = (direction == Misc.DIRECTION.BACKWARD) ? 1 : 0; int index = (direction == Misc.DIRECTION.BACKWARD) ? 1 : 0;
...@@ -485,7 +457,7 @@ namespace FlyADBase ...@@ -485,7 +457,7 @@ namespace FlyADBase
int len = grid_end - grid_start + 1; int len = grid_end - grid_start + 1;
var grid_data1 = fGrid.data[index]; var grid_data1 = fGrid1.data[index];
var grid_data2 = fGrid2.data[index]; var grid_data2 = fGrid2.data[index];
Array.Copy(gridsOfAd1, 0, grid_data1, grid_start, len); Array.Copy(gridsOfAd1, 0, grid_data1, grid_start, len);
...@@ -575,7 +547,7 @@ namespace FlyADBase ...@@ -575,7 +547,7 @@ namespace FlyADBase
//放入对应方向缓存区 //放入对应方向缓存区
int index = (direction == Misc.DIRECTION.BACKWARD) ? 1 : 0; int index = (direction == Misc.DIRECTION.BACKWARD) ? 1 : 0;
Array.Copy(gridsOfAd1, 0, fGrid.data[index], 0, GridLen); Array.Copy(gridsOfAd1, 0, fGrid1.data[index], 0, GridLen);
Array.Copy(gridsOfAd2, 0, fGrid2.data[index], 0, GridLen); Array.Copy(gridsOfAd2, 0, fGrid2.data[index], 0, GridLen);
...@@ -596,22 +568,6 @@ namespace FlyADBase ...@@ -596,22 +568,6 @@ namespace FlyADBase
grid_start = 0 grid_start = 0
}); });
} }
int CorrectAD(int gridIdx, int ad)
{
return CorrectAD(DIRECTION.FIX, gridIdx, ad);
}
int CorrectAD(Misc.DIRECTION direction, int gridIdx, int ad)
{
int[] d = new int[1];
d[0] = ad;
CorrectADs?.Invoke(direction, gridIdx, d);
return d[0];
}
} }
class CalSpeed class CalSpeed
......
...@@ -16,11 +16,6 @@ namespace FlyADBase ...@@ -16,11 +16,6 @@ namespace FlyADBase
/// </summary> /// </summary>
public interface IFlyADClientAdv : IFlyADClient public interface IFlyADClientAdv : IFlyADClient
{ {
/// <summary>
/// 机架修正
/// </summary>
CorrectADsHandler CorrectADs { get; set; }
/// <summary> /// <summary>
/// grid 滤波 /// grid 滤波
/// </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