首次上传
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.ThrottleValves.KITZ
|
||||
{
|
||||
class SimThrottleValve : SerialPortDeviceSimulator
|
||||
{
|
||||
private Dictionary<int, List<byte>> _flowDic = new Dictionary<int, List<byte>>();
|
||||
|
||||
Stopwatch _timer = new Stopwatch();
|
||||
|
||||
private System.Timers.Timer _tick;
|
||||
Random _rd = new Random();
|
||||
|
||||
private object _locker = new object();
|
||||
|
||||
public string ResultValue { get; set; }
|
||||
|
||||
private string _positionValue = 0.ToString();
|
||||
private string _pressureValue = 0.ToString();
|
||||
private string _controlMode = "PRESS";
|
||||
private string _accessMode = "LOCAL";
|
||||
private string _warningInformation = "0000000000000000";
|
||||
private string _cycleCounter= "1";
|
||||
|
||||
public SimThrottleValve(string port)
|
||||
: base(port, -1, "\r", ' ')
|
||||
{
|
||||
ResultValue = "";
|
||||
|
||||
_tick = new System.Timers.Timer();
|
||||
_tick.Interval = 200;
|
||||
|
||||
_tick.Elapsed += _tick_Elapsed;
|
||||
_tick.Start();
|
||||
}
|
||||
|
||||
private void _tick_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
if (_timer.IsRunning && _timer.Elapsed > TimeSpan.FromSeconds(10))
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void ProcessUnsplitMessage(string msg)
|
||||
{
|
||||
msg = msg.Replace("\r", "").Replace("\n", "");
|
||||
string[] datas = Regex.Split(msg, ":");
|
||||
if(datas.Length > 1)
|
||||
{
|
||||
switch(datas[0])
|
||||
{
|
||||
case "REMOTE":
|
||||
{
|
||||
_accessMode = "REMOTE";
|
||||
OnWriteMessage(msg + "\r");
|
||||
}
|
||||
break;
|
||||
case "C":
|
||||
{
|
||||
_controlMode = "CLOSE";
|
||||
OnWriteMessage(msg + "\r");
|
||||
}
|
||||
break;
|
||||
case "O":
|
||||
{
|
||||
_controlMode = "OPEN";
|
||||
OnWriteMessage(msg + "\r");
|
||||
}
|
||||
break;
|
||||
case "POS":
|
||||
{
|
||||
_controlMode = "POS";
|
||||
if (!string.IsNullOrEmpty(datas[1]))
|
||||
{
|
||||
_positionValue = datas[1];
|
||||
}
|
||||
OnWriteMessage(msg + "\r");
|
||||
}
|
||||
break;
|
||||
case "PRS":
|
||||
{
|
||||
_controlMode = "PRESS";
|
||||
if (!string.IsNullOrEmpty(datas[1]))
|
||||
{
|
||||
var array = datas[1].Split(',');
|
||||
_pressureValue = array[array.Length - 1];
|
||||
}
|
||||
OnWriteMessage(msg + "\r");
|
||||
}
|
||||
break;
|
||||
case "CAL":
|
||||
{
|
||||
_controlMode = "CALIB";
|
||||
OnWriteMessage(msg + "\r");
|
||||
}
|
||||
break;
|
||||
case "prs":
|
||||
{
|
||||
OnWriteMessage($"prs:{_pressureValue}" + "\r");
|
||||
}
|
||||
break;
|
||||
case "pos":
|
||||
{
|
||||
OnWriteMessage($"pos:{_positionValue}" + "\r");
|
||||
}
|
||||
break;
|
||||
case "sts":
|
||||
{
|
||||
OnWriteMessage($"sts:{_accessMode},{_controlMode},{_warningInformation},{_cycleCounter}" + "\r");
|
||||
|
||||
if (_controlMode == "CALIB")
|
||||
_controlMode = "CLOSE";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.ThrottleValves.KITZ.SimThrottleValveView"
|
||||
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: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">
|
||||
|
||||
</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,78 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
using Aitex.Core.Utilities;
|
||||
using MECF.Framework.Simulator.Core.Commons;
|
||||
using MECF.Framework.Simulator.Core.LoadPorts;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.ThrottleValves.KITZ
|
||||
{
|
||||
/// <summary>
|
||||
/// OmronCIDRWView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SimThrottleValveView : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty PortProperty = DependencyProperty.Register(
|
||||
"Port", typeof(string), typeof(SimThrottleValveView),
|
||||
new FrameworkPropertyMetadata("COM9", FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public string Port
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this.GetValue(PortProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetValue(PortProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public SimThrottleValveView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Loaded += OnViewLoaded;
|
||||
}
|
||||
|
||||
private void OnViewLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext == null)
|
||||
{
|
||||
DataContext = new SimThrottleValveViewModel( Port );
|
||||
(DataContext as TimerViewModelBase).Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SimThrottleValveViewModel : SerialPortDeviceViewModel
|
||||
{
|
||||
public string Title
|
||||
{
|
||||
get { return "KITZ Throttle Valve Simulator"; }
|
||||
}
|
||||
|
||||
private SimThrottleValve _reader;
|
||||
|
||||
//private string _value;
|
||||
|
||||
[IgnorePropertyChange]
|
||||
public string ResultValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reader.ResultValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reader.ResultValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SimThrottleValveViewModel(string port) : base("SimThrottleValveViewModel")
|
||||
{
|
||||
_reader = new SimThrottleValve(port);
|
||||
Init(_reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user