首次上传
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.LoadPorts
|
||||
{
|
||||
class OmronV640SerialSimulator : SerialPortDeviceSimulator
|
||||
{
|
||||
public bool Failed { get; set; }
|
||||
public string ResultValue { get; set; }
|
||||
private string _rfid = "";
|
||||
public OmronV640SerialSimulator(string port)
|
||||
: base(port, -1, "\r", ' ')
|
||||
{
|
||||
ResultValue = "";
|
||||
_rfid =
|
||||
"004346303533302020000000000000000000000000000000002020202020202020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
}
|
||||
|
||||
protected override void ProcessUnsplitMessage(string msg)
|
||||
{
|
||||
string type = msg.Substring(0, 4);
|
||||
if (type == "0100") //read
|
||||
{
|
||||
if (_rfid.TrimStart('0').Length == 0)
|
||||
_rfid = GenerateRandomNumber(16);
|
||||
_rfid = ASCII2HEX(GenerateRandomNumber(4));
|
||||
|
||||
OnWriteMessage("00" + _rfid+"\r");
|
||||
//OnWriteMessage("{0}\r" + _rfid);
|
||||
|
||||
}
|
||||
else if (type == "0200") //write
|
||||
{
|
||||
_rfid = msg.Substring(12);
|
||||
|
||||
OnWriteMessage("00\r");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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().ToUpper();
|
||||
}
|
||||
|
||||
public static string ASCII2HEX(string src)
|
||||
{
|
||||
while (src.Length < 128)
|
||||
{
|
||||
src = '\0' + src;
|
||||
}
|
||||
|
||||
if (src.Length > 128)
|
||||
{
|
||||
src = src.Substring(0, 128);
|
||||
}
|
||||
string res = String.Empty;
|
||||
try
|
||||
{
|
||||
|
||||
char[] charValues = src.ToCharArray();
|
||||
string hexOutput = "";
|
||||
foreach (char _eachChar in charValues)
|
||||
{
|
||||
// Get the integral value of the character.
|
||||
int value = Convert.ToInt32(_eachChar);
|
||||
// Convert the decimal value to a hexadecimal value in string form.
|
||||
hexOutput += String.Format("{0:X2}", value);
|
||||
// to make output as your eg
|
||||
// hexOutput +=" "+ String.Format("{0:X}", value);
|
||||
|
||||
}
|
||||
|
||||
return hexOutput;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.LoadPorts.OmronV640SerialView"
|
||||
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="Fail" IsChecked="{Binding IsFailed}" Canvas.Left="36" Canvas.Top="31"></CheckBox>
|
||||
|
||||
<TextBlock Text="Result:" Canvas.Left="155" Canvas.Top="42"></TextBlock>
|
||||
<TextBox Text="{Binding ResultValue, UpdateSourceTrigger=PropertyChanged }" Canvas.Left="212" Canvas.Top="31" Margin="0" Width="284"></TextBox>
|
||||
|
||||
</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,104 @@
|
||||
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 Aitex.Core.Utilities;
|
||||
using MECF.Framework.Simulator.Core.Aligners;
|
||||
using MECF.Framework.Simulator.Core.Commons;
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.LoadPorts
|
||||
{
|
||||
/// <summary>
|
||||
/// OmronCIDRWView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class OmronV640SerialView : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty PortProperty = DependencyProperty.Register(
|
||||
"Port", typeof(string), typeof(OmronBarcodeReaderView),
|
||||
new FrameworkPropertyMetadata("COM1", FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public string Port
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this.GetValue(PortProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetValue(PortProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public OmronV640SerialView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Loaded += OnViewLoaded;
|
||||
}
|
||||
|
||||
private void OnViewLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext == null)
|
||||
{
|
||||
DataContext = new OmronV640SerialViewModel( Port );
|
||||
(DataContext as TimerViewModelBase).Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OmronV640SerialViewModel : SerialPortDeviceViewModel
|
||||
{
|
||||
public string Title
|
||||
{
|
||||
get { return "Omron V640 Serial Simulator"; }
|
||||
}
|
||||
|
||||
private OmronV640SerialSimulator _reader;
|
||||
|
||||
public bool IsFailed
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reader.Failed;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reader.Failed = value;
|
||||
}
|
||||
}
|
||||
|
||||
//private string _value;
|
||||
|
||||
[IgnorePropertyChange]
|
||||
public string ResultValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reader.ResultValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reader.ResultValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public OmronV640SerialViewModel(string port) : base("OmronV640SerialViewModel")
|
||||
{
|
||||
_reader = new OmronV640SerialSimulator(port);
|
||||
Init(_reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user