This commit is contained in:
2025-03-21 08:51:20 +08:00
parent 0dedff36fd
commit 9a5d3be528
70 changed files with 4542 additions and 2207 deletions

View File

@ -12,10 +12,6 @@
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.IO.Ports" Version="9.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DH.Commons\DH.Commons.csproj" />
</ItemGroup>

View File

@ -1,82 +0,0 @@
using System.IO.Ports;
using DH.Commons.Enums;
using HslCommunication;
namespace DH.Devices.PLC
{
public class PLCBase
{
/// <summary>
/// 连接状态
/// </summary>
public bool connected = false;
public string PLCName;
/// <summary>
/// 类型
/// </summary>
public EnumPLCType PLCType=EnumPLCType.XD_网口;
/// <summary>
/// 串口号
/// </summary>
public string portName="COM1";
/// <summary>
/// 波特率
/// </summary>
public int baudRate = 9600;
/// <summary>
/// 数据位
/// </summary>
public int dataBit = 8;
/// <summary>
/// 停止位
/// </summary>
public StopBits stopBit = (StopBits)Enum.Parse(typeof(StopBits), "One");
/// <summary>
/// 奇偶效验位
/// </summary>
public Parity parity = (Parity)Enum.Parse(typeof(Parity), "None");
/// <summary>
/// IP地址
/// </summary>
public string IP = "192.168.6.6";
/// <summary>
/// 端口号
/// </summary>
public int Port = 502;
/// <summary>
/// 初始化
/// </summary>
/// <returns></returns>
public virtual bool PLCConnect() { return false; }
public virtual bool PLCDisConnect() { return false; }
public virtual ushort ReadShort(string address) { return 0; }
public virtual int ReadInt(string address) { return 0; }
public virtual float ReadFloat(string address) { return 0; }
public virtual bool ReadBool(string address) { return false; }
public virtual bool WriteShort(string address, short value, bool waitForReply = true) { return false; }
public virtual bool WriteInt(string address, int value, bool waitForReply = true) { return false; }
public virtual bool WriteDInt(string address, int value, bool waitForReply = true) { return false; }
public virtual bool WriteFloat(string address, float value, bool waitForReply = true) { return false; }
public virtual bool WriteBool(string address, bool value, bool waitForReply = true) { return false; }
}
}

View File

@ -8,6 +8,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
using DH.Commons.Base;
using DH.Commons.Enums;
using HslCommunication;
using HslCommunication.Enthernet;
@ -47,7 +48,7 @@ namespace DH.Devices.PLC
OperateResult ret = TcpNet.ConnectServer();
if (ret.IsSuccess)
{
connected = true;
Connected = true;
MonitorPieces();
TurntableOpen(12000,true);
@ -382,13 +383,13 @@ namespace DH.Devices.PLC
public override bool PLCDisConnect()
{
if (connected)
if (Connected)
{
TurntableStop();
var res = TcpNet.ConnectClose();
if (res.IsSuccess)
{
connected = false;
Connected = false;
return true;
}
return false;
@ -442,7 +443,7 @@ namespace DH.Devices.PLC
TimeSpan timeSpan = endTime - startTime;
Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
//while (CurrentState != DeviceState.DSClose && CurrentState != DeviceState.DSExcept && CurrentState != DeviceState.DSUninit)
while (connected)
while (Connected)
{
Stopwatch sw = new Stopwatch();
uint tmpPieceNumber = 0;