mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-06 16:06:34 +08:00
优化了示例工程
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
using Net461DllTest.Data;
|
||||
using Net461DllTest.Signal;
|
||||
using Serein.Library.Attributes;
|
||||
using Serein.Library.NodeFlow.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net461DllTest.Device
|
||||
{
|
||||
|
||||
|
||||
public class PlcDevice : ChannelFlowTrigger<OrderSignal>
|
||||
{
|
||||
[AutoInjection]
|
||||
public MyData MyData { get; set; }
|
||||
|
||||
public PlcDevice()
|
||||
{
|
||||
PlcId = 114514 + 10000000 * new Random().Next(1, 9);
|
||||
}
|
||||
public int PlcId { get; set; }
|
||||
|
||||
public void InitDevice(string ip, int port, string tips)
|
||||
{
|
||||
Write($"模拟设备初始化 :{Environment.NewLine}" +
|
||||
$" ip :{ip}{Environment.NewLine}" +
|
||||
$"port:{port}{Environment.NewLine}" +
|
||||
$"tips:{tips}{Environment.NewLine}");
|
||||
}
|
||||
|
||||
public void Write<T>(T value)
|
||||
{
|
||||
Console.WriteLine($"{value}");
|
||||
}
|
||||
public void Read<T>()
|
||||
{
|
||||
Console.WriteLine($"读取数据:... ");
|
||||
}
|
||||
public void Disconnect()
|
||||
{
|
||||
Console.WriteLine($"断开连接...");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
18
Net461DllTest/Device/PrakingDevice.cs
Normal file
18
Net461DllTest/Device/PrakingDevice.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Net461DllTest.LogicControl;
|
||||
using Serein.Library.Attributes;
|
||||
using Serein.Library.NodeFlow.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net461DllTest.Device
|
||||
{
|
||||
[AutoRegister]
|
||||
public class PrakingDevice : ChannelFlowTrigger<ParkingCommand>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
70
Net461DllTest/Device/SiemensPlcDevice.cs
Normal file
70
Net461DllTest/Device/SiemensPlcDevice.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using IoTClient.Clients.PLC;
|
||||
using Net461DllTest.Enums;
|
||||
using Net461DllTest.Signal;
|
||||
using Net461DllTest.Utils;
|
||||
using Serein.Library.NodeFlow.Tool;
|
||||
using System;
|
||||
|
||||
namespace Net461DllTest.Device
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 官方文档:如果没有主动Open,则会每次读写操作的时候自动打开自动和关闭连接,这样会使读写效率大大减低。所以建议手动Open和Close。
|
||||
/// </summary>
|
||||
public class SiemensPlcDevice : ChannelFlowTrigger<OrderSignal>
|
||||
{
|
||||
public SiemensClient Client { get; set; }
|
||||
|
||||
public IoTClient.Common.Enums.SiemensVersion Version { get; set; }
|
||||
public string IP { get; set; }
|
||||
public int Port { get; set; }
|
||||
public PlcState State { get; set; } = PlcState.PowerOff;
|
||||
|
||||
|
||||
public void Init(IoTClient.Common.Enums.SiemensVersion version,string ip, int port)
|
||||
{
|
||||
Client = new SiemensClient(version, ip, port);
|
||||
Version = version;
|
||||
IP = ip;
|
||||
Port = port;
|
||||
}
|
||||
|
||||
public void ResetDevice()
|
||||
{
|
||||
Client?.Close();
|
||||
Client = null;
|
||||
}
|
||||
|
||||
public void Write(PlcVarInfo plcValue, object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.WriteToPlcValue(plcValue, value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"写入出错:{this}{plcValue}。{ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public object Read(PlcVarInfo plcValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Client.ReadToPlcValue(plcValue);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"读取出错:{this}{plcValue}。{ex.Message}");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"西门子Plc[{this.Version}-{this.IP}:{this.Port}]";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user