资源简介
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#通讯串口调试入门教程.z
- 用C#实现PC与西门子PLC串行通讯
- C#与西门子PLC通讯测试DOME.rar
- 西门子 S7-200 PLC 通信DLL
- S7.NET-EXE.rar
- C#用S7.net
- 三菱PLC与C#等通讯
- C#与各种PLC通讯测试
- VS C#语言编写的与plc通讯的OPC代码完整
- 松下PLC与C#上位机通讯库含程序.rar
- 欧姆龙PLC网络通信程序
- C#读取ABPLC驱动程序和ABPLC模拟器
- C#基于OPC服务器读写欧姆龙PLC数据
- DELTA DVP Series PLC.zip
- PLC通讯实现-C#访问三菱PLCCPU-R04-MxCom
- C#实现各大厂商PLC通讯
- 0237 C#通过OPC连接PLC读写数据源码.ra
- 基于C#的台达PLCModus串口通信控件及源
- 上位机C#以太网连接三菱PLC
- 上位机(C#)MX Component以太网连接三菱
- VB通过dll建立S7-200Smart通讯。亲测简易
- PLC通讯实现-C#访问OPCUA实现读写PLC
- C# 通过 OPC连接plc,读取数据。
- OPC&Snap7;.zip
- C#写的组态软件--简单版
- C#使用ModbusTcp协议与西门子1200PLC通讯
- HslCommunication C#的PLC通信类库源代码
- 基恩士PLC通讯.rar
- 上位机与PLC通讯dll.zip
- C#编成Modbus TCP连接PLC寄存器读取、写
评论
共有 条评论