资源简介
C#基于.net直接访问西门子PLC的类库——S7.net,可以实现西门子200含Smart、300、1200、1500寄存器地址的直接读写操作

代码片段和文件信息
using System;
using System.Globalization;
namespace S7.Net
{
///
/// Conversion methods to convert from Siemens numeric format to C# and back
///
public static class Conversion
{
///
/// Converts a binary string to Int32 value
///
///
///
public static int BinStringToInt32(this string txt)
{
int ret = 0;
for (int i = 0; i < txt.Length; i++)
{
ret = (ret << 1) | ((txt[i] == ‘1‘) ? 1 : 0);
}
return ret;
}
///
/// Converts a binary string to a byte. Can return null.
///
///
///
public static byte? BinStringToByte(this string txt)
{
if (txt.Length == 8) return (byte)BinStringToInt32(txt);
return null;
}
///
/// Converts the value to a binary string
///
///
///
public static string ValToBinString(this object value)
{
int cnt = 0;
int cnt2 = 0;
int x = 0;
string txt = ““;
long longValue = 0;
try
{
if (value.GetType().Name.IndexOf(“[]“) < 0)
{
// ist nur ein Wert
switch (value.GetType().Name)
{
case “Byte“:
x = 7;
longValue = (long)((byte)value);
break;
case “Int16“:
x = 15;
longValue = (long)((Int16)value);
break;
case “Int32“:
x = 31;
longValue = (long)((Int32)value);
break;
case “Int64“:
x = 63;
longValue = (long)((Int64)value);
break;
default:
throw new Exception();
}
for (cnt = x; cnt >= 0; cnt += -1)
{
if (((Int64)longValue & (Int64)Math.Pow(2 cnt)) > 0)
txt += “1“;
else
txt += “0“;
}
}
else
{
// ist ein Array
switch (value.GetType().Name)
{
case “Byte[]“:
x = 7;
byte[] ByteArr = (byte[])value;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 158 2018-10-11 02:28 s7netplus-develop\.gitignore
....... 587 2018-10-11 02:28 s7netplus-develop\appveyor.yml
....... 191272 2018-10-11 02:28 s7netplus-develop\Documentation\Documentation.docx
....... 573506 2018-10-11 02:28 s7netplus-develop\Documentation\Documentation.pdf
....... 121055 2018-10-11 02:28 s7netplus-develop\Documentation\protection 2.png
....... 17466 2018-10-11 02:28 s7netplus-develop\Documentation\protection.png
....... 8392 2018-10-11 02:28 s7netplus-develop\Documentation\struct.png
....... 356 2018-10-11 02:28 s7netplus-develop\GitVersion.yml
....... 1082 2018-10-11 02:28 s7netplus-develop\License.txt
文件 70 2019-02-28 13:29 s7netplus-develop\Readme!!!.txt
....... 1706 2018-10-11 02:28 s7netplus-develop\README.md
....... 435 2018-10-11 02:28 s7netplus-develop\S7.Net\Compat\TcpClientMixins.cs
....... 9106 2018-10-11 02:28 s7netplus-develop\S7.Net\Conversion.cs
....... 5342 2018-10-11 02:28 s7netplus-develop\S7.Net\COTP.cs
....... 3775 2018-10-11 02:28 s7netplus-develop\S7.Net\Enums.cs
....... 5250 2018-10-11 02:28 s7netplus-develop\S7.Net\PLC.cs
....... 7326 2018-10-11 02:28 s7netplus-develop\S7.Net\PLCAddress.cs
....... 28297 2018-10-11 02:28 s7netplus-develop\S7.Net\PlcAsynchronous.cs
....... 1090 2018-10-11 02:28 s7netplus-develop\S7.Net\PlcException.cs
....... 2270 2018-10-11 02:28 s7netplus-develop\S7.Net\PLCExceptions.cs
....... 8325 2018-10-11 02:28 s7netplus-develop\S7.Net\PLCHelpers.cs
....... 26420 2018-10-11 02:28 s7netplus-develop\S7.Net\PlcSynchronous.cs
....... 427 2018-10-11 02:28 s7netplus-develop\S7.Net\Properties\AssemblyInfo.cs
....... 596 2018-10-11 02:28 s7netplus-develop\S7.Net\Properties\S7.Net.snk
....... 2343 2018-10-11 02:28 s7netplus-develop\S7.Net\Protocol\ConnectionRequest.cs
....... 5717 2018-10-11 02:28 s7netplus-develop\S7.Net\Protocol\S7WriteMultiple.cs
....... 3272 2018-10-11 02:28 s7netplus-develop\S7.Net\Protocol\Serialization.cs
....... 1342 2018-10-11 02:28 s7netplus-develop\S7.Net\S7.Net.csproj
....... 2482 2018-10-11 02:28 s7netplus-develop\S7.Net\TPKT.cs
....... 670 2018-10-11 02:28 s7netplus-develop\S7.Net\Types\Bit.cs
............此处省略56个文件信息
相关资源
- 从PLC循环读取到前台显示,并推送给
- C#和西门子CPU进行S7通讯
- PLC通讯170294
- c#与西门子s7-200 smart 通讯 S7TCPDLL.dll
- C# Modbus TCP通讯(S7200PLC)
- C# 台达PLC485通信
- VS开发S7-1200PLC上位机软件(案例源码
- C#与西门子1500通讯59060
-
欧姆龙PLC通讯程序源码(HOST li
nk 实 - 西门子网络RFID
- kepserver 连接 PLC代码
- 松下PLC 通讯(modbus)
- 三菱plc上载最终程序.gxw
- 三菱Q-PLC与C#串口
- C#与三菱Q系列PLC以太网通信
- TcpClient C#2010读取PLC
- C#-与西门子1200-1500-S7通讯(源码+文档
- plc通信(vb+c#+说明文档)
- C# 实现 信捷PLC通讯协议
- C# SHAP7与西门子PLC通讯及模拟
- C# 通过S7.NET方式实现与西门子PLC通信
- 基于webapi的PLC软件控制(softplc)
- 上位机语音识别控制PLC源码(附西门
- HMI-with-WPF-part-3-Communication-with-multipl
- 松下PLC与C#通讯串口调试入门教程.z
- 用C#实现PC与西门子PLC串行通讯
- C#与西门子PLC通讯测试DOME.rar
- 西门子 S7-200 PLC 通信DLL
- S7.NET-EXE.rar
- C#用S7.net
评论
共有 条评论