首次上传
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
public partial class E84SimulatorUnitView : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty LoadPortNameProperty = DependencyProperty.Register(
|
||||
"LoadPortName", typeof(string), typeof(E84SimulatorUnitView),
|
||||
null);
|
||||
|
||||
public string LoadPortName
|
||||
{
|
||||
get => (string) GetValue(LoadPortNameProperty);
|
||||
set => SetValue(LoadPortNameProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsFloorVehicleProperty = DependencyProperty.Register(
|
||||
"IsFloorVehicle", typeof(bool), typeof(E84SimulatorUnitView),
|
||||
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public bool IsFloorVehicle
|
||||
{
|
||||
get => (bool) GetValue(IsFloorVehicleProperty);
|
||||
set => SetValue(IsFloorVehicleProperty, value);
|
||||
}
|
||||
|
||||
private E84SimulatorUnitViewModel _viewModel;
|
||||
|
||||
public ICommand E84Command { get; set; }
|
||||
|
||||
public E84SimulatorUnitView()
|
||||
{
|
||||
InitializeComponent();
|
||||
E84Command = new DelegateCommand<string>(E84Operation);
|
||||
this.Loaded += OnViewLoaded;
|
||||
}
|
||||
|
||||
private void E84Operation(string obj)
|
||||
{
|
||||
var x = obj.ToString();
|
||||
// var command = CommandHelper.GetCommandItem(obj);
|
||||
// var lstParameter = new List<object>
|
||||
// {
|
||||
// Station
|
||||
// };
|
||||
//lstParameter.AddRange(obj.Parameters);
|
||||
//InvokeClient.Instance.Service.DoOperation(command.CommandName, lstParameter.ToArray());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnViewLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext == null)
|
||||
{
|
||||
_viewModel = new E84SimulatorUnitViewModel(LoadPortName, IsFloorVehicle);
|
||||
DataContext = _viewModel;
|
||||
(DataContext as TimerViewModelBase)?.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button button)
|
||||
{
|
||||
if ((string) button.Content == "Pick From Lp")
|
||||
{
|
||||
_viewModel._simulatorE84.Stage = E84Stage.TD0;
|
||||
//_viewModel._simulatorE84.LReq;
|
||||
}
|
||||
else
|
||||
{
|
||||
_viewModel._simulatorE84.Stage = E84Stage.TD0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class E84SimulatorUnitViewModel: TimerViewModelBase
|
||||
{
|
||||
public readonly SimulatorE84 _simulatorE84;
|
||||
|
||||
public bool IsFloorMode => _simulatorE84.IsFloor;
|
||||
public bool IsLoading => _simulatorE84.IsLoading;
|
||||
public bool IsUnloading => _simulatorE84.IsUnLoading;
|
||||
|
||||
public bool LReq => _simulatorE84.LReq;
|
||||
public bool UReq => _simulatorE84.UReq;
|
||||
public bool Ready => _simulatorE84.Ready;
|
||||
public bool HoAvbl => _simulatorE84.HoAvbl;
|
||||
public bool ES => _simulatorE84.ES;
|
||||
public bool VA => _simulatorE84.VA;
|
||||
public bool VS0 => _simulatorE84.VS0;
|
||||
public bool VS1 => _simulatorE84.VS1;
|
||||
|
||||
public bool ON => _simulatorE84.ON;
|
||||
public bool VALID => _simulatorE84.VALID;
|
||||
public bool CS_0 => _simulatorE84.CS_0;
|
||||
public bool TR_REQ => _simulatorE84.TR_REQ;
|
||||
public bool BUSY => _simulatorE84.BUSY;
|
||||
public bool COMPT => _simulatorE84.COMPT;
|
||||
public bool CONT => _simulatorE84.CONT;
|
||||
public bool AM_AVBL => _simulatorE84.AM_AVBL;
|
||||
public E84SimulatorUnitViewModel(string loadPortName, bool isFloorVehicle) : base("E84SimulatorUnitViewModel")
|
||||
{
|
||||
_simulatorE84 = new SimulatorE84(loadPortName, isFloorVehicle);
|
||||
}
|
||||
|
||||
protected override void Poll()
|
||||
{
|
||||
InvokePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.IoProviders.E84SimulatorUnitView"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="500" d:DesignWidth="500">
|
||||
<Grid>
|
||||
<GroupBox Header="E84" HorizontalAlignment="Left" Height="auto" VerticalAlignment="Top" Width="auto">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="5*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0">
|
||||
<CheckBox Content="IsFloorMode" IsChecked="{Binding IsFloorMode,Mode=OneWay}" IsEnabled="True"/>
|
||||
<CheckBox Content="IsLoading" IsChecked="{Binding IsLoading,Mode=OneWay}" />
|
||||
<CheckBox Content="IsUnloadingON" IsChecked="{Binding IsUnloading,Mode=OneWay}" />
|
||||
<Button Content="Pick From Lp" Click="ButtonBase_OnClick"
|
||||
CommandParameter="Pick"/>
|
||||
<Button Content="Place To Lp" Command="{Binding E84Command}"
|
||||
CommandParameter="Place"/>
|
||||
</StackPanel>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="DI" Grid.Column="0">
|
||||
<StackPanel>
|
||||
<CheckBox Content="ON" IsChecked="{Binding ON,Mode=OneWay}" />
|
||||
<CheckBox Content="VALID" IsChecked="{Binding VALID,Mode=OneWay}" />
|
||||
<CheckBox Content="CS_0" IsChecked="{Binding CS_0,Mode=OneWay}" />
|
||||
<CheckBox Content="TR_REQ" IsChecked="{Binding TR_REQ,Mode=OneWay}" />
|
||||
<CheckBox Content="BUSY" IsChecked="{Binding BUSY,Mode=OneWay}" />
|
||||
<CheckBox Content="COMPT" IsChecked="{Binding COMPT,Mode=OneWay}" />
|
||||
<CheckBox Content="CONT" IsChecked="{Binding CONT,Mode=OneWay}" />
|
||||
<CheckBox Content="AM_AVBL" IsChecked="{Binding AM_AVBL,Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
<GroupBox Header="DO" Grid.Column="1">
|
||||
<StackPanel>
|
||||
<CheckBox Content="L_REQ" IsChecked="{Binding LReq,Mode=OneWay}" />
|
||||
<CheckBox Content="U_REQ" IsChecked="{Binding UReq,Mode=OneWay}" />
|
||||
<CheckBox Content="READY" IsChecked="{Binding Ready,Mode=OneWay}" />
|
||||
<CheckBox Content="HO_AVBL" IsChecked="{Binding HoAvbl,Mode=OneWay}" />
|
||||
<CheckBox Content="ES" IsChecked="{Binding ES,Mode=OneWay}" />
|
||||
<CheckBox Content="VA" IsChecked="{Binding VA,Mode=OneWay}" />
|
||||
<CheckBox Content="VS_O" IsChecked="{Binding VS0,Mode=OneWay}" />
|
||||
<CheckBox Content="VS_1" IsChecked="{Binding VS1,Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
using MECF.Framework.Common.IOCore;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
public class IOViewModel : TimerViewModelBase
|
||||
{
|
||||
public SimulatorIO Plc { get; set; }
|
||||
|
||||
public ObservableCollection<NotifiableIoItem> DiItemList { get; set; }
|
||||
public ObservableCollection<NotifiableIoItem> DoItemList { get; set; }
|
||||
public ObservableCollection<NotifiableIoItem> AiItemList { get; set; }
|
||||
public ObservableCollection<NotifiableIoItem> AoItemList { get; set; }
|
||||
|
||||
public IOViewModel(int port, string source, string ioMapPathFile) : base(nameof(IOViewModel))
|
||||
{
|
||||
Plc = new SimulatorIO(port, source, ioMapPathFile);
|
||||
|
||||
DiItemList = Plc.DiItemList;
|
||||
DoItemList = Plc.DoItemList;
|
||||
AiItemList = Plc.AiItemList;
|
||||
AoItemList = Plc.AoItemList;
|
||||
}
|
||||
|
||||
|
||||
protected override void Poll()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Aitex.Core.RT.Log;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.RT.Core.IoProviders;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
public class PlcBuffer
|
||||
{
|
||||
public IoType Type;
|
||||
public int Offset;
|
||||
public int Size;
|
||||
public byte[] Buffer;
|
||||
public bool[] BoolValue;
|
||||
public ushort[] ShortValue;
|
||||
public float[] FloatValue;
|
||||
}
|
||||
|
||||
public class MCProtocolPlcSimulator
|
||||
{
|
||||
public event Action<string> NotifyEvent;
|
||||
|
||||
private PeriodicJob _threadSocket;
|
||||
private PeriodicJob _threadTimer;
|
||||
|
||||
private Socket _socketServer;
|
||||
|
||||
private string _ip;
|
||||
|
||||
|
||||
private bool _stopFlag;
|
||||
|
||||
protected List<PlcBuffer> _buffers = new List<PlcBuffer>();
|
||||
|
||||
private int _port = 6731;
|
||||
private int _socketId = 101;
|
||||
private int _stationId = 102;
|
||||
|
||||
private byte[] _bufferIn;
|
||||
private byte[] _bufferOut;
|
||||
|
||||
|
||||
private MCProtocol.MC_RESPONSE_HEADER _response;
|
||||
|
||||
public MCProtocolPlcSimulator(string ip, int port)
|
||||
{
|
||||
_ip = ip;
|
||||
|
||||
_port = port;
|
||||
|
||||
_response = new MCProtocol.MC_RESPONSE_HEADER()
|
||||
{
|
||||
ProtocolId = MCProtocol.MC_SUBHEADER_RESPONSE_MESSAGE,
|
||||
NetworkId = (byte)_socketId,
|
||||
StationId = (byte)_stationId,
|
||||
RequestIoNumber = MCProtocol.MC_REQUEST_MODULE_IO_NUMBER,
|
||||
RequestStationNumber = MCProtocol.MC_REQUEST_MODULE_STATION_NUMBER,
|
||||
ResponseDataLen = 0,
|
||||
CompleteCode = (ushort)(MCProtocol.MC_COMPLETE_CODE_SUCCESS ),
|
||||
};
|
||||
|
||||
_bufferOut = new byte[2048];
|
||||
_bufferIn = new byte[2048];
|
||||
|
||||
_socketServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
_threadSocket = new PeriodicJob(50, OnMonitor, "MCProtocolPlcSimulator",true);
|
||||
|
||||
_threadTimer = new PeriodicJob(1000, OnTimer, "MCProtocolPlcSimulatorTimer", true);
|
||||
}
|
||||
|
||||
protected virtual bool OnTimer()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private void PerformNotifyEvent(string msg)
|
||||
{
|
||||
if (NotifyEvent != null)
|
||||
{
|
||||
NotifyEvent(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private bool OnMonitor()
|
||||
{
|
||||
try
|
||||
{
|
||||
EndPoint ep = new IPEndPoint(IPAddress.Loopback, _port);
|
||||
_socketServer.Bind(ep);
|
||||
_socketServer.Listen(3);
|
||||
|
||||
Socket s;
|
||||
while (!_stopFlag)
|
||||
{
|
||||
PerformNotifyEvent("Waiting for connection ...");
|
||||
s = _socketServer.Accept();
|
||||
PerformNotifyEvent("Connected.");
|
||||
|
||||
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
|
||||
try
|
||||
{
|
||||
while (!_stopFlag && OnTransmission(s))
|
||||
{
|
||||
PerformNotifyEvent("Waiting for another command ...");
|
||||
}
|
||||
PerformNotifyEvent("receive error buffer content and exit ...");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
return true;
|
||||
}
|
||||
PerformNotifyEvent("A client disconnected from port " + _port);
|
||||
s = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
try
|
||||
{
|
||||
_socketServer.Close();
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
_socketServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_threadSocket.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_stopFlag = true;
|
||||
_threadSocket.Stop();
|
||||
}
|
||||
|
||||
protected bool OnTransmission(Socket s)
|
||||
{
|
||||
int size = s.Receive(_bufferIn, 0, MCProtocol.MC_QHEADER_COMMAND_SIZE, SocketFlags.None);
|
||||
if (size < MCProtocol.MC_QHEADER_COMMAND_SIZE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
MCProtocol.MC_COMMAND_HEADER header = MCProtocol.ToStruct<MCProtocol.MC_COMMAND_HEADER>(_bufferIn);
|
||||
int dataLength = header.RequestDataLen - MCProtocol.MC_BATCH_COMMAND_SIZE - MCProtocol.JUNK_SIZE;
|
||||
if (dataLength < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
size = s.Receive(_bufferIn, 0, MCProtocol.MC_BATCH_COMMAND_SIZE, SocketFlags.None);
|
||||
if (size < MCProtocol.MC_BATCH_COMMAND_SIZE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
MCProtocol.MC_BATCH_COMMAND cmd = MCProtocol.ToStruct<MCProtocol.MC_BATCH_COMMAND>(_bufferIn);
|
||||
int offset = cmd.Reserved * (0xFFFF + 1) + cmd.HeadAddr;
|
||||
if (dataLength > 0)
|
||||
{
|
||||
size = s.Receive(_bufferIn, 0, dataLength, SocketFlags.None);
|
||||
if (size < dataLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
byte[] data = null;
|
||||
if (cmd.Command == MCProtocol.MC_COMMAND_BATCH_READ)
|
||||
{
|
||||
|
||||
data = GetData(offset, cmd.DevicePoints, cmd.SubCommand == MCProtocol.MC_SUBCOMMAND_BIT_UNITS);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetData(offset, _bufferIn, dataLength, cmd.SubCommand == MCProtocol.MC_SUBCOMMAND_BIT_UNITS);
|
||||
}
|
||||
|
||||
_response.ResponseDataLen = (ushort)(MCProtocol.JUNK_SIZE + (data == null ? 0 : data.Length));
|
||||
|
||||
byte[] response = MCProtocol.Struct2Bytes(_response);
|
||||
Array.Copy(response, 0, _bufferOut, 0, response.Length);
|
||||
s.Send(_bufferOut, response.Length, SocketFlags.None);
|
||||
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
Array.Copy(data, 0, _bufferOut, 0, data.Length);
|
||||
|
||||
s.Send(_bufferOut, data.Length, SocketFlags.None);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected void SetData(int headAddr, byte[] data, int length, bool isBit)
|
||||
{
|
||||
IoType ioType = isBit ? IoType.DO : IoType.AO;
|
||||
|
||||
if (ioType == IoType.DO)
|
||||
{
|
||||
bool[] boolData = MCProtocol.TransByteDataToBoolArray(data, 0, length);
|
||||
|
||||
PlcBuffer buffer = _buffers.Find(x => x.Type == ioType && x.Size == boolData.Length && x.Offset == headAddr);
|
||||
if (buffer != null)
|
||||
{
|
||||
buffer.BoolValue = boolData;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ushort[] shortValue = MCProtocol.Byte2Ushort(data, 0, length);
|
||||
PlcBuffer buffer = _buffers.Find(x=>x.Type == ioType && x.Offset == headAddr);
|
||||
if (buffer != null && shortValue != null && shortValue.Length > 0 && buffer.ShortValue.Length >= headAddr + shortValue.Length)
|
||||
{
|
||||
Array.Copy(shortValue, 0, buffer.ShortValue, headAddr, shortValue.Length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void SetDi(int headAddr, int offset, bool value)
|
||||
{
|
||||
PlcBuffer buffer = _buffers.Find(x =>x.Type == IoType.DI && x.Offset == headAddr );
|
||||
if (buffer != null)
|
||||
{
|
||||
buffer.BoolValue[offset] = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected void SetAi(int headAddr, int offset, ushort value)
|
||||
{
|
||||
PlcBuffer buffer = _buffers.Find(x => x.Type == IoType.AI && x.Offset == headAddr );
|
||||
if (buffer != null)
|
||||
{
|
||||
buffer.ShortValue[offset] = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual byte[] GetData(int headAddr, ushort length, bool isBit)
|
||||
{
|
||||
IoType ioType = isBit ? IoType.DI : IoType.AI;
|
||||
if(!isBit)
|
||||
{
|
||||
var tmp = _buffers.Find(x => x.Type == ioType && x.Offset == headAddr);
|
||||
if(tmp != null && tmp.ShortValue != null)
|
||||
{
|
||||
var remain = tmp.ShortValue.Length - headAddr;
|
||||
var size = remain >= length ? length : (remain > 0 ? remain : 0);
|
||||
if (size > 0)
|
||||
{
|
||||
ushort[] bf = new ushort[size];
|
||||
Array.Copy(tmp.ShortValue, headAddr, bf, 0, bf.Length);
|
||||
return MCProtocol.Ushort2Byte(bf);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PlcBuffer buffer = _buffers.Find(x => x.Type == ioType && x.Offset == headAddr);
|
||||
|
||||
if (buffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] result = null;
|
||||
if (ioType == IoType.DI)
|
||||
{
|
||||
bool[] value = buffer.BoolValue;
|
||||
int size = (value.Length + 1) / 2;
|
||||
result = new byte[size];
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (value[i * 2 + 0])
|
||||
result[i] += 0x10;
|
||||
if ((i * 2 + 1) < value.Length)
|
||||
{
|
||||
if (value[i * 2 + 1])
|
||||
result[i] += 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
//result = MCProtocol.TransBoolArrayToByteData(buffer.BoolValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = MCProtocol.Ushort2Byte(buffer.ShortValue);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
using Aitex.Core.RT.IOCore;
|
||||
using Aitex.Core.Util;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
public enum E84Stage
|
||||
{
|
||||
WaitForStation,
|
||||
IDLE,
|
||||
TD0, //when CS_0 wait for VALID
|
||||
TA1, //CS_0 and VALID wait for L_REQ(U_REQ)
|
||||
TP1, //when TA1 and TR_REQ is set
|
||||
TA2, //
|
||||
TP2,
|
||||
TP3,
|
||||
TP4,
|
||||
TA3,
|
||||
TP5
|
||||
}
|
||||
|
||||
public class SimulatorE84
|
||||
{
|
||||
#region sequence
|
||||
|
||||
/*
|
||||
* for loading sequence:
|
||||
* (1) Active set CS_0 *ON* then set VALID *ON* for valid confirm
|
||||
* A:CS_0 *ON* VALID *ON*
|
||||
* (2) Passive equipment set L_REQ *ON* if the load port is ready for loading operation / U_REQ for unload
|
||||
* A:CS_0 *ON* VALID *ON*
|
||||
* P:L_REQ *ON \\ U_REQ *ON*
|
||||
* (3) After active equipment receive the L_REQ/U_REQ *ON* set TR_REQ *ON*
|
||||
* A:TR_TRQ *ON* CS_0 *ON* VALID *ON*
|
||||
* P:L_REQ *ON \\ U_REQ *ON*
|
||||
* (4) After passive equipment turn the READY *ON*, active equipment BUSY set to *ON* and proceed handoff operation
|
||||
* A:BUSY *ON* TR_TRQ *ON* CS_0 *ON* VALID *ON*
|
||||
* P:READY *ON* L_REQ *ON \\ U_REQ *ON*
|
||||
* (5) When passive equipment turns the L_REQ(U_REQ) signal *OFF* when carrier is done processing
|
||||
* A:BUSY *ON* TR_TRQ *ON* CS_0 *ON* VALID *ON*
|
||||
* P:READY *ON*
|
||||
* (6) After finish the operation and the active equipment is out of conflict area,
|
||||
* active equipment turns the BUSY signal *OFF*(make sure after the L_REQ(R_REQ) was *OFF*)
|
||||
* A:TR_TRQ *ON* CS_0 *ON* VALID *ON*
|
||||
* P:READY *ON*
|
||||
* (7) After the BUSY *OFF*, active equipment set the TR_REQ signal *OFF*
|
||||
* A:CS_0 *ON* VALID *ON*
|
||||
* P:READY *ON*
|
||||
* (8) When finish those above, active equipment set the COMPT *ON*
|
||||
* A:COMPT *ON* CS_0 *ON* VALID *ON*
|
||||
* P:READY *ON*
|
||||
* (9) After COMPT *ON*, passive equipment should set the READY *OFF*
|
||||
* A:COMPT *ON* CS_0 *ON* VALID *ON*
|
||||
* P:
|
||||
* (10) After READY *OFF*, active set the signal all off
|
||||
* A:
|
||||
* P:
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
private readonly string _loadPortName;
|
||||
private PeriodicJob _thread;
|
||||
|
||||
public readonly bool IsFloor;
|
||||
|
||||
public bool IsLoading => Stage == E84Stage.TP2 && lReq;
|
||||
public bool IsUnLoading => Stage == E84Stage.TP2 && uReq;
|
||||
|
||||
|
||||
public string LoadPortName => _loadPortName;
|
||||
public bool LReq => lReq;
|
||||
public bool UReq => uReq;
|
||||
public bool Ready => ready;
|
||||
public bool HoAvbl => hoAvbl;
|
||||
public bool ES => es;
|
||||
public bool VA => va;
|
||||
public bool VS0 => vs0;
|
||||
public bool VS1 => vs1;
|
||||
|
||||
//inputs
|
||||
private bool lReq;
|
||||
private bool uReq;
|
||||
private bool ready;
|
||||
private bool hoAvbl;
|
||||
private bool es;
|
||||
private bool va;
|
||||
private bool vs0;
|
||||
private bool vs1;
|
||||
|
||||
private RD_TRIG _lReq = new RD_TRIG();
|
||||
private RD_TRIG _uReq = new RD_TRIG();
|
||||
private RD_TRIG _ready = new RD_TRIG();
|
||||
private RD_TRIG _hoAvbl = new RD_TRIG();
|
||||
private RD_TRIG _es = new RD_TRIG();
|
||||
private RD_TRIG _va = new RD_TRIG();
|
||||
private RD_TRIG _vs0 = new RD_TRIG();
|
||||
private RD_TRIG _vs1 = new RD_TRIG();
|
||||
|
||||
//outputs
|
||||
public bool ON => IO.DI[$"DI_{_loadPortName}_ON"].Value;
|
||||
public bool VALID => IO.DI[$"DI_{_loadPortName}_VALID"].Value;
|
||||
public bool CS_0 => IO.DI[$"DI_{_loadPortName}_CS_0"].Value;
|
||||
public bool TR_REQ => IO.DI[$"DI_{_loadPortName}_TR_REQ"].Value;
|
||||
public bool BUSY => IO.DI[$"DI_{_loadPortName}_BUSY"].Value;
|
||||
public bool COMPT => IO.DI[$"DI_{_loadPortName}_COMPT"].Value;
|
||||
public bool CONT => IO.DI[$"DI_{_loadPortName}_CONT"].Value;
|
||||
public bool AM_AVBL => IO.DI[$"DI_{_loadPortName}_AM_AVBL"].Value;
|
||||
|
||||
|
||||
public E84Stage Stage;
|
||||
|
||||
private readonly DeviceTimer _timerDelay = new DeviceTimer();
|
||||
|
||||
public SimulatorE84(string loadPortName, bool isFloor)
|
||||
{
|
||||
_loadPortName = loadPortName;
|
||||
IsFloor = isFloor;
|
||||
_thread = new PeriodicJob(50, OnMonitor, _loadPortName, true);
|
||||
Stage = E84Stage.IDLE;
|
||||
if (isFloor)
|
||||
IO.DI[$"DI_{_loadPortName}_AM_AVBL"].Value = true;
|
||||
_thread.Start();
|
||||
}
|
||||
|
||||
//DO_LP1_L_REQ Load Request
|
||||
//DO_LP1_U_REQ Unload Request
|
||||
//DO_LP1_READY Ready Signal
|
||||
//DO_LP1_HO_AVBL HandOff Available Always on
|
||||
//DO_LP1_ES Emergency Stop Always on
|
||||
//DO_LP1_VA Vehicle Arrive
|
||||
//DO_LP1_VS_O Carrier Stage 0
|
||||
//DO_LP1_VS_1 Carrier Stage 1
|
||||
private bool OnMonitor()
|
||||
{
|
||||
//inputs
|
||||
lReq = IO.DO[$"DO_{_loadPortName}_L_REQ"].Value;
|
||||
uReq = IO.DO[$"DO_{_loadPortName}_U_REQ"].Value;
|
||||
ready = IO.DO[$"DO_{_loadPortName}_READY"].Value;
|
||||
hoAvbl = IO.DO[$"DO_{_loadPortName}_HO_AVBL"].Value;
|
||||
es = IO.DO[$"DO_{_loadPortName}_ES"].Value;
|
||||
va = IO.DO[$"DO_{_loadPortName}_VA"].Value;
|
||||
vs0 = IO.DO[$"DO_{_loadPortName}_VS_O"].Value;
|
||||
vs1 = IO.DO[$"DO_{_loadPortName}_VS_1"].Value;
|
||||
|
||||
_lReq.CLK = lReq;
|
||||
_uReq.CLK = uReq;
|
||||
_ready.CLK = ready;
|
||||
_hoAvbl.CLK = hoAvbl;
|
||||
_es.CLK = es;
|
||||
_va.CLK = va;
|
||||
_vs0.CLK = vs0;
|
||||
_vs1.CLK = vs1;
|
||||
|
||||
//outputs
|
||||
if (IsFloor)
|
||||
{
|
||||
if (_es.T || _hoAvbl.T)
|
||||
{
|
||||
Stage = E84Stage.WaitForStation;
|
||||
IO.DI[$"DI_{_loadPortName}_CS_0"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_VALID"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_TR_REQ"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_BUSY"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_COMPT"].Value = false;
|
||||
}
|
||||
else if (_es.R || _hoAvbl.R)
|
||||
{
|
||||
Stage = E84Stage.IDLE;
|
||||
}
|
||||
|
||||
switch(Stage)
|
||||
{
|
||||
case E84Stage.IDLE:
|
||||
{
|
||||
if ((lReq || uReq) && (vs0 || vs1))
|
||||
Stage = E84Stage.TD0;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TD0:
|
||||
{
|
||||
if (va)
|
||||
Stage = E84Stage.TA1;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TA1:
|
||||
{
|
||||
IO.DI[$"DI_{_loadPortName}_TR_REQ"].Value = true;
|
||||
Stage = E84Stage.TA2;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TA2:
|
||||
{
|
||||
if (ready)
|
||||
Stage = E84Stage.TP2;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TP2:
|
||||
IO.DI[$"DI_{_loadPortName}_BUSY"].Value = true;
|
||||
Stage = E84Stage.TP3;
|
||||
break;
|
||||
case E84Stage.TP3:
|
||||
{
|
||||
if (!uReq || !lReq)
|
||||
Stage = E84Stage.TP4;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TP4:
|
||||
IO.DI[$"DI_{_loadPortName}_BUSY"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_TR_REQ"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_COMPT"].Value = true;
|
||||
Stage = E84Stage.TA3;
|
||||
break;
|
||||
case E84Stage.TA3:
|
||||
{
|
||||
if (!ready)
|
||||
Stage = E84Stage.TP5;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TP5:
|
||||
IO.DI[$"DI_{_loadPortName}_CS_0"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_VALID"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_COMPT"].Value = false;
|
||||
Stage = E84Stage.IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_es.T || _hoAvbl.T)
|
||||
{
|
||||
Stage = E84Stage.WaitForStation;
|
||||
IO.DI[$"DI_{_loadPortName}_CS_0"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_VALID"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_TR_REQ"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_BUSY"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_COMPT"].Value = false;
|
||||
}
|
||||
else if (_es.R || _hoAvbl.R)
|
||||
{
|
||||
Stage = E84Stage.IDLE;
|
||||
}
|
||||
|
||||
switch(Stage)
|
||||
{
|
||||
case E84Stage.IDLE:
|
||||
{
|
||||
IO.DI[$"DI_{_loadPortName}_CS_0"].Value = true;
|
||||
Stage = E84Stage.TD0;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TD0:
|
||||
{
|
||||
IO.DI[$"DI_{_loadPortName}_VALID"].Value = true;
|
||||
Stage = E84Stage.TA1;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TA1:
|
||||
{
|
||||
if (lReq || uReq)
|
||||
Stage = E84Stage.TP1;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TP1:
|
||||
IO.DI[$"DI_{_loadPortName}_TR_REQ"].Value = true;
|
||||
Stage = E84Stage.TA2;
|
||||
break;
|
||||
case E84Stage.TA2:
|
||||
{
|
||||
if (ready)
|
||||
Stage = E84Stage.TP2;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TP2:
|
||||
IO.DI[$"DI_{_loadPortName}_BUSY"].Value = true;
|
||||
Stage = E84Stage.TP3;
|
||||
break;
|
||||
case E84Stage.TP3:
|
||||
{
|
||||
if (!uReq || !lReq)
|
||||
Stage = E84Stage.TP4;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TP4:
|
||||
IO.DI[$"DI_{_loadPortName}_BUSY"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_TR_REQ"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_COMPT"].Value = true;
|
||||
Stage = E84Stage.TA3;
|
||||
break;
|
||||
case E84Stage.TA3:
|
||||
{
|
||||
if (!ready)
|
||||
Stage = E84Stage.TP5;
|
||||
break;
|
||||
}
|
||||
case E84Stage.TP5:
|
||||
IO.DI[$"DI_{_loadPortName}_CS_0"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_VALID"].Value = false;
|
||||
IO.DI[$"DI_{_loadPortName}_COMPT"].Value = false;
|
||||
Stage = E84Stage.IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Media.Converters;
|
||||
using Aitex.Core.RT.IOCore;
|
||||
using MECF.Framework.Common.IOCore;
|
||||
using MECF.Framework.RT.Core.IoProviders;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
public class SimulatorIO : MCProtocolPlcSimulator
|
||||
{
|
||||
|
||||
private readonly bool _isInit = false;
|
||||
|
||||
private Random _rd = new Random();
|
||||
private const int BufferSize = 640;
|
||||
public ObservableCollection<NotifiableIoItem> DiItemList { get; private set; }
|
||||
public ObservableCollection<NotifiableIoItem> DoItemList { get; private set; }
|
||||
public ObservableCollection<NotifiableIoItem> AiItemList { get; private set; }
|
||||
public ObservableCollection<NotifiableIoItem> AoItemList { get; private set; }
|
||||
|
||||
private string _source;
|
||||
|
||||
public SimulatorIO(int port, string source, string ioMapPathFile)
|
||||
: base("127.0.0.1", port)
|
||||
{
|
||||
_source = source;
|
||||
|
||||
// DI Buffer1
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize], Type = IoType.DI, Offset = 0, Size = BufferSize,
|
||||
BoolValue = new bool[BufferSize]
|
||||
});
|
||||
|
||||
// DI Buffer2
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize], Type = IoType.DI, Offset = 1, Size = BufferSize,
|
||||
BoolValue = new bool[BufferSize]
|
||||
});
|
||||
|
||||
// DI Buffer3
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize],
|
||||
Type = IoType.DI,
|
||||
Offset = 2,
|
||||
Size = BufferSize,
|
||||
BoolValue = new bool[BufferSize]
|
||||
});
|
||||
|
||||
// DO Buffer1
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize], Type = IoType.DO, Offset = 0, Size = BufferSize,
|
||||
BoolValue = new bool[BufferSize]
|
||||
});
|
||||
|
||||
// DO Buffer2
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize],
|
||||
Type = IoType.DO,
|
||||
Offset = 1,
|
||||
Size = BufferSize,
|
||||
BoolValue = new bool[BufferSize]
|
||||
});
|
||||
|
||||
// DO Buffer3
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize],
|
||||
Type = IoType.DO,
|
||||
Offset = 2,
|
||||
Size = BufferSize,
|
||||
BoolValue = new bool[BufferSize]
|
||||
});
|
||||
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize], Type = IoType.AI, Offset = 0, Size = BufferSize,
|
||||
ShortValue = new ushort[BufferSize]
|
||||
});
|
||||
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize],
|
||||
Type = IoType.AI,
|
||||
Offset = 1,
|
||||
Size = BufferSize,
|
||||
ShortValue = new ushort[BufferSize]
|
||||
});
|
||||
|
||||
_buffers.Add(new PlcBuffer()
|
||||
{
|
||||
Buffer = new byte[BufferSize], Type = IoType.AO, Offset = 0, Size = BufferSize,
|
||||
ShortValue = new ushort[BufferSize]
|
||||
});
|
||||
|
||||
var lstBuffers = new List<IoBlockItem>
|
||||
{
|
||||
new IoBlockItem() { Type = IoType.DI, Index = 0, Size = BufferSize }, // DI Block1
|
||||
new IoBlockItem() { Type = IoType.DI, Index = 1, Size = BufferSize }, // DI Block2
|
||||
new IoBlockItem() { Type = IoType.DI, Index = 2, Size = BufferSize }, // DI Block3
|
||||
new IoBlockItem() { Type = IoType.DO, Index = 0, Size = BufferSize }, // DO Block1
|
||||
new IoBlockItem() { Type = IoType.DO, Index = 1, Size = BufferSize }, // DO Block2
|
||||
new IoBlockItem() { Type = IoType.DO, Index = 2, Size = BufferSize }, // DO Block3
|
||||
new IoBlockItem() { Type = IoType.AI, Index = 0, Size = BufferSize },
|
||||
new IoBlockItem() { Type = IoType.AI, Index = 1, Size = BufferSize },
|
||||
new IoBlockItem() { Type = IoType.AO, Index = 0, Size = BufferSize }
|
||||
};
|
||||
|
||||
SimulatorIoManager.Instance.CreateBuffer(source, lstBuffers);
|
||||
SimulatorIoManager.Instance.SetIoMap(source, ioMapPathFile);
|
||||
|
||||
Init();
|
||||
|
||||
_isInit = true;
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
if (DiItemList == null)
|
||||
{
|
||||
List<DIAccessor> diItems = IO.GetDiList(_source);
|
||||
if (diItems != null)
|
||||
{
|
||||
DiItemList = new ObservableCollection<NotifiableIoItem>();
|
||||
foreach (var diItem in diItems)
|
||||
{
|
||||
NotifiableIoItem item = new NotifiableIoItem()
|
||||
{
|
||||
Name = diItem.Name,
|
||||
Index = diItem.Index,
|
||||
Description = diItem.Description,
|
||||
BoolValue = diItem.Value,
|
||||
Address = diItem.Addr,
|
||||
BlockOffset = diItem.BlockOffset,
|
||||
BlockIndex = diItem.Index,
|
||||
};
|
||||
DiItemList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DoItemList == null)
|
||||
{
|
||||
List<DOAccessor> doItems = IO.GetDoList(_source);
|
||||
if (doItems != null)
|
||||
{
|
||||
DoItemList = new ObservableCollection<NotifiableIoItem>();
|
||||
foreach (var ioItem in doItems)
|
||||
{
|
||||
NotifiableIoItem item = new NotifiableIoItem()
|
||||
{
|
||||
Name = ioItem.Name,
|
||||
Index = ioItem.Index,
|
||||
Description = ioItem.Description,
|
||||
BoolValue = ioItem.Value,
|
||||
Address = ioItem.Addr,
|
||||
BlockOffset = ioItem.BlockOffset,
|
||||
BlockIndex = ioItem.Index,
|
||||
};
|
||||
DoItemList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (AiItemList == null)
|
||||
{
|
||||
List<AIAccessor> aiItems = IO.GetAiList(_source);
|
||||
if (aiItems != null)
|
||||
{
|
||||
AiItemList = new ObservableCollection<NotifiableIoItem>();
|
||||
foreach (var ioItem in aiItems)
|
||||
{
|
||||
NotifiableIoItem item = new NotifiableIoItem()
|
||||
{
|
||||
Name = ioItem.Name,
|
||||
Index = ioItem.Index,
|
||||
Description = ioItem.Description,
|
||||
ShortValue = (short)ioItem.Value,
|
||||
Address = ioItem.Addr,
|
||||
BlockOffset = ioItem.BlockOffset,
|
||||
BlockIndex = ioItem.Index,
|
||||
};
|
||||
AiItemList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (AoItemList == null)
|
||||
{
|
||||
List<AOAccessor> aoItems = IO.GetAoList(_source);
|
||||
if (aoItems != null)
|
||||
{
|
||||
AoItemList = new ObservableCollection<NotifiableIoItem>();
|
||||
foreach (var ioItem in aoItems)
|
||||
{
|
||||
NotifiableIoItem item = new NotifiableIoItem()
|
||||
{
|
||||
Name = ioItem.Name,
|
||||
Index = ioItem.Index,
|
||||
Description = ioItem.Description,
|
||||
ShortValue = (short)ioItem.Value,
|
||||
Address = ioItem.Addr,
|
||||
BlockOffset = ioItem.BlockOffset,
|
||||
BlockIndex = ioItem.Index,
|
||||
};
|
||||
AoItemList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnTimer()
|
||||
{
|
||||
if (!_isInit) return true;
|
||||
|
||||
if (DiItemList != null)
|
||||
{
|
||||
foreach (var notifiableIoItem in DiItemList)
|
||||
{
|
||||
if (notifiableIoItem.HoldValue)
|
||||
{
|
||||
IO.DI[notifiableIoItem.Name].Value = notifiableIoItem.BoolValue;
|
||||
}
|
||||
|
||||
notifiableIoItem.BoolValue = IO.DI[notifiableIoItem.Name].Value;
|
||||
notifiableIoItem.InvokePropertyChanged("BoolValue");
|
||||
}
|
||||
}
|
||||
|
||||
if (DoItemList != null)
|
||||
{
|
||||
foreach (var notifiableIoItem in DoItemList)
|
||||
{
|
||||
if (notifiableIoItem.HoldValue)
|
||||
{
|
||||
var _plcBuff = _buffers.FirstOrDefault(x => x.Type == IoType.DO);
|
||||
if (_plcBuff != null)
|
||||
_plcBuff.BoolValue[notifiableIoItem.Index] = notifiableIoItem.BoolValue;
|
||||
|
||||
IO.DO[notifiableIoItem.Name].Value = notifiableIoItem.BoolValue;
|
||||
}
|
||||
else
|
||||
notifiableIoItem.BoolValue = IO.DO[notifiableIoItem.Name].Value;
|
||||
|
||||
notifiableIoItem.InvokePropertyChanged("BoolValue");
|
||||
}
|
||||
}
|
||||
|
||||
if (AiItemList != null)
|
||||
{
|
||||
foreach (var notifiableIoItem in AiItemList)
|
||||
{
|
||||
if (notifiableIoItem.HoldValue)
|
||||
{
|
||||
IO.AI[notifiableIoItem.Name].Value = notifiableIoItem.ShortValue;
|
||||
}
|
||||
|
||||
notifiableIoItem.ShortValue = (short)IO.AI[notifiableIoItem.Name].Value;
|
||||
notifiableIoItem.InvokePropertyChanged("ShortValue");
|
||||
}
|
||||
}
|
||||
|
||||
if (AoItemList != null)
|
||||
{
|
||||
foreach (var notifiableIoItem in AoItemList)
|
||||
{
|
||||
if (notifiableIoItem.HoldValue)
|
||||
IO.AO[notifiableIoItem.Name].Value = notifiableIoItem.ShortValue;
|
||||
else
|
||||
notifiableIoItem.ShortValue = (short)IO.AO[notifiableIoItem.Name].Value;
|
||||
notifiableIoItem.InvokePropertyChanged("ShortValue");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var plcBuffer in _buffers)
|
||||
{
|
||||
//IO修改 ---> PLC
|
||||
if (plcBuffer.Type == IoType.DI)
|
||||
{
|
||||
var ioBuffers = SimulatorIoManager.Instance.GetDiBuffer(_source);
|
||||
if (ioBuffers != null)
|
||||
{
|
||||
foreach (var ioBuffer in ioBuffers)
|
||||
{
|
||||
if (plcBuffer.Offset == ioBuffer.Key)
|
||||
{
|
||||
plcBuffer.BoolValue = ioBuffer.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PLC --> IO
|
||||
if (plcBuffer.Type == IoType.DO)
|
||||
{
|
||||
var ioBuffers = SimulatorIoManager.Instance.GetDoBuffer(_source);
|
||||
if (ioBuffers != null)
|
||||
{
|
||||
foreach (var buffer in ioBuffers)
|
||||
{
|
||||
if (plcBuffer.Offset == buffer.Key)
|
||||
{
|
||||
SimulatorIoManager.Instance.SetDoBuffer(_source, plcBuffer.Offset, plcBuffer.BoolValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//IO修改 ---> PLC
|
||||
if (plcBuffer.Type == IoType.AI)
|
||||
{
|
||||
var ioBuffers = SimulatorIoManager.Instance.GetAiBuffer(_source);
|
||||
if (ioBuffers != null)
|
||||
{
|
||||
foreach (var buffer in ioBuffers)
|
||||
{
|
||||
if (plcBuffer.Offset == buffer.Key)
|
||||
{
|
||||
plcBuffer.ShortValue = Array.ConvertAll(buffer.Value, Convert.ToUInt16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PLC --> IO
|
||||
if (plcBuffer.Type == IoType.AO)
|
||||
{
|
||||
var ioBuffers = SimulatorIoManager.Instance.GetAoBuffer(_source);
|
||||
if (ioBuffers != null)
|
||||
{
|
||||
foreach (var buffer in ioBuffers)
|
||||
{
|
||||
if (plcBuffer.Offset == buffer.Key)
|
||||
{
|
||||
SimulatorIoManager.Instance.SetAoBuffer(_source, plcBuffer.Offset,
|
||||
Array.ConvertAll(plcBuffer.ShortValue, x => (float)x));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.IoProviders.SimulatorIO1View"
|
||||
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:control="clr-namespace:MECF.Framework.UI.Core.Control;assembly=MECF.Framework.UI.Core"
|
||||
mc:Ignorable="d"
|
||||
Height="970" Width="1280">
|
||||
<Grid>
|
||||
<control:SimulatorDiItemEditor></control:SimulatorDiItemEditor>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Aitex.Common.Util;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
/// <summary>
|
||||
/// IoView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SimulatorIO1View : UserControl
|
||||
{
|
||||
public SimulatorIO1View()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new IOViewModel(6731, "System.io1", PathManager.GetCfgDir() + "_ioDefine1.xml");
|
||||
|
||||
this.IsVisibleChanged += IOView_IsVisibleChanged;
|
||||
}
|
||||
|
||||
private void IOView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (this.DataContext == null)
|
||||
{
|
||||
}
|
||||
(DataContext as TimerViewModelBase).EnableTimer(IsVisible);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.IoProviders.SimulatorIO2View"
|
||||
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:control="clr-namespace:MECF.Framework.UI.Core.Control;assembly=MECF.Framework.UI.Core"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<control:SimulatorDiItemEditor></control:SimulatorDiItemEditor>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Aitex.Common.Util;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
/// <summary>
|
||||
/// IoView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SimulatorIO2View : UserControl
|
||||
{
|
||||
public SimulatorIO2View()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new IOViewModel(6732, "System.io2", PathManager.GetCfgDir() + "_ioDefine2.xml");
|
||||
|
||||
this.IsVisibleChanged += IOView_IsVisibleChanged;
|
||||
}
|
||||
|
||||
private void IOView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (this.DataContext == null)
|
||||
{
|
||||
}
|
||||
(DataContext as TimerViewModelBase).EnableTimer(IsVisible);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.IoProviders.SimulatorIO3View"
|
||||
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:control="clr-namespace:MECF.Framework.UI.Core.Control;assembly=MECF.Framework.UI.Core"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<control:SimulatorDoItemEditor></control:SimulatorDoItemEditor>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Aitex.Common.Util;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
/// <summary>
|
||||
/// IoView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SimulatorIO3View : UserControl
|
||||
{
|
||||
public SimulatorIO3View()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new IOViewModel(6733, "System.io3", PathManager.GetCfgDir() + "_ioDefine3.xml");
|
||||
|
||||
this.IsVisibleChanged += IOView_IsVisibleChanged;
|
||||
}
|
||||
|
||||
private void IOView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (this.DataContext == null)
|
||||
{
|
||||
}
|
||||
(DataContext as TimerViewModelBase).EnableTimer(IsVisible);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.IoProviders.SimulatorIO4View"
|
||||
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:control="clr-namespace:MECF.Framework.UI.Core.Control;assembly=MECF.Framework.UI.Core"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<control:SimulatorAiItemEditor></control:SimulatorAiItemEditor>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Aitex.Common.Util;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.IoProviders
|
||||
{
|
||||
/// <summary>
|
||||
/// IoView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SimulatorIO4View : UserControl
|
||||
{
|
||||
public SimulatorIO4View()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new IOViewModel(6734, "System.io4", PathManager.GetCfgDir() + "_ioDefine4.xml");
|
||||
|
||||
this.IsVisibleChanged += IOView_IsVisibleChanged;
|
||||
}
|
||||
|
||||
private void IOView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (this.DataContext == null)
|
||||
{
|
||||
}
|
||||
(DataContext as TimerViewModelBase).EnableTimer(IsVisible);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user