基于Winform开发S7.net协议 与Smart-200PLC通讯

1:软件编写都有架构 分为UI层 -> CoreLogicManager(逻辑管理层)Modes(实体层)

 具体使用根据大家喜好 我的函数方法如下:

步骤一:在C#工具栏 Nuget包管理器内 下载S7.net 通讯协议库

步骤二:
              S7.Net.Plc siemensS7 = new Plc(CpuType.S7200Smart, 192.168.1.177, 0, 0);//输入IP地址 这里CpuTpye是枚举类型可以根据需要和选项框按钮绑定
              siemensS7.Open();    //连接PLC

   private void GetCurrentInform()//数据集中采集  具体解析大家自己进行组合
    {

        //获取时时数据
        byte[] result10 = siemensS7.ReadBytes(S7.Net.DataType.DataBlock, 1, 5100, 60); //读取实时1#线1~15个工位 VD5100-VD5156 15*4 =60个字节
        byte[] result20 = siemensS7.ReadBytes(S7.Net.DataType.DataBlock, 1, 5300, 60); //读取实时2#线 1~15个工位 VD5300-VD5356 15*4 =60个字节
        byte[] result30 = siemensS7.ReadBytes(S7.Net.DataType.DataBlock, 1, 5500, 60);//读取实时3#线 1~15个工位 VD5500-VD5556 15*4 =60个字节

        //获取上一小时 天 月 数据
        byte[] result11 = siemensS7.ReadBytes(S7.Net.DataType.DataBlock, 1, 5200, 60); //读取上一小时1#线1~15个工位 VD5100-VD5156 15*4 =60个字节
        byte[] result21 = siemensS7.ReadBytes(S7.Net.DataType.DataBlock, 1, 5400, 60); //读取上一日2#线 1~15个工位 VD5300-VD5356 15*4 =60个字节
        byte[] result31 = siemensS7.ReadBytes(S7.Net.DataType.DataBlock, 1, 5600, 60);//读取上一月 1~15个工位 VD5500-VD5556 15*4 =60个字节


 

}

你可能感兴趣的:(c#,开发语言)