refactor: 将Framework库和RT、UI放在同一个解决方案中。

This commit is contained in:
SL
2026-06-01 17:48:28 +08:00
parent 1948f4290d
commit b73d39a6b1
4331 changed files with 506148 additions and 49363 deletions
@@ -0,0 +1,242 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Timers;
using MECF.Framework.Simulator.Core.SubstrateTrackings;
namespace MECF.Framework.Simulator.Core.Robots
{
public class TrayRobotSimulator : RobotSimulator
{
public enum OperateEnum
{
Null,
RSR,
INPUT,
STAT,
}
protected Random _rd = new Random();
public bool IsError { get; set; }
public string ErrorCode { get; set; }
public bool StateChecked { get; set; }
public int StateCode { get; set; }
public bool EventChecked { get; set; }
public string EventCode { get; set; }
private static string msgDone = ">";
private static string msgError = "?";
private static string msgRSRCassB = "1001311011110000000000101"; //f
private static string msgRSR = "1";
private string lastMsg = "";
private System.Timers.Timer timer;
private bool IsRSR = false;
public TrayRobotSimulator() : base(1104, 0, "\r\n", ' ', 5)
{
AddCommandHandler("HOM", HandleHome);
AddCommandHandler("GETA", HandleHome);
AddCommandHandler("PUTA", HandleHome);
AddCommandHandler("GETB", HandleHome);
AddCommandHandler("PUTB", HandleHome);
AddCommandHandler("GETSP", HandleGetSp);
AddCommandHandler("PUTSP", HandleHome);
AddCommandHandler("MAP", HandleMap);
AddCommandHandler("RSR", HandleRSR);
AddCommandHandler("RESP", HandleHome);
AddCommandHandler("REMS", HandleHome);
AddCommandHandler("SVON", HandleHome);
AddCommandHandler("OUTP", HandleHome);
AddCommandHandler("MTCS", HandleHome);
AddCommandHandler("MOVR", HandleHome);
AddCommandHandler("RETH", HandleHome);
AddCommandHandler("ERR", HandleErr);
AddCommandHandler("STAT", HandleStat);
AddCommandHandler("INPUT", HandleInput);
ErrorCode = "0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000";
timer = new System.Timers.Timer();
timer.Enabled = false;
timer.AutoReset = false;
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}
internal void HandleErr(string msg)
{
lastMsg = msg;
if (IsError)
OnWriteMessage(string.IsNullOrEmpty(ErrorCode) ? @"FFFF, FFFF, FFFF, FFFF, FFFF, FFFF, FFFF, FFFF" : ErrorCode);
else
OnWriteMessage("0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000");
}
internal void HandleGetSp(string msg)
{
// GETSP B 11 1
lastMsg = msg;
operateEnum = OperateEnum.Null;
HandleGetSp(RobotStateEnum.Picking, msg.Split(' '));
}
OperateEnum operateEnum = OperateEnum.Null;
internal void HandleStat(string msg)
{
lastMsg = msg;
operateEnum = OperateEnum.STAT;
OnWriteMessage(StateCode.ToString());
}
internal void HandleHome(string msg)
{
operateEnum = OperateEnum.Null;
lastMsg = msg;
HandleMove(RobotStateEnum.Homing, new string[] { "" });
}
internal void HandleMap(string msg)
{
lastMsg = msg;
HandleMap(RobotStateEnum.MAP, new string[] { "" });
}
internal void HandleRSR(string msg)
{
operateEnum = OperateEnum.RSR;
HandleRSR(RobotStateEnum.RSR, new string[] { "" });
}
internal void HandleInput(string msg)
{
lastMsg = msg;
operateEnum = OperateEnum.INPUT;
HandleInput(RobotStateEnum.Input, new string[] { "" });
}
private bool HandleInput(RobotStateEnum action, string[] cmdComponents)
{
if (robotStateArgs.State != RobotStateEnum.Idle &&
(action == RobotStateEnum.Homing && robotStateArgs.State != RobotStateEnum.Errored)) // allow homes when in error, but not other moves
{
HandleError("Already moving");
return false;
}
double delay = 2;
timer.Interval = delay * 1000;
timer.Enabled = true;
return true;
}
private bool HandleRSR(RobotStateEnum action, string[] cmdComponents)
{
if (robotStateArgs.State != RobotStateEnum.Idle &&
(action == RobotStateEnum.Homing && robotStateArgs.State != RobotStateEnum.Errored)) // allow homes when in error, but not other moves
{
HandleError("Already moving");
return false;
}
double delay = 2;
timer.Interval = delay * 1000;
timer.Enabled = true;
return true;
}
internal void HandleUnknown(string msg)
{
OnWriteMessage(msgError);
}
private bool HandleMove(RobotStateEnum action, string[] cmdComponents)
{
if (robotStateArgs.State != RobotStateEnum.Idle &&
(action == RobotStateEnum.Homing && robotStateArgs.State != RobotStateEnum.Errored)) // allow homes when in error, but not other moves
{
HandleError("Already moving");
return false;
}
ErrorCode = "0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000";
IsRSR = false;
double delay = 2;
timer.Interval = delay * 1000;
timer.Enabled = true;
return true;
}
private bool HandleGetSp(RobotStateEnum action, string[] args)
{
if (IsError && args[3] == "1")
{
ErrorCode = "0000, 0000, 0000, 0001, 0000, 0000, 0001, 0001";
OnWriteMessage(msgError);
return true;
}
OnWriteMessage(msgDone);
return true;
}
private bool HandleMap(RobotStateEnum action, string[] cmdComponents)
{
if (robotStateArgs.State != RobotStateEnum.Idle &&
(action == RobotStateEnum.Homing && robotStateArgs.State != RobotStateEnum.Errored)) // allow homes when in error, but not other moves
{
HandleError("Already moving");
return false;
}
IsRSR = false;
double delay = 2;
timer.Interval = delay * 1000;
timer.Enabled = true;
return true;
}
private void HandleError(string msg)
{
OnWriteMessage(msgError);
}
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
SetRobotState(RobotStateEnum.Idle);
timer.Enabled = false;
if (operateEnum == OperateEnum.STAT)
{
OnWriteMessage(msgRSRCassB);
}
else if (operateEnum == OperateEnum.RSR)
{
OnWriteMessage(msgRSRCassB);
}
else if (operateEnum == OperateEnum.INPUT)
{
OnWriteMessage("1");
}
else
{
OnWriteMessage(msgDone);
}
}
}
}
@@ -0,0 +1,84 @@
<UserControl x:Class="MECF.Framework.Simulator.Core.Robots.TrayRobotView"
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.Aligners"
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">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="150"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="400"></RowDefinition>
</Grid.RowDefinitions>
<commons:SocketTitleView Grid.Row="0"></commons:SocketTitleView>
<Canvas Grid.Row="1" Width="900">
<CheckBox Content="Error" IsChecked="{Binding IsError}" Canvas.Left="36" Canvas.Top="73"></CheckBox>
<TextBlock Text="_ERR {Code}" Canvas.Left="204" Canvas.Top="52"></TextBlock>
<TextBlock Text="Error Code:" Canvas.Left="99" Canvas.Top="72"></TextBlock>
<!--<TextBox Text="{Binding ResultValue, UpdateSourceTrigger=PropertyChanged }" Canvas.Left="358" Canvas.Top="31" Margin="0" Width="284"></TextBox>
<TextBlock Text="Error:" Canvas.Left="310" Canvas.Top="45"></TextBlock>-->
<TextBox Text="{Binding ErrorCode, UpdateSourceTrigger=PropertyChanged}" Canvas.Left="203" Canvas.Top="70" Width="369" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Text="_STA {Code}" Canvas.Left="204" Canvas.Top="10"></TextBlock>
<TextBlock Text="State Code:" Canvas.Left="99" Canvas.Top="30"></TextBlock>
<TextBox Text="{Binding StateCode, UpdateSourceTrigger=PropertyChanged}" Canvas.Left="203" Canvas.Top="28" Margin="0" Width="74" IsReadOnly="False"/>
<CheckBox Content="Event" IsChecked="{Binding EventChecked}" Canvas.Left="36" Canvas.Top="110"></CheckBox>
<TextBlock Text="_Event {Code}" Canvas.Left="204" Canvas.Top="91"></TextBlock>
<TextBlock Text="Event Code:" Canvas.Left="99" Canvas.Top="110"></TextBlock>
<TextBox Text="{Binding EventCode, UpdateSourceTrigger=PropertyChanged}" Canvas.Left="203" Canvas.Top="107" Margin="0" Width="550" IsReadOnly="False"/>
</Canvas>
<StackPanel Grid.Row="2" Orientation="Horizontal" Width="900">
<Button Content="Clear Log" Width="100" Height="35" Command="{Binding ClearLogCommand}"></Button>
</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,85 @@
using System.Windows;
using System.Windows.Controls;
using Aitex.Core.UI.MVVM;
using Aitex.Core.Utilities;
using MECF.Framework.Simulator.Core.Commons;
namespace MECF.Framework.Simulator.Core.Robots
{
/// <summary>
/// HwinRobotView.xaml 的交互逻辑
/// </summary>
public partial class TrayRobotView : UserControl
{
public TrayRobotView()
{
InitializeComponent();
this.DataContext = new TrayRobotViewModel();
this.Loaded += OnViewLoaded;
}
private void OnViewLoaded(object sender, RoutedEventArgs e)
{
(DataContext as TimerViewModelBase).Start();
}
}
class TrayRobotViewModel : SocketDeviceViewModel
{
public string Title
{
get { return "Tray Robot Simulator"; }
}
private TrayRobotSimulator _robot;
public bool IsError
{
get => _robot.IsError;
set => _robot.IsError = value;
}
public bool StateChecked
{
get => _robot.StateChecked;
set => _robot.StateChecked = value;
}
//private string _value;
[IgnorePropertyChange]
public string ErrorCode
{
get => _robot.ErrorCode;
set => _robot.ErrorCode = value;
}
public bool EventChecked
{
get => _robot.EventChecked;
set
{
_robot.EventChecked = value;
if (value) EventCode = "_EVENT ROBOR 02610 0003 B -00028 000028 000028 -00002\r";
else EventCode = null;
}
}
[IgnorePropertyChange]
public string EventCode
{
get => _robot.EventCode;
set => _robot.EventCode = value;
}
public TrayRobotViewModel() : base("TrayRobotViewModel")
{
_robot = new TrayRobotSimulator();
Init(_robot);
}
}
}