1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using HslCommunication.Profinet.Siemens;
- using System;
- namespace WCS.Service.PLCAccessors
- {
- public class SiemensS7PLC : SiemensS7Net
- {
- private SiemensS7Net plc;
- public SiemensS7PLC(SiemensPLCS type) : base(type)
- {
- }
- public SiemensS7PLC(SiemensPLCS type, string ip) : base(type, ip)
- {
- plc = new SiemensS7Net(type, ip);
- }
- public SiemensS7PLC(int type, string ip) : base((SiemensPLCS)type, ip)
- {
- plc = new SiemensS7Net((SiemensPLCS)type, ip);
- }
- public byte[] ReadBytes(ushort db, ushort address, ushort length)
- {
- var addr = "DB" + db + "." + address;
- var res = plc.Read(addr, length);
- if (res.IsSuccess)
- return res.Content;
- throw new Exception("读取PLC数据失败:" + res.Message);
- }
- public void WriteBytes(ushort db, ushort address, byte[] data)
- {
- var start = db + address / 2;
- var res = plc.Write("D" + start, data);
- if (!res.IsSuccess)
- throw new Exception("写入PLC数据失败:" + res.Message);
- }
- }
- }
|