feat - 添加自动写入功能

read_card
SoulStar 2 days ago
parent 84f852a9d5
commit 7a21faf9d0

@ -212,7 +212,7 @@ Content="查询" Width="200" Visibility="Hidden" FontSize="20" Command="{Binding
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding WriteCount,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<Button Content="生成编码" Width="100" Height="30" FontSize="15" Command="{Binding GenerateCodeCommand}" Background="#009999" Style="{StaticResource BUTTON_AGREE}" Margin="10,0,0,0"/>
<Button Content="清除数据" Width="100" Height="30" FontSize="15" Command="{Binding ListClearCommand}" Background="OrangeRed" Style="{StaticResource BUTTON_AGREE}" Margin="10,0,0,0"/>
<!--<Button Content="自动写入" Width="100" Height="30" FontSize="15" Command="{Binding AutoWriteCommand}" Background="#009999" Style="{StaticResource BUTTON_AGREE}" Margin="10,0,0,0"/>-->
<Button Content="{Binding AutoWriteName, Mode=TwoWay}" Width="100" Height="30" FontSize="15" Command="{Binding AutoWriteCommand}" Background="Green" Style="{StaticResource BUTTON_AGREE}" Margin="10,0,0,0"/>
</WrapPanel>
</Grid>
<!-- 数据表格绑定ViewModel中的历史记录 -->

@ -50,6 +50,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
private RealReadDataService dataService = RealReadDataService.Instance;
private real_readdata NowReadData;
private bool IsAuto = false;
#region 关联属性
@ -61,7 +62,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
get { return _QueryIsCheck; }
set
{
_QueryIsCheck = value;
if (_QueryIsCheck != value)
{
SetProperty(ref _QueryIsCheck, value);
@ -69,6 +69,19 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
}
}
private string _AutoWriteName = "自动写入";
public string AutoWriteName
{
get { return _AutoWriteName; }
set
{
if (_AutoWriteName != value)
{
SetProperty(ref _AutoWriteName, value);
}
}
}
/// <summary>
/// 准备写入的列表
/// </summary>
@ -253,6 +266,8 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
appConfig = App.ServiceProvider.GetService<AppConfig>();
rfidList = App.ServiceProvider.GetRequiredService<List<RfidAbsractFactory>>();
AutoWriteName = "自动写入";
rfidList.ForEach(rfid =>
{
rfid._Action += RecvIdentifyData_Instance;
@ -353,11 +368,44 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
/// <param name="obj"></param>
private void AutoWrite(object obj)
{
//获取设备编号
if (string.IsNullOrEmpty(QueryIsCheck.ToString().Trim()))
try
{
MessageBox.Show("请选择产线!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
//获取设备编号
if (string.IsNullOrEmpty(QueryIsCheck.ToString().Trim()))
{
MessageBox.Show("请选择产线!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
List<DeviceInfoConfig> DeviceInfos = appConfig.deviceInfoConfig.Where(x => x.Collectid == appConfig.StationCode && x.Name == QueryIsCheck.ToString().Trim() && x.Deleteflag == 0).ToList();
if (!IsAuto)
{
var data = PreparedWriteList.FirstOrDefault(x => x.writestatus == "等待");
if (data == null)
{
MessageBox.Show("无待写入数据", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
IsAuto = false;
return;
}
NowReadData = data;
rfidList.FirstOrDefault(x => x.deviceid == DeviceInfos[0].Deviceid).Set_BeginIdentify().GetAwaiter().GetResult();
IsAuto = true;
AutoWriteName = "停止写入";
}
else
{
IsAuto = false;
rfidList.FirstOrDefault(x => x.deviceid == DeviceInfos[0].Deviceid).Set_StopIdentify();
AutoWriteName = "自动写入";
}
}
catch (Exception ex)
{
Log.Error($"自动写入异常:{ex.Message}");
MessageBox.Show($"自动写入异常:{ex.Message}");
}
}
@ -376,6 +424,8 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
return;
}
IsAuto = false;
real_readdata? data;
if (obj is real_readdata)
{
@ -395,6 +445,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
catch (Exception ex)
{
Log.Error($"手动写入异常:{ex.Message}");
MessageBox.Show($"手动写入异常:{ex.Message}");
}
}
@ -457,6 +508,12 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
NowReadData = null!;
LastWriteState = "成功";
//连续写入就读完紧接着开启下一条盘点
if (IsAuto)
{
rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_BeginIdentify().GetAwaiter().GetResult();
}
}
catch (Exception e)
{

Loading…
Cancel
Save