using SecsGem.Core;
using SecsGem.Core.ItemModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
namespace EapClientSimulator
{
///
/// ULpControl.xaml 的交互逻辑
///
public partial class ULpControl : UserControl
{
private string sequence= System.Configuration.ConfigurationManager.AppSettings.Get("defaultSequence");
public event EventHandler OnSendMessage;
public ULpControl()
{
InitializeComponent();
}
string portId = "";
string jobId = "";
string lotId = "";
private void btnLoadId_Click(object sender, RoutedEventArgs e)
{
PortCommand("Load");
}
private void btnReadId_Click(object sender, RoutedEventArgs e)
{
PortCommand("ReadID");
}
FrmSequence frmSequence = null;
private void btnPPSelect_Click(object sender, RoutedEventArgs e)
{
frmSequence = new FrmSequence(portId, jobId, lotId,sequence);
frmSequence.OnUpdateSequence += FrmSequence_OnUpdateSequence;
frmSequence.OnSendMessage += FrmSequence_OnSendMessage;
frmSequence.ShowDialog();
}
private void FrmSequence_OnUpdateSequence(object sender, string e)
{
sequence = e;
}
private void FrmSequence_OnSendMessage(object sender, string e)
{
if(OnSendMessage!=null)
{
OnSendMessage(sender, e);
}
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
JobCommand("StartJob");
}
private void btnStop_Click(object sender, RoutedEventArgs e)
{
JobCommand("StopJob");
}
private void btnAbort_Click(object sender, RoutedEventArgs e)
{
JobCommand("AbortJob");
}
private void btnResume_Click(object sender, RoutedEventArgs e)
{
JobCommand("ResumeJob");
}
private void btnPause_Click(object sender, RoutedEventArgs e)
{
JobCommand("PauseJob");
}
private void JobCommand(string command)
{
RemoteCommand remoteCommand = new RemoteCommand();
remoteCommand.Command = command;
RemoteParameter remoteParameter = new RemoteParameter();
remoteParameter.Name = "JobID";
remoteParameter.Value = new StringItem(SecsGem.Core.DataFormat.Ascii, jobId);
remoteCommand.RemoteParameters.Add(remoteParameter);
SecsGem.Core.SecsMessage secsMessage = SecsMessageSendUtil.CreateS2F49Message(remoteCommand);
if (GlobalData.Client != null)
{
GlobalData.Client.SendMessage(secsMessage);
}
if (OnSendMessage != null)
{
OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
portId = this.Name.Substring(this.Name.Length - 1);
jobId = "Job_" + portId;
lotId = "C00" + portId;
}
private void btnUnload_Click(object sender, RoutedEventArgs e)
{
PortCommand("UnLoad");
}
private void PortCommand(string command)
{
RemoteCommand remoteCommand = new RemoteCommand();
remoteCommand.Command = command;
RemoteParameter remoteParameter = new RemoteParameter();
remoteParameter.Name = "PortID";
remoteParameter.Value = new StringItem(SecsGem.Core.DataFormat.Ascii, portId);
remoteCommand.RemoteParameters.Add(remoteParameter);
SecsGem.Core.SecsMessage secsMessage = SecsMessageSendUtil.CreateS2F49Message(remoteCommand);
if (GlobalData.Client != null)
{
GlobalData.Client.SendMessage(secsMessage);
}
if (OnSendMessage != null)
{
OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
}
}
private void btnMapCassette_Click(object sender, RoutedEventArgs e)
{
PortCommand("MapCassette");
}
}
}