|
|
@@ -5,6 +5,7 @@ import com.gg.reader.api.protocol.gx.EnumG;
|
|
|
import com.gg.reader.api.protocol.gx.MsgBaseInventoryEpc;
|
|
|
import com.gg.reader.api.protocol.gx.MsgBaseSetPower;
|
|
|
import com.gg.reader.api.protocol.gx.MsgBaseStop;
|
|
|
+import com.payne.reader.Reader;
|
|
|
import com.zd.netty.service.ISendService;
|
|
|
import com.zd.netty.service.IService;
|
|
|
import com.zd.system.api.domain.InventoryTag;
|
|
|
@@ -14,19 +15,23 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.Hashtable;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class DeJuRFIDService implements IService {
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private ISendService sendService;
|
|
|
- static GClient client;
|
|
|
+
|
|
|
+ private final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
@Override
|
|
|
public void start(RemoteLabHardware hardware) {
|
|
|
- client = new GClient();
|
|
|
+ GClient client = new GClient();
|
|
|
String ipAddress = hardware.getIpAddress();
|
|
|
Integer port = hardware.getPort();
|
|
|
if (client.openTcp(ipAddress+":"+port, 2000)) {
|
|
|
@@ -88,7 +93,7 @@ public class DeJuRFIDService implements IService {
|
|
|
} else {
|
|
|
System.out.println("Inventory epc error.");
|
|
|
}
|
|
|
-
|
|
|
+ clientMap.put(ipAddress,client);
|
|
|
} else {
|
|
|
System.out.println("Connect failure.");
|
|
|
}
|
|
|
@@ -96,15 +101,19 @@ public class DeJuRFIDService implements IService {
|
|
|
|
|
|
@Override
|
|
|
public void disconnect(RemoteLabHardware hardware) {
|
|
|
- MsgBaseStop msg = new MsgBaseStop();
|
|
|
- // 停止读卡,空闲态
|
|
|
- client.sendSynMsg(msg);
|
|
|
- if (0 == msg.getRtCode()) {
|
|
|
- System.out.println("Stop successful.");
|
|
|
- } else {
|
|
|
- System.out.println("Stop error.");
|
|
|
+ String ipAddress = hardware.getIpAddress();
|
|
|
+ if (clientMap.containsKey(ipAddress)){
|
|
|
+ GClient client = clientMap.get(ipAddress);
|
|
|
+ MsgBaseStop msg = new MsgBaseStop();
|
|
|
+ // 停止读卡,空闲态
|
|
|
+ client.sendSynMsg(msg);
|
|
|
+ if (0 == msg.getRtCode()) {
|
|
|
+ System.out.println("Stop successful.");
|
|
|
+ } else {
|
|
|
+ System.out.println("Stop error.");
|
|
|
+ }
|
|
|
+ System.out.println("Close the connection");
|
|
|
+ client.close();
|
|
|
}
|
|
|
- System.out.println("Close the connection");
|
|
|
- client.close();
|
|
|
}
|
|
|
}
|