| | |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.DateUtils; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | // 心跳 |
| | | heartbeat(); |
| | | Thread.sleep(400); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | OperateResult connect = siemensS7Net.ConnectServer(); |
| | | if(connect.IsSuccess){ |
| | | result = true; |
| | | OutputQueue.CRN.offer(MessageFormat.format( "【{0}】输送线plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | log.info("输送线plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } else { |
| | | OutputQueue.CRN.offer(MessageFormat.format( "【{0}】输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | log.error("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | siemensS7Net.ConnectClose(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 读取状态 |
| | | * 读取状态 ====> 整块plc |
| | | */ |
| | | private void read(){ |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 40); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 写入 |
| | | * 写入 =====> 单站点写入 |
| | | */ |
| | | private void write(StaProtocol staProtocol){ |
| | | if (null == staProtocol) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 心跳 |
| | | */ |
| | | private void heartbeat(){ |
| | | OperateResult write = siemensS7Net.Write("DB100.50", (short) 1); |
| | | if (!write.IsSuccess) { |
| | | log.error("输送线plc编号={} 心跳失败", slave.getId()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void close() { |
| | | siemensS7Net.ConnectClose(); |