资源简介
用C#写的西门子S7-200 PLC 的PPI通讯测试程序,可读写I,Q,M,VB等,希望对学习PPI通讯的同学有帮助。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace testPPI
{
class ConvertDataToByte
{
///
/// 写一个Byte数组
///
/// 站号
/// 地址
/// 值
///
public static byte[] WriteVB(int stationNO int address int value)
{
byte[] data = new byte[38];
//开始标记符
data[0] = 0x68;
data[1] = 0x20;
data[2] = 0x20;
data[3] = 0x68;
//站号
data[4] = (byte)stationNO;
data[5] = 0x00;
//功能码,写入
data[6] = 0x7C;
//
data[7] = 0x32;
data[8] = 0x01;
data[9] = 0x00;
data[10] = 0x00;
data[11] = 0x00;
data[12] = 0x00;
data[13] = 0x00;
data[14] = 0x0E;
data[15] = 0x00;
data[16] = 0x05;
data[17] = 0x05;
data[18] = 0x01;
data[19] = 0x12;
data[20] = 0x0A;
data[21] = 0x10;
//长度
//01:1 Bit
//02:1 Byte
//04:1 Word
//06:Double Word
data[22] = 0x02;
data[23] = 0x00;
//个数
data[24] = 0x01;
data[25] = 0x00;
//存储器类型,01:V存储器 00:其它
data[26] = 0x01;
//存储器类型
//04:S 05:SM 06:AI 07:AQ 1E: C
//81:I 82:Q 83:M 84:V 1F: T
data[27] = 0x84;
//地址,偏移量
data[28] = 0x00;
data[29] = Convert.ToByte(address * 8 / 256);
data[30] = Convert.ToByte(address * 8 % 256);
data[31] = 0x00;
//如果写入的是位数据这一字节为03,其它则为04
data[32] = 0x04;
data[33] = 0x00;
//位数
//01: 1 Bit 08: 1 Byte 10H: 1 Word 20H: 1 Double Word
data[34] = 0x08;
//值
data[35] = (byte)value;
//效验和
int j = 0;
for (int i = 4; i <= 35; i++)
j = j + data[i];
data[36] = Convert.ToByte(j % 256);
data[37] = 0x16;
return data;
}
///
/// 写一个Byte数组
///
/// 站号
/// 地址
/// 值
///
public static byte[] WriteQ(int stationNO double address int value)
{
byte[] data = new byte[38];
//开始标记符
data[0] = 0x68;
data[1] = 0x20;
data[2] = 0x20;
data[3] = 0x68;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 18944 2012-12-04 12:42 testPPI\testPPI\bin\Debug\testPPI.exe
文件 42496 2012-12-04 12:42 testPPI\testPPI\bin\Debug\testPPI.pdb
文件 14328 2012-12-04 12:43 testPPI\testPPI\bin\Debug\testPPI.vshost.exe
文件 490 2007-07-21 01:33 testPPI\testPPI\bin\Debug\testPPI.vshost.exe.manifest
文件 13555 2012-12-03 00:29 testPPI\testPPI\ConvertDataToByte.cs
文件 8766 2012-12-04 12:42 testPPI\testPPI\Form1.cs
文件 16902 2012-12-04 12:42 testPPI\testPPI\Form1.Designer.cs
文件 6013 2012-12-04 12:42 testPPI\testPPI\Form1.resx
文件 804 2012-12-04 12:43 testPPI\testPPI\obj\Debug\testPPI.csproj.FileListAbsolute.txt
文件 847 2012-12-04 12:42 testPPI\testPPI\obj\Debug\testPPI.csproj.GenerateResource.Cache
文件 18944 2012-12-04 12:42 testPPI\testPPI\obj\Debug\testPPI.exe
文件 180 2012-12-04 12:42 testPPI\testPPI\obj\Debug\testPPI.Form1.resources
文件 42496 2012-12-04 12:42 testPPI\testPPI\obj\Debug\testPPI.pdb
文件 180 2012-11-29 13:33 testPPI\testPPI\obj\Debug\testPPI.Properties.Resources.resources
文件 488 2012-11-27 22:38 testPPI\testPPI\Program.cs
文件 1346 2012-11-27 22:38 testPPI\testPPI\Properties\AssemblyInfo.cs
文件 2864 2012-11-27 22:38 testPPI\testPPI\Properties\Resources.Designer.cs
文件 5612 2012-11-27 22:38 testPPI\testPPI\Properties\Resources.resx
文件 1092 2012-11-27 22:38 testPPI\testPPI\Properties\Settings.Designer.cs
文件 249 2012-11-27 22:38 testPPI\testPPI\Properties\Settings.settings
文件 5393 2012-11-29 13:33 testPPI\testPPI\testPPI.csproj
文件 533 2012-11-29 13:33 testPPI\testPPI\testPPI.csproj.user
文件 911 2012-11-27 22:38 testPPI\testPPI.sln
..A..H. 18432 2012-12-04 12:43 testPPI\testPPI.suo
目录 0 2012-11-28 23:39 testPPI\testPPI\obj\Debug\Refactor
目录 0 2012-11-27 22:38 testPPI\testPPI\obj\Debug\TempPE
目录 0 2012-12-02 15:19 testPPI\testPPI\bin\Debug
目录 0 2012-12-04 12:42 testPPI\testPPI\obj\Debug
目录 0 2012-11-29 12:51 testPPI\testPPI\bin
目录 0 2012-11-27 22:38 testPPI\testPPI\obj
............此处省略6个文件信息
- 上一篇:C#自动出题判分小程序
- 下一篇:Asp.net动态生成Word文档并填充数据
相关资源
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
评论
共有 条评论