You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
218 lines
6.0 KiB
C#
218 lines
6.0 KiB
C#
using Aucma.Scada.Business;
|
|
using HighWayIot.Config;
|
|
using HighWayIot.Log4net;
|
|
using HighWayIot.Plc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace Aucma.Scada.UI.Page.InStoreInfo
|
|
{
|
|
/// <summary>
|
|
/// NullMaterial.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class NullMaterialWindow : Window
|
|
{
|
|
private Dictionary<string, IPlc> _plcDictionary = new Dictionary<string, IPlc>();
|
|
private AppConfig appConfig = AppConfig.Instance;
|
|
private PlcConfig plcConfig = PlcConfig.Instance;
|
|
private LogHelper logHelper = LogHelper.Instance;
|
|
|
|
private PlcPool _pool = PlcPool.Instance;
|
|
private InStoreBusiness inStoreBusiness = InStoreBusiness.Instance;
|
|
|
|
private Timer _timer;
|
|
|
|
/// <summary>
|
|
/// 箱壳空板入库处理
|
|
/// </summary>
|
|
/// <param name="materialCodeStr"></param>
|
|
/// <param name="ip"></param>
|
|
public delegate void RefreshMaterialCodeStr(string materialCodeStr, string ip);
|
|
public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent;
|
|
|
|
public NullMaterialWindow()
|
|
{
|
|
InitializeComponent();
|
|
_plcDictionary = _pool.GetAll();
|
|
|
|
// 初始化定时器
|
|
_timer = new Timer(1000); // 1000 毫秒 = 1 秒
|
|
_timer.Elapsed += TimerElapsed; // 绑定定时器事件
|
|
|
|
}
|
|
|
|
private void TimerElapsed(object sender, ElapsedEventArgs e)
|
|
{
|
|
int nullAmount = ReadNullAmount();
|
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)(() =>
|
|
{
|
|
NullAmount.Text = nullAmount.ToString();
|
|
}));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取plc空板数量
|
|
/// </summary>
|
|
/// <param name="taskInfo"></param>
|
|
/// <returns></returns>
|
|
public int ReadNullAmount()
|
|
{
|
|
int result = 0;
|
|
try
|
|
{
|
|
IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
|
|
|
|
if (_plc != null)
|
|
{
|
|
result = _plc.readInt32ByAddress(plcConfig.null_shell_amount);
|
|
return result;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("打开放空板按钮:" + ex.Message.ToString());
|
|
|
|
}
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
_timer.Start(); // 启动定时器
|
|
if (OpenNullKey())
|
|
{
|
|
MessageBox.Show("成功打开");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("打开空板开关失败!");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void Button_Click_1(object sender, RoutedEventArgs e)
|
|
{
|
|
_timer.Stop();
|
|
if (OpenNullKey())
|
|
{
|
|
MessageBox.Show("成功关闭");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("关闭空板开关失败!");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 打开放空板按钮
|
|
/// </summary>
|
|
/// <param name="taskInfo"></param>
|
|
/// <returns></returns>
|
|
public bool OpenNullKey()
|
|
{
|
|
bool result = false;
|
|
try
|
|
{
|
|
IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
|
|
|
|
if (_plc != null)
|
|
{
|
|
result = _plc.writeBoolByAddress(plcConfig.null_shell_open, true);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("打开放空板按钮:" + ex.Message.ToString());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 关闭放空板按钮
|
|
/// </summary>
|
|
/// <param name="taskInfo"></param>
|
|
/// <returns></returns>
|
|
public bool CloseNullKey()
|
|
{
|
|
bool result = false;
|
|
try
|
|
{
|
|
IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
|
|
|
|
if (_plc != null)
|
|
{
|
|
result = _plc.writeBoolByAddress(plcConfig.null_shell_open, false);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logHelper.Error("关闭放空板按钮:" + ex.Message.ToString());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
protected override void OnClosed(EventArgs e)
|
|
{
|
|
base.OnClosed(e);
|
|
// 在窗口关闭时停止定时器
|
|
_timer.Stop();
|
|
_timer.Dispose();
|
|
}
|
|
|
|
private void Button_Click_2(object sender, RoutedEventArgs e)
|
|
{
|
|
window.Close();
|
|
}
|
|
|
|
private void Button_Click_3(object sender, RoutedEventArgs e)
|
|
{
|
|
int amount ;
|
|
try
|
|
{
|
|
amount = int.Parse(NullAmount.Text);
|
|
}catch (Exception ex)
|
|
{
|
|
amount=0;
|
|
}
|
|
|
|
if (amount <= 0)
|
|
{
|
|
MessageBox.Show("数量要大于0");
|
|
NullAmount.Text = "";
|
|
return;
|
|
}
|
|
MessageBoxResult result = MessageBox.Show("确认创建"+ amount+"个空板入库任务吗,请仔细核对空板数量", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
if (result == MessageBoxResult.Yes)
|
|
{
|
|
// 创建空板入库任务
|
|
for(int i = 0; i < amount; i++)
|
|
{
|
|
inStoreBusiness.InStore("1111111111111111111111", appConfig.shellHikRobotIp);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|