Commit 51ba77ec authored by 潘栩锋's avatar 潘栩锋 🚴

1.优化 IFixService 改为轮询模式, 使用 FObj.Reflect 作为服务代理

2.添加 测试模式,DynArea.IsTest, 就是 B=100, 不需要找边界。 用于没有膜时,测试机架。
3.删除 系统参数界面 删除 编码器2 放大设置
parent aaba269c
......@@ -227,8 +227,8 @@
</Compile>
<Compile Include="UiModule\FixGraph\FixGraphItemParam.cs" />
<Compile Include="UiModule\FixGraph\FixGraphParams.cs" />
<Compile Include="UiModule\FixGraph\FixGraphViewModel.cs" />
<Compile Include="UiModule\FixGraph\FixGraphViewModel_UnitTest.cs" />
<Compile Include="UiModule\FixGraph\FixGraphVm.cs" />
<Compile Include="UiModule\FixGraph\FixGraphVmUt.cs" />
<Compile Include="UiModule\FixGraph\PgFixAnalyze.xaml.cs">
<DependentUpon>PgFixAnalyze.xaml</DependentUpon>
</Compile>
......
......@@ -117,15 +117,6 @@
</TextBlock>
</StackPanel>
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="编码器2放大" />
<StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding Encoder2_comp}" HorizontalAlignment="Left"/>
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
<Run Text="倍"/>
</TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding IsSelected,Converter={StaticResource visbilityconv},ConverterParameter=Collapsed, ElementName=comboBoxotem_ROUND}">
......
......@@ -22,16 +22,21 @@
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Border Style="{StaticResource BorderStyle_module}" Name="Border_AD" >
<Border Style="{StaticResource Styles.Module.Border}" Name="Border_AD" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid x:Name="grid_initparam"/>
<Border Background="{StaticResource Background_Title}" CornerRadius="3" Height="130" >
<Border Background="{StaticResource Brushes.TitleBar.Background}" CornerRadius="3" Height="130" >
<Grid>
<Viewbox Margin="10">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-4" Visibility="{Binding IsTest,Converter={StaticResource visbilityconv}}"
Style="{StaticResource Styles.Card.Title}"
Background="{StaticResource MahApps.Brushes.SemiTransparent}"
Foreground="{StaticResource Brushes.TitleBar.Foreground}"
Text="测试模式" />
<Viewbox Margin="10">
<TextBlock Text="{Binding Thk,StringFormat={}{0:F1}}" Foreground="White" FontSize="30" FontWeight="Bold" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Viewbox>
<TextBlock Text="{Binding ControllerState,Converter={StaticResource ctrlstateconv}}" FontSize="12" FontFamily="Microsoft Sans Serif" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="White" Margin="5"/>
......
......@@ -31,7 +31,7 @@ namespace FLY.Thick.Base.UI.UiModule
/// </summary>
public partial class FixGraph : UserControl
{
FixGraphViewModel viewModel;
FixGraphVm viewModel;
FixGraphItemParam graphparam;
public FixGraph()
{
......@@ -51,7 +51,7 @@ namespace FLY.Thick.Base.UI.UiModule
}
//获取设备
viewModel = new FixGraphViewModel();
viewModel = new FixGraphVm();
viewModel.Init(fixService, graphparam);
this.DataContext = viewModel;
......
......@@ -13,7 +13,7 @@ using FLY.Thick.Base.UI;
namespace FLY.Thick.Base.UI.UiModule
{
public class FixGraphViewModel : ISaveManager, INotifyPropertyChanged
public class FixGraphVm : ISaveManager, INotifyPropertyChanged
{
#region 图表控制
/// <summary>
......@@ -113,10 +113,10 @@ namespace FLY.Thick.Base.UI.UiModule
/// </summary>
const int values_cap = 1000;
IFixService mFixService;
IFixService fixService;
FixGraphItemParam graphparam;
public FixGraphViewModel()
DateTime updateTime;
public FixGraphVm()
{
#region 与数据无关界面参数
XFormatter = (x) =>
......@@ -132,18 +132,31 @@ namespace FLY.Thick.Base.UI.UiModule
}
public void Init(IFixService fixService, FixGraphItemParam bulkGraphItemFix)
{
mFixService = fixService;
this.fixService = fixService;
graphparam = bulkGraphItemFix;
Update4Graphparam();
graphparam.PropertyChanged += Graphparam_PropertyChanged;
mFixService.RegistTimeGridEvent(new FixEventHandler(mFixService_TimeGridEvent));
this.fixService.PropertyChanged += FixService_PropertyChanged;
this.PropertyChanged += FixGraphViewModel_PropertyChanged;
}
private void FixService_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(fixService.UpdateTime))
{
//检测是哪个变化了
if (fixService.UpdateTime != updateTime)
{
//变化了
//向服务获取数据
fixService.GetFixDatas(fixService_GetFixDatas, this);
}
}
}
private void FixGraphViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "AutoTarget")
......@@ -358,18 +371,19 @@ namespace FLY.Thick.Base.UI.UiModule
List<double> data_mix = new List<double>();
#endregion
void mFixService_TimeGridEvent(object sender, FixEventArgs e)
void fixService_GetFixDatas(object asyncContext, object retData)
{
var reponse = retData as GetFixDatasReponse;
if (IsPaused)
return;
//输入1.28ms 的数据, 输出 混合为mix,间隔为 interval 的数据
List<double> data_out = new List<double>();
for (int i = 0; i < e.thicks.Length; i++)
for (int i = 0; i < reponse.thicks.Length; i++)
{
double v = (IsADMode) ? e.ADs[i] : e.thicks[i];
double v = (IsADMode) ? reponse.ADs[i] : reponse.thicks[i];
data_interval.Add(v);
data_interval_totaltime += e.ts;
data_interval_totaltime += reponse.ts;
if (data_interval_totaltime >= Interval)
{
......@@ -387,10 +401,11 @@ namespace FLY.Thick.Base.UI.UiModule
if (data_out.Count() > 0)
{
Time = e.time;
Time = reponse.time;
AddPoint(data_out);
}
}
void UpdateStat()
{
if (mDatas.Count() == 0)
......
......@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace FLY.Thick.Base.UI.UiModule
{
public class FixGraphViewModel_UnitTest : INotifyPropertyChanged
public class FixGraphVmUt : INotifyPropertyChanged
{
#region 图表控制
public double YMax { get; set; } = double.NaN;
......@@ -56,7 +56,7 @@ namespace FLY.Thick.Base.UI.UiModule
const int TotalValueCountInView = 1000;
public FixGraphViewModel_UnitTest()
public FixGraphVmUt()
{
#region 与数据无关界面参数
XFormatter = (x) =>
......
......@@ -9,84 +9,29 @@ using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using FObjBase.Reflect;
namespace FLY.Thick.Base.Client
{
public class FixServiceClient : FObjServiceClient, IFixService
public class FixServiceClient : FObjBase.Reflect.Reflect_SeviceClient, IFixService
{
protected override Type InterfaceType => typeof(IFixService);
public FixServiceClient(UInt32 serviceId) : base(serviceId) { }
public FixServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
#region IFlyAD接口
/// <summary>
/// 注册timegrid 事件
/// </summary>
/// <param name="handler"></param>
public void RegistTimeGridEvent(FixEventHandler handler)
{
FixEvent += handler;
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID),
SENSE_CONFIG.ADD);
}
/// <summary>
/// 关闭注册timegrid 事件
/// </summary>
/// <param name="handler"></param>
public void UnRegistTimeGridEvent(FixEventHandler handler)
{
FixEvent -= handler;
if (FixEvent == null)
{
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID),
SENSE_CONFIG.REMOVE);
}
}
event FixEventHandler FixEvent;
public DateTime UpdateTime { get; set; }
#endregion
public override void ConnectNotify(IFConn from)
[Call(typeof(GetFixDatasReponse))]
public void GetFixDatas(AsyncCBHandler asyncDelegate, object asyncContext)
{
base.ConnectNotify(from);
if (from.IsConnected)
{
//设置推送
if (FixEvent != null)
{
UInt32 sense_mask = Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID);
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
sense_mask,
SENSE_CONFIG.ADD);
}
}
Call(nameof(GetFixDatas), null, asyncDelegate, asyncContext);
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
switch (infoid)
{
case FIX_OBJ_INTERFACE.PUSH_TIMEGRID:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FixEventArgs>(json);
FixEvent?.Invoke(this, p);
} break;
}
}
}
}
\ No newline at end of file
......@@ -116,6 +116,11 @@ namespace FLY.Thick.Base.Common
/// </summary>
public int AutoScanCounter { get; set; } = 5;
/// <summary>
/// 测试模式
/// </summary>
public bool IsTest { get; set; }
#endregion
#region IO
......
......@@ -58,6 +58,7 @@
<Compile Include="Client\FlyADServiceClient.cs" />
<Compile Include="Client\GageInfoServiceClient.cs" />
<Compile Include="Client\GetSampleServiceClient.cs" />
<Compile Include="Client\FlyAdIoDefineServiceClient.cs" />
<Compile Include="Client\InitParamServiceClient.cs" />
<Compile Include="Client\RejectServiceClient.cs" />
<Compile Include="Client\ScanCorrServiceClient.cs" />
......@@ -78,6 +79,7 @@
<Compile Include="IService\IBorderSearchService.cs" />
<Compile Include="IService\ICurveService.cs" />
<Compile Include="IService\IFixService.cs" />
<Compile Include="IService\IFlyAdIoDefineService.cs" />
<Compile Include="IService\IFlyADService.cs" />
<Compile Include="IService\IGageInfoService.cs" />
<Compile Include="IService\IGetSampleService.cs" />
......@@ -93,8 +95,6 @@
<Compile Include="OBJ_INTERFACE\GETSAMPLE_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\SCANCORR_OBJ_INTERFACE.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.OBJProxy\Fix_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\Gage_ObjProxy.cs" />
<Compile Include="Server.OBJProxy\GetSample_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\ScanCorr_OBJProxy.cs" />
<Compile Include="Server\BoltMapImg.cs" />
......
using System;
using FObjBase;
using FObjBase.Reflect;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
......@@ -8,23 +11,16 @@ namespace FLY.Thick.Base.IService
/// <summary>
/// 定点测量服务
/// </summary>
public interface IFixService
public interface IFixService : INotifyPropertyChanged
{
/// <summary>
/// 注册timegrid 事件
/// </summary>
/// <param name="handler"></param>
void RegistTimeGridEvent(FixEventHandler handler);
/// <summary>
/// 关闭注册timegrid 事件
/// </summary>
/// <param name="handler"></param>
void UnRegistTimeGridEvent(FixEventHandler handler);
DateTime UpdateTime { get; }
[Call(typeof(GetFixDatasReponse))]
void GetFixDatas(AsyncCBHandler asyncDelegate, object asyncContext);
}
public delegate void FixEventHandler(object sender, FixEventArgs e);
public class FixEventArgs : EventArgs
public class GetFixDatasReponse
{
/// <summary>
/// 数据, AD数据!!!!!
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.Server;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.Common;
namespace FLY.Thick.Base.Server.OBJProxy
{
public class Fix_OBJProxy: FObj
{
#region 延时推送 MARKNO
#endregion
IFixService mFix;
public Fix_OBJProxy(int objsys_idx, UInt32 id, IFixService fix)
: base(objsys_idx)
{
ID = id;
mFix = fix;
mFix.RegistTimeGridEvent(new FixEventHandler(GM_Fix_TimeGridEvent));
}
void GM_Fix_TimeGridEvent(object sender, FixEventArgs e)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(e);
CurrObjSys.PushObjInfoEx(
this, FIX_OBJ_INTERFACE.PUSH_TIMEGRID,
Misc.Converter.StringToBytes(json));
}
#region FObj 重载
#endregion
}
}
......@@ -8,6 +8,8 @@ using System.ComponentModel;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using Misc;
using FlyADBase;
using FObjBase;
namespace FLY.Thick.Base.Server
{
......@@ -22,6 +24,11 @@ namespace FLY.Thick.Base.Server
public bool IsRunning { get; protected set; }
#endregion
#region IFixService
public DateTime UpdateTime { get; private set; }
#endregion
/// <summary>
/// 闲置时(IsRunning==false) 忽略数据
/// </summary>
......@@ -29,7 +36,7 @@ namespace FLY.Thick.Base.Server
FlyADBase.FlyAD7 mFlyAD;
DynArea mDynArea;
AD2ThkHandler Ad2Thk;
GetFixDatasReponse reponse;
public GM_Fix()
{
......@@ -53,15 +60,12 @@ namespace FLY.Thick.Base.Server
void flyad_TimeGridEvent(object sender, FlyADBase.TimeGridEventArgs e)
{
//if (IsIgnoreDataWhenIdle && !IsRunning)
// return;
DateTime dt = e.Time;
TimeSpan ts = e.Ts;
List<int> data = new List<int>(e.Data);
var datas = e.Data.ToArray();
//1秒数据
Data1s.AddRange(data);
Data1s.AddRange(datas);
if (TimeSpan.FromTicks(Data1s.Count * ts.Ticks) >= TimeSpan.FromSeconds(1))
{
int ad = (int)Data1s.Average();
......@@ -73,35 +77,16 @@ namespace FLY.Thick.Base.Server
//转换为thick
List<double> thicks = new List<double>();
foreach(int ad in data)
{
double thk = Ad2Thk(ad);
thicks.Add(thk);
}
double[] thks = datas.Select((ad) => Ad2Thk(ad)).ToArray();
//需要限制大小,push 不能太大
//分拆为多个包
int size = 200;
while (data.Count()>0)
reponse = new GetFixDatasReponse()
{
int cnt = (data.Count() > size) ? size : data.Count();
int[] ADs2 = data.Take(cnt).ToArray();
double[] thicks2 = thicks.Take(cnt).ToArray();
data.RemoveRange(0, cnt);
thicks.RemoveRange(0, cnt);
FixEvent?.Invoke(this,
new FixEventArgs()
{
time = dt,
ts = ts,
ADs = ADs2,
thicks = thicks2
});
dt += TimeSpan.FromTicks(cnt * ts.Ticks);
}
ADs = datas,
thicks = thks,
time = dt,
ts = TimeGridAdvHelperExt.ad_ts
};
UpdateTime = dt;
}
#region IGageMode
......@@ -120,24 +105,9 @@ namespace FLY.Thick.Base.Server
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
event FixEventHandler FixEvent;
/// <summary>
/// 注册定点数据事件 FixEvent += handler;
/// </summary>
/// <param name="handler"></param>
public void RegistTimeGridEvent(FixEventHandler handler)
{
FixEvent += handler;
}
/// <summary>
/// 取消注册定点数据事件 FixEvent -= handler;
/// </summary>
/// <param name="handler"></param>
public void UnRegistTimeGridEvent(FixEventHandler handler)
public void GetFixDatas(AsyncCBHandler asyncDelegate, object asyncContext)
{
FixEvent -= handler;
asyncDelegate(asyncContext, reponse);
}
}
}
......@@ -241,7 +241,7 @@ namespace FLY.Thick.Base.Server
/// <summary>
/// 保存
/// </summary>
void Save()
public void Save()
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(param_path, json);
......
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