96SEO 2026-02-19 22:30 0
这里我们进行封装读写西门子PLC的S7协议命令以及连接西门子PLC并两次握手
新建部分类文件SiemensS7ProtocolUtil.ReadWrite.cs
连接西门子PLC并发送两次握手。
两次握手成功后才真正连接到PLC
ConnectPlcAndHandshake(SiemensPlcCategory
BuildWriteByteCommand(OperateResultbyte,
生成一个读取字数据指令头的通用方法【一个字Word占用两个字节Byte】
BuildReadCommand(OperateResultbyte,
SiemensS7ProtocolUtil.ReadWrite.cs源程序如下
System.Threading.Tasks;namespace
关键方法:连接PLC并发送两次握手、生成写PLC命令生成读PLC命令///
ConnectPlcAndHandshake(SiemensPlcCategory
BuildWriteByteCommand(OperateResultlt;byte,
(3).BuildReadCommand(OperateResultlt;byte,
西门子S7协议握手【两次握手】命令固定.不同型号的PLC握手命令有少许不同private
byte[22]{0x03,0x00,0x00,0x16,0x11,0xE0,0x00,0x00,0x00,0x01,0x00,0xC0,0x01,0x0A,0xC1,0x02,0x01,0x02,0xC2,0x02,0x01,0x00};private
byte[25]{0x03,0x00,0x00,0x19,0x02,0xF0,0x80,0x32,0x01,0x00,0x00,0x04,0x00,0x00,0x08,0x00,0x00,0xF0,0x00,0x00,0x01,0x00,0x01,0x01,0xE0};private
byte[22]{0x03,0x00,0x00,0x16,0x11,0xE0,0x00,0x00,0x00,0x01,0x00,0xC1,0x02,0x10,0x00,0xC2,0x02,0x03,0x00,0xC0,0x01,0x0A};private
byte[25]{0x03,0x00,0x00,0x19,0x02,0xF0,0x80,0x32,0x01,0x00,0x00,0xCC,0xC1,0x00,0x08,0x00,0x00,0xF0,0x00,0x00,0x01,0x00,0x01,0x03,0xC0};#endregion///
连接西门子PLC并发送两次握手。
两次握手成功后才真正连接到PLC///
namesiemensPlcCategory/param///
ConnectPlcAndHandshake(SiemensPlcCategory
SiemensPlcCategory.S1500:plcHead1[21]
SiemensPlcCategory.S300:plcHead1[21]
SiemensPlcCategory.S400:plcHead1[21]
SiemensPlcCategory.S200Smart:plcHead1
plcHead2_200smart;break;default:plcHead1[18]
重新连接之前先将旧的数据进行清空CoreSocket?.Close();OperateResultSocket
SendDataAndWaitResult(result.Content,
(!read_first.IsSuccess){RecordLogEvent?.Invoke($第一次握手出错{read_first.Message});return
SendDataAndWaitResult(result.Content,
(!read_second.IsSuccess){RecordLogEvent?.Invoke($第二次握手出错{read_second.Message});return
result.Content;result.IsSuccess
true;RecordLogEvent?.Invoke($连接PLC【{endPoint}】成功并且两次握手成功);}else{result.Content?.Close();CoreSocket
连接西门子PLC并发送两次握手。
两次握手成功后才真正连接到PLC///
使用IP地址和端口【默认102】和PLC型号枚举进行连接///
namesiemensPlcCategory/param///
ConnectPlcAndHandshake(SiemensPlcCategory
ConnectPlcAndHandshake(siemensPlcCategory,
IPEndPoint(IPAddress.Parse(ipAddress),
InteractionsOperateResultbyte[]
SendDataAndWaitResult(command.Content);if
OperateResult.CreateSuccessResult(buffer);}else{return
数据块长度校验失败请检查是否开启put/get以及关闭db块优化
ReadBitFromPLC(OperateResultbyte,
BuildBitReadCommand(analysis);if
OperateResult.CreateFailedResultbyte[](command);//
SendDataAndWaitResult(command.Content);if
OperateResult.CreateSuccessResult(buffer);}else{return
OperateResultbyte[](read.ErrorCode,
数据块长度校验失败请检查是否开启put/get以及关闭db块优化);}}///
entireValue){OperateResultbyte[]
SendDataAndWaitResult(entireValue);if
(write.Content[write.Content.Length
OperateResult(write.Content[write.Content.Length
write.Content[write.Content.Length
OperateResult.CreateSuccessResult();}}///
BuildWriteByteCommand(OperateResultbyte,
偏移地址占用三个字节下面注释的三行等价于BitConverter.GetBytes(Int32)
BitConverter.GetBytes(analysis.Content2);_PLCCommand[28]
offsetAddress[2];_PLCCommand[29]
offsetAddress[1];_PLCCommand[30]
OperateResult.CreateSuccessResult(_PLCCommand);}public
BuildWriteBitCommand(OperateResultbyte,
OperateResult.CreateFailedResultbyte[](analysis);byte[]
256);buffer.CopyTo(_PLCCommand,
OperateResult.CreateSuccessResult(_PLCCommand);}///
nameplcRegisterCategory寄存器类型/param///
nameoffsetAddress偏移量偏移地址/param///
AnalysisAddress(PlcRegisterCategory
0){//地址类型起始地址DB块编号OperateResultbyte,
PlcRegisterCategory.DB:result.Content1
PlcRegisterCategory.M:result.Content1
PlcRegisterCategory.Input:result.Content1
PlcRegisterCategory.Quit:result.Content1
PlcRegisterCategory.T:result.Content1
PlcRegisterCategory.C:result.Content1
PlcRegisterCategory.V:result.Content1
生成一个读取字数据指令头的通用方法【一个字Word占用两个字节Byte】
nameaddress起始地址例如M100I0Q0DB2.100
BuildReadCommand(OperateResultbyte,
NullReferenceException(address);if
NullReferenceException(count);if
OperateResult.CreateSuccessResult(_PLCCommand);}///
nameaddress起始地址例如M100.0I0.1Q0.1DB2.100.2
BuildBitReadCommand(OperateResultbyte,
OperateResult.CreateFailedResultbyte[](analysis);byte[]
OperateResult.CreateSuccessResult(_PLCCommand);}}
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback