Преглед на файлове

s7 协议开发

样式分支
pry преди 2 години
родител
ревизия
e1e0af0d72
променени са 3 файла, в които са добавени 106 реда и са изтрити 0 реда
  1. +13
    -0
      BPASmartClient.S7Net/BPASmartClient.S7Net.csproj
  2. +69
    -0
      BPASmartClient.S7Net/SiemensHelper.cs
  3. +24
    -0
      SmartClient.sln

+ 13
- 0
BPASmartClient.S7Net/BPASmartClient.S7Net.csproj Целия файл

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="S7netplus" Version="0.14.0" />
</ItemGroup>

</Project>

+ 69
- 0
BPASmartClient.S7Net/SiemensHelper.cs Целия файл

@@ -0,0 +1,69 @@
using S7.Net;

namespace BPASmartClient.S7Net
{
public class SiemensHelper
{

Plc myPlc;

public bool IsConnected => myPlc is null ? false : myPlc.IsConnected;

/// <summary>
/// 打开连接
/// </summary>
/// <param name="cpuType">PLC CPU 类型</param>
/// <param name="ip">plc ip 地址</param>
/// <param name="port">plc 端口号</param>
/// <param name="rack">PLC 机架号</param>
/// <param name="solt"> PLC 插槽号</param>
public void Connect(CpuType cpuType, string ip, int port = 102, short rack = 0, short solt = 0)
{
myPlc = new Plc(cpuType, ip, port, rack, solt);
myPlc.Open();
}

/// <summary>
/// 断开和PLC的连接
/// </summary>
public void Disconnect()
{
myPlc?.Close();
}

public object Read(string address)
{
if (!IsConnected) return default;
return myPlc?.Read(address);
}

public void Write(string address, object value)
{
myPlc?.Write(address, value);
}

public ReadT ReadStruct<ReadT>(int db, int startAddress = 0)
{
if (!IsConnected) return default;
return (ReadT)myPlc.ReadStruct(typeof(ReadT), db, startAddress);
}

public void WriteStruct(object structValue, int db, int startAddress = 0)
{
myPlc?.WriteStruct(structValue, db, startAddress);
}


public int ReadClass(object sourceClass, int db, int startAddress = 0)
{
if (!IsConnected) return -1;
return myPlc.ReadClass(sourceClass, db, startAddress);
}

public void WriteClass(object sourceClass, int db, int startAddress = 0)
{
myPlc?.WriteClass(sourceClass, db, startAddress);
}

}
}

+ 24
- 0
SmartClient.sln Целия файл

@@ -126,6 +126,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.Nfc", "BPASm
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.Argox", "BPASmartClient.Argox\BPASmartClient.Argox.csproj", "{B8D499BA-A18A-4FD6-B036-44F02B4D164B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPASmartClient.S7Net", "BPASmartClient.S7Net\BPASmartClient.S7Net.csproj", "{D1F2379E-1755-4B50-9D67-15C960C33FFA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -1200,6 +1202,26 @@ Global
{B8D499BA-A18A-4FD6-B036-44F02B4D164B}.Release|x64.Build.0 = Release|Any CPU
{B8D499BA-A18A-4FD6-B036-44F02B4D164B}.Release|x86.ActiveCfg = Release|Any CPU
{B8D499BA-A18A-4FD6-B036-44F02B4D164B}.Release|x86.Build.0 = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|ARM.Build.0 = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|ARM64.Build.0 = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|x64.ActiveCfg = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|x64.Build.0 = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|x86.ActiveCfg = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|x86.Build.0 = Debug|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|Any CPU.Build.0 = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|ARM.ActiveCfg = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|ARM.Build.0 = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|ARM64.ActiveCfg = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|ARM64.Build.0 = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|x64.ActiveCfg = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|x64.Build.0 = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|x86.ActiveCfg = Release|Any CPU
{D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1255,8 +1277,10 @@ Global
{2366AC9B-B662-4550-9486-AF848B4D2961} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F}
{BFA4E222-BBCC-4AC7-9EA4-4549AEF3174B} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
{C0060FB3-7AEA-4D14-ADCE-DB78D3665D5B} = {666CB1A9-562E-453A-A2C7-FD9D77CFDFDD}
{1612F583-D328-45C6-8BB1-5D41B8F1D216} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F}
{42D35B7C-764C-4692-AA85-9B343A0F5B7F} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
{B8D499BA-A18A-4FD6-B036-44F02B4D164B} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
{D1F2379E-1755-4B50-9D67-15C960C33FFA} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC}


Зареждане…
Отказ
Запис