package com.zy.core.network;
|
|
import HslCommunication.Profinet.Siemens.SiemensS7Net;
|
import com.zy.asrs.entity.DeviceConfig;
|
import com.zy.core.ThreadHandler;
|
import com.zy.core.model.CommandResponse;
|
import com.zy.core.model.command.StationCommand;
|
import com.zy.core.network.api.ZyStationConnectApi;
|
import com.zy.core.network.entity.ZyStationStatusEntity;
|
import java.util.List;
|
import com.zy.core.network.fake.ZyStationFakeConnect;
|
import com.zy.core.network.real.ZyStationRealConnect;
|
import lombok.extern.slf4j.Slf4j;
|
|
/**
|
* 输送站连接驱动
|
*/
|
@Slf4j
|
public class ZyStationConnectDriver implements ThreadHandler {
|
|
private boolean connected = false;
|
private DeviceConfig deviceConfig;
|
private ZyStationConnectApi zyStationConnectApi;
|
|
public ZyStationConnectDriver(DeviceConfig deviceConfig) {
|
this.deviceConfig = deviceConfig;
|
}
|
|
@Override
|
@SuppressWarnings("InfiniteLoopStatement")
|
public void run() {
|
while (true) {
|
try {
|
if (!connected) {
|
connect();
|
}
|
Thread.sleep(1000);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
@Override
|
public boolean connect() {
|
if (deviceConfig.getFake() == 0) {
|
zyStationConnectApi = new ZyStationRealConnect(deviceConfig);
|
} else {
|
zyStationConnectApi = new ZyStationFakeConnect(deviceConfig);
|
}
|
|
boolean connect = zyStationConnectApi.connect();
|
connected = connect;
|
return connect;
|
}
|
|
@Override
|
public void close() {
|
zyStationConnectApi.disconnect();
|
zyStationConnectApi = null;
|
connected = false;
|
}
|
|
public List<ZyStationStatusEntity> getStatus() {
|
if (zyStationConnectApi == null) {
|
return null;
|
}
|
return zyStationConnectApi.getStatus();
|
}
|
|
public CommandResponse sendCommand(StationCommand command) {
|
return zyStationConnectApi.sendCommand(command);
|
}
|
}
|