首次上传
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.Pumps.Magpower.MagpowerPumpSimulatorView"
|
||||
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.Pumps"
|
||||
mc:Ignorable="d"
|
||||
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>
|
||||
|
||||
<CheckBox Content="Pump on" IsChecked="{Binding IsPumpOn}" Canvas.Left="36" Canvas.Top="86"></CheckBox>
|
||||
|
||||
<CheckBox Content="OverTemp" IsChecked="{Binding IsOverTemp}" Canvas.Left="172" Canvas.Top="86"></CheckBox>
|
||||
|
||||
<CheckBox Content="At Speed" IsChecked="{Binding IsAtSpeed}" Canvas.Left="324" Canvas.Top="90"></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,117 @@
|
||||
using Aitex.Core.UI.MVVM;
|
||||
using Aitex.Core.Utilities;
|
||||
using MECF.Framework.Simulator.Core.Commons;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.Pumps.Magpower
|
||||
{
|
||||
/// <summary>
|
||||
/// MagpowerPumpSimulatorView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
|
||||
public partial class MagpowerPumpSimulatorView : UserControl
|
||||
{
|
||||
public MagpowerPumpSimulatorView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = new MagpowerPumpSimulatorViewModel("COM22");
|
||||
this.Loaded += MagpowerPumpSimulatorView_Loaded;
|
||||
}
|
||||
|
||||
private void MagpowerPumpSimulatorView_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
(DataContext as MagpowerPumpSimulatorViewModel).EnableTimer(true);
|
||||
}
|
||||
}
|
||||
|
||||
class MagpowerPumpSimulatorViewModel : SerialPortDeviceViewModel
|
||||
{
|
||||
public string Title
|
||||
{
|
||||
get { return "Magpower Pump Simulator"; }
|
||||
}
|
||||
|
||||
private MagpowerSimulator _reader;
|
||||
|
||||
public bool IsFailed
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reader.Failed;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reader.Failed = value;
|
||||
}
|
||||
}
|
||||
public bool IsPumpOn
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reader.IsPumpOn;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reader.IsPumpOn = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsOverTemp
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reader.IsOverTemp;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reader.IsOverTemp = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAtSpeed
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reader.IsAtSpeed;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reader.IsAtSpeed = value;
|
||||
}
|
||||
}
|
||||
|
||||
//private string _value;
|
||||
|
||||
[IgnorePropertyChange]
|
||||
public string ResultValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _reader.ResultValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
_reader.ResultValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MagpowerPumpSimulatorViewModel(string port) : base("MagpowerPumpSimulatorViewModel")
|
||||
{
|
||||
_reader = new MagpowerSimulator(port);
|
||||
Init(_reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.Pumps.Magpower
|
||||
{
|
||||
class MagpowerSimulator : SerialPortDeviceSimulator
|
||||
{
|
||||
public bool Failed { get; set; }
|
||||
|
||||
public bool IsPumpOn { get; set; }
|
||||
|
||||
public bool IsNormalSpeed { get; set; }
|
||||
|
||||
public bool IsOverTemp { get; set; }
|
||||
|
||||
public bool IsAtSpeed { get; set; }
|
||||
|
||||
Stopwatch _timer = new Stopwatch();
|
||||
|
||||
private System.Timers.Timer _tick;
|
||||
Random _rd = new Random();
|
||||
|
||||
private object _locker = new object();
|
||||
|
||||
public string ResultValue { get; set; }
|
||||
|
||||
public MagpowerSimulator(string port)
|
||||
: base(port, -1, "\r", ' ')
|
||||
{
|
||||
ResultValue = "";
|
||||
|
||||
_tick = new System.Timers.Timer();
|
||||
_tick.Interval = 200;
|
||||
|
||||
_tick.Elapsed += _tick_Elapsed;
|
||||
_tick.Start();
|
||||
|
||||
IsAtSpeed = true;
|
||||
}
|
||||
|
||||
private void _tick_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
if (_timer.IsRunning && _timer.Elapsed > TimeSpan.FromSeconds(10))
|
||||
{
|
||||
_timer.Stop();
|
||||
|
||||
IsAtSpeed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Byte[] GetBytesFromBinaryString(String binary)
|
||||
{
|
||||
var list = new List<Byte>();
|
||||
|
||||
for (int i = 0; i < binary.Length; i += 8)
|
||||
{
|
||||
String t = binary.Substring(i, 8);
|
||||
|
||||
list.Add(Convert.ToByte(t, 2));
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
private string GetCharsFormFromBinaryString(String binary)
|
||||
{
|
||||
return Encoding.ASCII.GetString(GetBytesFromBinaryString(binary));
|
||||
}
|
||||
|
||||
private int _speed = 1200;
|
||||
int iStep = 0;
|
||||
protected override void ProcessUnsplitMessage(string msg)
|
||||
{
|
||||
//if (!Failed)
|
||||
{
|
||||
iStep++;
|
||||
|
||||
if (msg.Contains("TMPON"))
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (!IsPumpOn)
|
||||
{
|
||||
IsPumpOn = true;
|
||||
IsAtSpeed = false;
|
||||
_timer.Restart();
|
||||
|
||||
OnWriteMessage("#001,OK\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
OnWriteMessage("#001,Err3\r");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.Contains("TMPOFF"))
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (IsPumpOn)
|
||||
{
|
||||
IsPumpOn = false;
|
||||
IsAtSpeed = false;
|
||||
|
||||
_timer.Restart();
|
||||
|
||||
OnWriteMessage("#001,OK\r");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
OnWriteMessage("#001,Err3\r");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.Contains("NSP"))
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (!IsNormalSpeed)
|
||||
{
|
||||
IsNormalSpeed = true;
|
||||
_timer.Restart();
|
||||
|
||||
OnWriteMessage("#001,OK\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
OnWriteMessage("#001,Err3\r");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.Contains("SBY"))
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (IsNormalSpeed)
|
||||
{
|
||||
IsNormalSpeed = false;
|
||||
_timer.Restart();
|
||||
|
||||
OnWriteMessage("#001,OK\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
OnWriteMessage("#001,Err3\r");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (msg.Contains("DEF"))
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_timer.Restart();
|
||||
string error = iStep % 10 < 5 ? "Err2,Err3" : "OK";
|
||||
OnWriteMessage($"#001,{error}\r");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.Contains("SPD"))
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_timer.Restart();
|
||||
|
||||
string sSpeed = _speed.ToString("D6");
|
||||
OnWriteMessage($"#001,{sSpeed} rpm\r");
|
||||
|
||||
_speed++;
|
||||
if(_speed > 1210)
|
||||
{
|
||||
_speed = 1200;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.Contains("STA"))
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_timer.Restart();
|
||||
|
||||
string pumpStatus1 = GetCharsFormFromBinaryString("00101011");
|
||||
string pumpStatus2 = GetCharsFormFromBinaryString("00000111");
|
||||
string pumpStatus = iStep % 10 <5 ? pumpStatus2 : pumpStatus1;
|
||||
string pumpTemp = iStep % 10 < 5 ? "025" : "030";
|
||||
OnWriteMessage($"#001,s{pumpStatus}s,rrrrr,vvv,www,xxx,yyy,zzz,aa,bbbbb,{pumpTemp},ddd,ggggggggggggggggggggggggg\r");
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (msg.Contains("SEL10"))
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_timer.Restart();
|
||||
|
||||
string r = iStep % 10 < 5 ? "1" : "0";
|
||||
OnWriteMessage($"#001,a,u,1,b,{r}\r");
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user