首次上传

This commit is contained in:
hanqiangqiang
2026-06-15 10:56:30 +08:00
commit b0213b94d6
4160 changed files with 736101 additions and 0 deletions
@@ -0,0 +1,236 @@
using MECF.Framework.Simulator.Core.Driver;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
namespace MECF.Framework.Simulator.Core.Pumps.DRYVacuum
{
class DRYVacuumPump : SerialPortDeviceSimulator
{
Stopwatch _timer = new Stopwatch();
private System.Timers.Timer _tick;
Random _rd = new Random();
public event Action<string> receiveMsg;
public bool IsRunS { get; set; }
public bool IsMPS { get; set; }
public bool IsBPS { get; set; }
public bool IsAlarmRondom { get; set; }
public bool IsAlarm { get; set; }
private object _locker = new object();
public DRYVacuumPump(string port)
: base(port, -1, "\r", ' ', false)
{
// ResultValue = "";
_tick = new System.Timers.Timer();
_tick.Interval = 200;
_tick.Elapsed += _tick_Elapsed;
_tick.Start();
IsRunS = false;
IsMPS = false;
IsBPS = false;
IsAlarmRondom = false;
IsAlarm = false;
}
private byte[] GetRandomValue()
{
Thread.Sleep(20);
Random random = new Random();
return Encoding.ASCII.GetBytes(random.Next(16).ToString());
}
private byte GetValue()
{
Random random = new Random();
return (byte)random.Next(16);
}
private void _tick_Elapsed(object sender, ElapsedEventArgs e)
{
lock (_locker)
{
if (_timer.IsRunning && _timer.Elapsed > TimeSpan.FromSeconds(10))
{
_timer.Stop();
//IsAtSpeed = true;
}
}
}
protected override void ProcessUnsplitMessage(byte[] message)
{
if (message.Length != 8)
{ return; }
//var arry = ModRTU_CRC(message.Take(6).ToArray()).Skip(2).ToArray();
//if (CheckModRTU_CRC(arry) != CheckModRTU_CRC(message.Skip(2).ToArray()))
//{ return; }
base.ProcessUnsplitMessage(message);
byte prefix = message[0];
var mw = message.Take(4);
var mws = mw.Skip(1);
string command = Encoding.ASCII.GetString(message.Take(4).Skip(1).ToArray());
byte AddressHigh = (byte)(message[2]);
byte AddressLow = message[3];
switch (command)
{
case "M21":
{
byte[] speedmsg = new byte[27];
speedmsg[0] = message[0];
speedmsg[1] = message[1];
speedmsg[2] = message[2];
speedmsg[3] = message[3];
if (IsRunS)
speedmsg[4] = Encoding.ASCII.GetBytes("S")[0];
else speedmsg[4] = Encoding.ASCII.GetBytes("N")[0];
if (IsMPS)
speedmsg[5] = Encoding.ASCII.GetBytes("S")[0];
else speedmsg[5] = Encoding.ASCII.GetBytes("R")[0];
if (IsBPS)
speedmsg[6] = Encoding.ASCII.GetBytes("S")[0];
else speedmsg[6] = Encoding.ASCII.GetBytes("R")[0];
if (IsAlarmRondom)
{
speedmsg[7] = GetRandomValue()[0];
speedmsg[8] = GetRandomValue()[0];
speedmsg[9] = GetRandomValue()[0];
speedmsg[10] = GetRandomValue()[0];
speedmsg[11] = GetRandomValue()[0];
speedmsg[12] = GetRandomValue()[0];
speedmsg[13] = GetRandomValue()[0];
speedmsg[14] = GetRandomValue()[0];
speedmsg[15] = GetRandomValue()[0];
speedmsg[16] = GetRandomValue()[0];
speedmsg[17] = GetRandomValue()[0];
speedmsg[18] = GetRandomValue()[0];
speedmsg[19] = GetRandomValue()[0];
speedmsg[20] = GetRandomValue()[0];
speedmsg[21] = GetRandomValue()[0];
speedmsg[22] = GetRandomValue()[0];
}
else
{
if (IsAlarm)
{
speedmsg[7] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[8] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[9] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[10] = Encoding.ASCII.GetBytes("F")[0];
speedmsg[11] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[12] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[13] = Encoding.ASCII.GetBytes("2")[0];
speedmsg[14] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[15] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[16] = Encoding.ASCII.GetBytes("0")[0]; ;
speedmsg[17] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[18] = Encoding.ASCII.GetBytes("4")[0];
speedmsg[19] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[20] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[21] = Encoding.ASCII.GetBytes("2")[0];
speedmsg[22] = Encoding.ASCII.GetBytes("3")[0];
}
else
{
speedmsg[7] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[8] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[9] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[10] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[11] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[12] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[13] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[14] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[15] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[16] = Encoding.ASCII.GetBytes("0")[0]; ;
speedmsg[17] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[18] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[19] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[20] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[21] = Encoding.ASCII.GetBytes("0")[0];
speedmsg[22] = Encoding.ASCII.GetBytes("0")[0];
}
}
speedmsg[23] =0x03;
var CheckLow = SUMCHECK(speedmsg.Take(24).ToArray());
speedmsg[24] = Convert.ToByte(CheckLow[0]); ;
speedmsg[25] = Convert.ToByte(CheckLow[1]); ;
speedmsg[26] =0x0D;
OnWriteMessage(speedmsg);
}
break;
}
}
public byte[] ModRTU_CRC(byte[] value)
{
var val = 0xFFFF;
for (int i = 0; i < value.Length; i++)
{
val ^= value[i];
for (int j = 0; j < 8; j++)
{
var xdabit = (int)(val & 0x01);
val >>= 1;
if (xdabit == 1)
val ^= 0xA001;
}
}
if (val == 0x0000)
return value;
var arg = value.ToList();
arg.Add((byte)(val & 0xFF));
arg.Add((byte)(val >> 8));
return arg.ToArray();
}
public static string SUMCHECK(byte[] buffer)
{
// byte[] buffer = Encoding.ASCII.GetBytes(command);
int sum = 0;
for (int i = 0; i < buffer.Length; i++)
{
sum += Convert.ToInt16(buffer[i]);
}
var SUM = 0x02 + sum + 0x03;
return (SUM & 0xff).ToString("X2");
}
private static byte CheckModRTU_CRC(byte[] buffer)
{
//ushort crc = 0xFFFF;
// var buf = System.Text.Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, buffer));
var buf = buffer;
var len = buffer.Length;
byte temp = buffer[0];
for (int i = 1; i < buffer.Length; i++)
{
temp = (byte)(temp ^ buffer[i]);
}
return (byte)temp;
}
}
}
@@ -0,0 +1,109 @@
<UserControl x:Class="MECF.Framework.Simulator.Core.Pumps.DRYVacuum.DRYVacuumPumpView"
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.FFUs"
mc:Ignorable="d"
xmlns:commons="clr-namespace:MECF.Framework.Simulator.Core.Commons"
Height="900" Width="900" Background="LightBlue" Initialized="UserControl_Initialized">
<UserControl.Resources>
<commons:ConnectionStatusBackgroundConverter x:Key="connectionStatusBackgroundConverter"/>
<Style TargetType="Label">
<Setter Property="FontSize" Value="16" />
<Setter Property="Padding" Value="10,0,10,0" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="150"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="400"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Title}" FontSize="20" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Height="50" Background="{Binding IsConnected, Converter={StaticResource connectionStatusBackgroundConverter}}" ></Label>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<ComboBox Name="PortName" Text="{Binding PortSetPoint}" VerticalContentAlignment="Center" Width="120" Margin="20,0,0,0" Height="35" />
<Label Content="Listen port:"></Label>
<Label Content="{Binding LocalPort}"></Label>
<Label Content="{Binding ConnectionStatus}"></Label>
<Button Width="100" Height="35" Content="Enable" Command="{Binding EnableCommand}" IsEnabled="{Binding IsEnableEnable}"></Button>
<Button Width="100" Height="35" Content="Disable" Command="{Binding DisableCommand}" IsEnabled="{Binding IsEnableDisable}"></Button>
<Label Content="Connection:"></Label>
<Label Content="{Binding RemoteConnection}"></Label>
</StackPanel>
</Grid>
<Canvas Grid.Row="1" Width="900">
<!--<TextBox Text="{Binding ActualTemp, UpdateSourceTrigger=PropertyChanged }" Canvas.Left="250" Canvas.Top="19" Margin="0" Width="94"></TextBox>-->
<CheckBox Content=" Power-saving operation mode" IsChecked="{Binding IsRunS}" Canvas.Left="56" Canvas.Top="28" RenderTransformOrigin="1.288,-4.39"></CheckBox>
<!--<TextBlock Text="SettingTemp:" Canvas.Left="151" Canvas.Top="88" ></TextBlock>
<TextBox Text="{Binding SettingTemp, UpdateSourceTrigger=PropertyChanged }" Canvas.Left="250" Canvas.Top="76" Margin="0" Width="94"></TextBox>-->
<CheckBox Content="MP-S(being stopped)" IsChecked="{Binding IsMPS}" Canvas.Left="56" Canvas.Top="65" RenderTransformOrigin="1.288,-4.39"></CheckBox>
<CheckBox Content="BP-S(being stopped)" IsChecked="{Binding IsBPS}" Canvas.Left="56" Canvas.Top="103" RenderTransformOrigin="1.288,-4.39"></CheckBox>
<CheckBox Content="AlarmRondom" IsChecked="{Binding IsAlarmRondom}" Canvas.Left="458" Canvas.Top="28" RenderTransformOrigin="1.288,-4.39"></CheckBox>
<CheckBox Content="Alarm" IsChecked="{Binding IsAlarm}" Canvas.Left="458" Canvas.Top="54" RenderTransformOrigin="1.288,-4.39"></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,58 @@
using Aitex.Core.UI.MVVM;
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.DRYVacuum
{
/// <summary>
/// DRYVacuumPumpView.xaml 的交互逻辑
/// </summary>
public partial class DRYVacuumPumpView : UserControl
{
public static int CurrentTick = 0;
public DRYVacuumPumpView()
{
InitializeComponent();
DataContext = new DRYVacuumPumpViewModel((CurrentTick++ == 0) ? "COM42" : "COM46");
(DataContext as TimerViewModelBase).Start();
this.Loaded += OnViewLoaded;
}
private void OnViewLoaded(object sender, RoutedEventArgs e)
{
if (DataContext == null)
{
}
}
private void UserControl_Initialized(object sender, EventArgs e)
{
InitSerialPort();
}
//GetPortNames()方法:获取当前计算机的串行端口名的数组
private void InitSerialPort()
{
PortName.Items.Clear();
foreach (string com in System.IO.Ports.SerialPort.GetPortNames())
{
PortName.Items.Add(com);
}
PortName.SelectedIndex = 0;
}
}
}
@@ -0,0 +1,86 @@
using MECF.Framework.Simulator.Core.Commons;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MECF.Framework.Simulator.Core.Pumps.DRYVacuum
{
class DRYVacuumPumpViewModel : SerialPortDeviceViewModel
{
private DRYVacuumPump _reader;
public string ResultValue { get; set; }
public bool IsRunS
{
get
{
return _reader.IsRunS;
}
set
{
_reader.IsRunS = value;
}
}
public bool IsMPS
{
get
{
return _reader.IsMPS;
}
set
{
_reader.IsMPS = value;
}
}
public bool IsBPS
{
get
{
return _reader.IsBPS;
}
set
{
_reader.IsBPS = value;
}
}
public bool IsAlarmRondom
{
get
{
return _reader.IsAlarmRondom;
}
set
{
_reader.IsAlarmRondom = value;
}
}
public bool IsAlarm
{
get
{
return _reader.IsAlarm;
}
set
{
_reader.IsAlarm = value;
}
}
public DRYVacuumPumpViewModel(string port) : base("DRYVacuumPumpViewModel")
{
_reader = new DRYVacuumPump(port);
Init(_reader, true);
_reader.receiveMsg += _reader_receiveMsg;
}
private void _reader_receiveMsg(string obj)
{
ResultValue = obj;
}
}
}