首次上传
This commit is contained in:
@@ -0,0 +1,244 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.Aligners.HPA48
|
||||
{
|
||||
public class HPA48Simulator : SerialPortDeviceSimulator
|
||||
{
|
||||
#region Variables
|
||||
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
private readonly object _lock = new object();
|
||||
private bool _isBusy = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public HPA48Simulator(string portName)
|
||||
: base(portName, -1, "", ' ')
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public bool IsAlarm { get; set; }
|
||||
|
||||
public bool IsVacuumOn { get; set; }
|
||||
|
||||
public bool IsGenerateBALError { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override void ProcessUnsplitMessage(string message)
|
||||
{
|
||||
if (message.StartsWith("ERS"))
|
||||
ERS(message);
|
||||
else if (message.StartsWith("BAL"))
|
||||
BAL(message);
|
||||
else if (message.StartsWith("HOM"))
|
||||
HOM(message);
|
||||
else if (message.StartsWith("CVN"))
|
||||
CVN(message);
|
||||
else if (message.StartsWith("CVF"))
|
||||
CVF(message);
|
||||
else if (message.StartsWith("CVD"))
|
||||
CVD(message);
|
||||
else if (message.StartsWith("MTM"))
|
||||
MTM(message);
|
||||
else if (message.StartsWith("DOC"))
|
||||
DOC(message);
|
||||
else if (message.StartsWith("STP"))
|
||||
STP(message);
|
||||
else if (message.StartsWith("PER"))
|
||||
PER(message);
|
||||
|
||||
}
|
||||
|
||||
protected override void ProcessWriteMessage(string msg)
|
||||
{
|
||||
var msgReformatted = $"{msg}\r\n";
|
||||
base.ProcessWriteMessage(msgReformatted);
|
||||
}
|
||||
|
||||
private void SendResponse(string cmd, Action<string> handleCmd, Action customizeEcho = null)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if(_isBusy)
|
||||
OnWriteMessage("BUSY");
|
||||
else
|
||||
{
|
||||
if (_cancellationTokenSource == null)
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
_isBusy = true;
|
||||
Task.Run(() => { handleCmd?.Invoke(cmd); }, _cancellationTokenSource.Token).ContinueWith(t =>
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_isBusy = false;
|
||||
|
||||
if(customizeEcho != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
customizeEcho?.Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.WriteLine(ex.Message);
|
||||
Debugger.Break();
|
||||
}
|
||||
}
|
||||
else
|
||||
OnWriteMessage("END");
|
||||
_cancellationTokenSource = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始寻边。
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void BAL(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
}, () =>
|
||||
{
|
||||
if(IsGenerateBALError)
|
||||
OnWriteMessage("ERR 0411");
|
||||
else
|
||||
OnWriteMessage("END");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回机械零点。
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void HOM(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取真空值
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void CVD(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
OnWriteMessage("-65");
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开真空。
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void CVN(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
IsVacuumOn = true;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭真空。
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void CVF(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
IsVacuumOn = false;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有报警。
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void ERS(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
IsAlarm = false;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取上一次报警
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void PER(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
OnWriteMessage("ERR 444");
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移动至测量中心点。
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void MTM(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///检测是否有Wafer。
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void DOC(string cmd)
|
||||
{
|
||||
SendResponse(cmd, s =>
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
OnWriteMessage("1");
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止运动。
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
private void STP(string cmd)
|
||||
{
|
||||
_cancellationTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.LoadPorts.HPA48View"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:MECF.Framework.Simulator.Core.LoadPorts"
|
||||
xmlns:deviceControl="clr-namespace:MECF.Framework.UI.Core.DeviceControl;assembly=MECF.Framework.UI.Core"
|
||||
xmlns:commons="clr-namespace:MECF.Framework.Simulator.Core.Commons"
|
||||
Height="900" Width="900">
|
||||
<UserControl.Resources>
|
||||
<DataTemplate x:Key="DataTemplate1">
|
||||
<StackPanel Orientation="Horizontal" Width="200" Height="15">
|
||||
<TextBox Text="{Binding Index}"></TextBox>
|
||||
<TextBox Text="{Binding State}"></TextBox>
|
||||
<Button Content="{Binding State}" Margin="0" Width="100" Height="15" Background="LightBlue" VerticalAlignment="Center"></Button>
|
||||
<TextBox Text="{Binding Index}"></TextBox>
|
||||
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="100"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<commons:SerialPortTitleView Grid.Row="0"/>
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" Width="900">
|
||||
<Button Content="Clear Log" Width="100" Height="35" Command="{Binding ClearLogCommand}"></Button>
|
||||
|
||||
<CheckBox
|
||||
Content="Gen BAL Error"
|
||||
VerticalAlignment="Center"
|
||||
Margin="10 0 0 0"
|
||||
IsChecked="{Binding IsGenBALError, Mode=OneWayToSource}"/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<DataGrid Grid.Row="3" FontSize="16" AutoGenerateColumns="False" CanUserAddRows="False" CanUserResizeRows="False" CanUserSortColumns="False" ItemsSource="{Binding TransactionLogItems}"
|
||||
ScrollViewer.CanContentScroll="True"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||
Width="900" Height="380" VerticalAlignment="Top">
|
||||
<DataGrid.Columns>
|
||||
|
||||
<DataGridTextColumn Header="Time" Width="160" IsReadOnly="True" Binding="{Binding OccurTime, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<DataGridTextColumn Header="Incoming" Width="350" IsReadOnly="True" Binding="{Binding Incoming, UpdateSourceTrigger=PropertyChanged}">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="TextWrapping" Value="Wrap"/>
|
||||
<Setter Property="Height" Value="auto"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.ElementStyle>
|
||||
</DataGridTextColumn>
|
||||
|
||||
|
||||
<DataGridTextColumn Header="Outgoing" Width="350" IsReadOnly="True" Binding="{Binding Outgoing, UpdateSourceTrigger=PropertyChanged}">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="TextWrapping" Value="Wrap"/>
|
||||
<Setter Property="Height" Value="auto"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.ElementStyle>
|
||||
</DataGridTextColumn>
|
||||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
||||
@@ -0,0 +1,95 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
using Aitex.Core.Utilities;
|
||||
using MECF.Framework.Simulator.Core.Aligners.HPA48;
|
||||
using MECF.Framework.Simulator.Core.Commons;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.LoadPorts
|
||||
{
|
||||
//public class WaferItem
|
||||
//{
|
||||
// public int index { get; set; }
|
||||
|
||||
// public string Display { get; set; }
|
||||
|
||||
// public int State { get; set; }
|
||||
//}
|
||||
/// <summary>
|
||||
/// TazmoAligner.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class HPA48View : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty PortNameProperty = DependencyProperty.Register(
|
||||
"PortName", typeof(string), typeof(TazmoAlignerView),
|
||||
new FrameworkPropertyMetadata("COM10", FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public string PortName
|
||||
{
|
||||
get => (string)this.GetValue(PortNameProperty);
|
||||
set => this.SetValue(PortNameProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty PortNumberProperty = DependencyProperty.Register(
|
||||
"PortNumber", typeof(int), typeof(TazmoAlignerView),
|
||||
new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public int PortNumber
|
||||
{
|
||||
get => (int)this.GetValue(PortNumberProperty);
|
||||
set => this.SetValue(PortNumberProperty, value);
|
||||
}
|
||||
|
||||
public HPA48View()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Loaded += OnViewLoaded;
|
||||
}
|
||||
|
||||
private void OnViewLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext == null)
|
||||
{
|
||||
DataContext = new HPA48ViewModel(PortName, PortNumber);
|
||||
(DataContext as TimerViewModelBase).Start();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class HPA48ViewModel : SerialPortDeviceViewModel
|
||||
{
|
||||
public string Title => "HiWin HPA48 Aligner Simulator";
|
||||
|
||||
public bool IsGenBALError
|
||||
{
|
||||
set
|
||||
{
|
||||
_sim.IsGenerateBALError = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<WaferItem> WaferList { get; set; }
|
||||
|
||||
private HPA48Simulator _sim;
|
||||
|
||||
|
||||
public HPA48ViewModel(string port, int index) : base("HPA48ViewModel")
|
||||
{
|
||||
_sim = new HPA48Simulator(port);
|
||||
|
||||
Init(_sim);
|
||||
|
||||
|
||||
WaferList = new ObservableCollection<WaferItem>()
|
||||
{
|
||||
new WaferItem {Display = "1", Index = 2, State = 3}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user