首次上传
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.Aligners
|
||||
{
|
||||
public class CognexOcrReaderSimulator : SocketDeviceSimulator
|
||||
{
|
||||
Random _rd = new Random();
|
||||
|
||||
public CognexOcrReaderSimulator()
|
||||
: base(23, -1, "\r\n", ' ')
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CognexOcrReaderSimulator(int port)
|
||||
: base(port, -1, "\r\n", ' ')
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int GetSleepTime()
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
private int _slotID = 0;
|
||||
private int GeneratorSlotID()
|
||||
{
|
||||
int ret;
|
||||
if (_slotID < 1)
|
||||
{
|
||||
_slotID = 1;
|
||||
|
||||
}
|
||||
if (_slotID > 25)
|
||||
{
|
||||
_slotID = 1;
|
||||
|
||||
}
|
||||
ret = _slotID;
|
||||
_slotID++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected override void ProcessUnsplitMessage(string msg)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
var isMultipleWrite = false;
|
||||
switch (msg)
|
||||
{
|
||||
case "admin":
|
||||
result.Add("Password:");
|
||||
break;
|
||||
case "":
|
||||
result.Add("User Logged In");
|
||||
break;
|
||||
case "SM\"READ\"0 ":
|
||||
// [PNGHE001MXC2,400.000,1.000].
|
||||
isMultipleWrite = true;
|
||||
Thread.Sleep(2000);
|
||||
result.Add("1");
|
||||
result.Add($"[ABCD{GeneratorSlotID():D2}EF,{1:F3}]");
|
||||
//result.Add($"ABCDEF,{_rd.Next(300, 400):F3},{1:F3}]");
|
||||
break;
|
||||
case "Get Filelist":
|
||||
isMultipleWrite = true;
|
||||
result.AddRange(GenerateFilelist());
|
||||
break;
|
||||
default:
|
||||
result.Add("1");
|
||||
break;
|
||||
}
|
||||
|
||||
if (isMultipleWrite)
|
||||
{
|
||||
Thread.Sleep(GetSleepTime());
|
||||
foreach (var res in result)
|
||||
{
|
||||
Thread.Sleep(5);
|
||||
OnWriteMessage(res);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(GetSleepTime());
|
||||
|
||||
OnWriteMessage(result.FirstOrDefault());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static char[] constant =
|
||||
{
|
||||
'0','1','2','3','4','5','6','7','8','9',
|
||||
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
|
||||
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
|
||||
};
|
||||
public static string GenerateRandomNumber(int Length)
|
||||
{
|
||||
System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62);
|
||||
Random rd = new Random();
|
||||
for (int i = 0; i < Length; i++)
|
||||
{
|
||||
newRandom.Append(constant[rd.Next(62)]);
|
||||
}
|
||||
return newRandom.ToString();
|
||||
}
|
||||
|
||||
public static List<string> GenerateFilelist()
|
||||
{
|
||||
var newRandom = new System.Text.StringBuilder(62);
|
||||
var rd = new Random();
|
||||
var quantity = 50;
|
||||
var listStr = new List<string>();
|
||||
listStr.Add("1");
|
||||
listStr.Add(quantity.ToString());
|
||||
for (var i = 0; i < quantity; i++)
|
||||
{
|
||||
for (int j = 0; j < rd.Next(2, 8); j++)
|
||||
{
|
||||
newRandom.Append(constant[rd.Next(62)]);
|
||||
}
|
||||
listStr.Add(newRandom.Append(".job").ToString());
|
||||
newRandom.Clear();
|
||||
}
|
||||
|
||||
return listStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.Aligners.CognexOcrReaderView"
|
||||
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="350"></RowDefinition>
|
||||
<RowDefinition Height="50"></RowDefinition>
|
||||
<RowDefinition Height="400"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<commons:SocketTitleView Grid.Row="0"></commons:SocketTitleView>
|
||||
|
||||
<Grid Grid.Row="1" Height="350" Width="900">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="300"></RowDefinition>
|
||||
<RowDefinition Height="50"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
<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,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
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;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
using MECF.Framework.Simulator.Core.Commons;
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.Aligners
|
||||
{
|
||||
/// <summary>
|
||||
/// CognexOcrReaderView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class CognexOcrReaderView : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty PortProperty = DependencyProperty.Register(
|
||||
"Port", typeof(int), typeof(CognexOcrReaderView),
|
||||
new FrameworkPropertyMetadata(23, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public int Port
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)this.GetValue(PortProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetValue(PortProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CognexOcrReaderView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
this.Loaded += OnViewLoaded;
|
||||
}
|
||||
|
||||
private void OnViewLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext == null)
|
||||
{
|
||||
|
||||
this.DataContext = new CognexOcrReaderViewModel(Port);
|
||||
}
|
||||
(DataContext as TimerViewModelBase).Start();
|
||||
}
|
||||
}
|
||||
|
||||
class CognexOcrReaderViewModel : SocketDeviceViewModel
|
||||
{
|
||||
public string Title
|
||||
{
|
||||
get { return "Cognex Ocr Reader Simulator"; }
|
||||
}
|
||||
|
||||
public CognexOcrReaderViewModel(int port) : base("CognexOcrReaderViewModel")
|
||||
{
|
||||
Init(new CognexOcrReaderSimulator(port));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.Aligners
|
||||
{
|
||||
|
||||
public class HstOcrReaderSimulator : SocketDeviceSimulator
|
||||
{
|
||||
Random _rd = new Random();
|
||||
|
||||
public HstOcrReaderSimulator( )
|
||||
: base(23, -1, "\r\n", ' ')
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public HstOcrReaderSimulator(int port)
|
||||
: base(port, -1, "\r\n", ' ')
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int GetSleepTime()
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
public bool ResultOK { get; set; } = true;
|
||||
protected override void ProcessUnsplitMessage(string msg)
|
||||
{
|
||||
string result = "Welcome to e-Reader8000 \r\n";//ResultOK?"1":"-2";
|
||||
|
||||
OnWriteMessage(result);
|
||||
|
||||
|
||||
if (msg.StartsWith("SM"))
|
||||
{
|
||||
result = string.Format("{0},{1:F2},{2:F2}", GenerateRandomNumber(12), _rd.Next(80, 100), 1);
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(GetSleepTime());
|
||||
|
||||
OnWriteMessage(result);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static char[] constant =
|
||||
{
|
||||
'0','1','2','3','4','5','6','7','8','9',
|
||||
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
|
||||
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
|
||||
};
|
||||
public static string GenerateRandomNumber(int Length)
|
||||
{
|
||||
System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62);
|
||||
Random rd = new Random();
|
||||
for (int i = 0; i < Length; i++)
|
||||
{
|
||||
newRandom.Append(constant[rd.Next(62)]);
|
||||
}
|
||||
return newRandom.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.Aligners.HstOcrReaderView"
|
||||
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="350"></RowDefinition>
|
||||
<RowDefinition Height="50"></RowDefinition>
|
||||
<RowDefinition Height="400"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<commons:SocketTitleView Grid.Row="0"></commons:SocketTitleView>
|
||||
|
||||
<Grid Grid.Row="1" Height="350" Width="900">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="300"></RowDefinition>
|
||||
<RowDefinition Height="50"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" Width="900">
|
||||
<Button Content="Clear Log" Width="100" Height="35" Command="{Binding ClearLogCommand}"></Button>
|
||||
<Button Content="Error" Width="100" Height="35" Command="{Binding ClearLogCommand}"></Button>
|
||||
<Button Content="Normal" 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,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
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;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
using MECF.Framework.Simulator.Core.Commons;
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.Aligners
|
||||
{
|
||||
/// <summary>
|
||||
/// HstOcrReaderView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class HstOcrReaderView : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty PortProperty = DependencyProperty.Register(
|
||||
"Port", typeof(int), typeof(HstOcrReaderView),
|
||||
new FrameworkPropertyMetadata(23, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public int Port
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)this.GetValue(PortProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetValue(PortProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public HstOcrReaderView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
this.Loaded += OnViewLoaded;
|
||||
}
|
||||
|
||||
private void OnViewLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext == null)
|
||||
{
|
||||
|
||||
this.DataContext = new HstOcrReaderViewModel(Port);
|
||||
}
|
||||
(DataContext as TimerViewModelBase).Start();
|
||||
}
|
||||
}
|
||||
|
||||
class HstOcrReaderViewModel : SocketDeviceViewModel
|
||||
{
|
||||
public string Title
|
||||
{
|
||||
get { return "Hst Ocr Reader Simulator"; }
|
||||
}
|
||||
|
||||
public HstOcrReaderViewModel(int port) : base("HstOcrReaderViewModel")
|
||||
{
|
||||
Init(new HstOcrReaderSimulator(port));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user