修改地磅称重等待间隔时间控制

dev
lisai17@sina.com 2020-10-17 16:43:12 +08:00
parent 5dda71bd90
commit b8cfd0453b
8 changed files with 67 additions and 52 deletions

View File

@ -8,6 +8,7 @@ import com.cowr.local.ssjygl.devicectrl.controllers.InController;
import com.cowr.local.ssjygl.devicectrl.controllers.OutController; import com.cowr.local.ssjygl.devicectrl.controllers.OutController;
import com.cowr.local.ssjygl.devicectrl.device.*; import com.cowr.local.ssjygl.devicectrl.device.*;
import com.cowr.local.ssjygl.main.CliCacheData; import com.cowr.local.ssjygl.main.CliCacheData;
import com.cowr.local.ssjygl.main.Config;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.log.Log; import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Db;
@ -61,6 +62,7 @@ public class DeviceThread extends Thread {
"plc": { "ip": "192.168.0.220", "port": 502 }, "plc": { "ip": "192.168.0.220", "port": 502 },
"scale": { "ip": "192.168.0.189", "port": 10003 }, "scale": { "ip": "192.168.0.189", "port": 10003 },
"which": "R01", "which": "R01",
"scale_wait_time":5000,
"camera": { "ip": "192.168.0.100" } "camera": { "ip": "192.168.0.100" }
}, { }, {
"led": { "ip": "192.168.0.197", "port": 5005 }, "led": { "ip": "192.168.0.197", "port": 5005 },
@ -153,6 +155,7 @@ public class DeviceThread extends Thread {
JSONObject device = flow.getJSONObject(i); JSONObject device = flow.getJSONObject(i);
String which = device.getString("which"); String which = device.getString("which");
Integer scale_wait_time = device.getInteger("scale_wait_time");
JSONObject cameraconf = device.getJSONObject("camera"); JSONObject cameraconf = device.getJSONObject("camera");
JSONObject scaleconf = device.getJSONObject("scale"); JSONObject scaleconf = device.getJSONObject("scale");
JSONObject ledconf = device.getJSONObject("led"); JSONObject ledconf = device.getJSONObject("led");
@ -191,14 +194,19 @@ public class DeviceThread extends Thread {
} }
Controller controller = null; Controller controller = null;
if (scale_wait_time == null) {
scale_wait_time = Config.configprop.getInt("default_scale_wait_time");
}
if (scale_wait_time < 1000) {
log.error("scale_wait_time 值设置错误 %s ", config);
return;
}
if (which.startsWith(Enums.CtrlFlowEnum.R.name())) { if (which.startsWith(Enums.CtrlFlowEnum.R.name())) {
InController incontroller = new InController(which, camera, scale, led, plc); controller = new InController(which, camera, scale, led, plc, scale_wait_time);
incontroller.setSupermarket_id(supermarket_id);
controller = incontroller;
} else if (which.startsWith(Enums.CtrlFlowEnum.C.name())) { } else if (which.startsWith(Enums.CtrlFlowEnum.C.name())) {
controller = new OutController(which, camera, scale, led, plc); controller = new OutController(which, camera, scale, led, plc, scale_wait_time);
} else { } else {
log.error("which 值设置错误 %s ", config); log.error("which 值设置错误 %s ", config);
return; return;

View File

@ -32,6 +32,7 @@ public abstract class Controller implements Runnable {
private AbsScale scale; // 入场称重 private AbsScale scale; // 入场称重
private LEDThread led; // 称重结果显示 private LEDThread led; // 称重结果显示
private PLC plc; // 道闸控制 private PLC plc; // 道闸控制
private int scaleWaitTime; // 落杆后,上榜等待时间
private String currentLicense; // 当前流程车牌 private String currentLicense; // 当前流程车牌
private BlockingQueue<LicenseJPGPair> licenseQueue = new LinkedBlockingQueue<>(); // 车识识别结果队列 private BlockingQueue<LicenseJPGPair> licenseQueue = new LinkedBlockingQueue<>(); // 车识识别结果队列
@ -40,12 +41,15 @@ public abstract class Controller implements Runnable {
private boolean running = true; private boolean running = true;
public Controller(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc) { public Controller(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc, int scaleWaitTime) {
log.info("%s 流程上磅等待时间 %s", which, scaleWaitTime);
this.which = which; this.which = which;
this.camera = camera; this.camera = camera;
this.scale = scale; this.scale = scale;
this.led = led; this.led = led;
this.plc = plc; this.plc = plc;
this.scaleWaitTime = scaleWaitTime;
} }
public void onLicenseResult(String license, File file, boolean head, boolean delete) { public void onLicenseResult(String license, File file, boolean head, boolean delete) {
@ -248,6 +252,14 @@ public abstract class Controller implements Runnable {
public abstract String plcSensor1(); // 读地感 1 public abstract String plcSensor1(); // 读地感 1
public int getScaleWaitTime() {
return scaleWaitTime;
}
public void setScaleWaitTime(int scaleWaitTime) {
this.scaleWaitTime = scaleWaitTime;
}
public void deviceInit() { public void deviceInit() {
// 后续加入摄像头连不上的时候,可以手动加入 // 后续加入摄像头连不上的时候,可以手动加入
// 摄像头没有连上 getLicenseQueue() 不为空,表示有手动加入车牌 // 摄像头没有连上 getLicenseQueue() 不为空,表示有手动加入车牌

View File

@ -3,6 +3,7 @@ package com.cowr.local.ssjygl.devicectrl.controllers;
import com.cowr.local.ssjygl.devicectrl.device.*; import com.cowr.local.ssjygl.devicectrl.device.*;
import com.cowr.local.ssjygl.devicectrl.utils.LicenseJPGPair; import com.cowr.local.ssjygl.devicectrl.utils.LicenseJPGPair;
import com.cowr.local.ssjygl.main.CliCacheData; import com.cowr.local.ssjygl.main.CliCacheData;
import com.cowr.local.ssjygl.main.Config;
import com.cowr.model.PostLicenseResult; import com.cowr.model.PostLicenseResult;
import com.jfinal.log.Log; import com.jfinal.log.Log;
@ -11,18 +12,8 @@ import java.io.IOException;
public class InController extends Controller implements Runnable { public class InController extends Controller implements Runnable {
private static Log log = Log.getLog(InController.class); private static Log log = Log.getLog(InController.class);
private int supermarket_id; public InController(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc, int scaleWaitTime) {
super(which, camera, scale, led, plc, scaleWaitTime);
public InController(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc) {
super(which, camera, scale, led, plc);
}
public int getSupermarket_id() {
return supermarket_id;
}
public void setSupermarket_id(int supermarket_id) {
this.supermarket_id = supermarket_id;
} }
@Override @Override
@ -41,7 +32,7 @@ public class InController extends Controller implements Runnable {
} }
public void run() { public void run() {
log.debug("开始 %s 流程 %s", getWhich(), supermarket_id); log.debug("开始 %s 流程", getWhich());
deviceInit(); deviceInit();
while (isRunning()) { while (isRunning()) {
@ -108,7 +99,7 @@ public class InController extends Controller implements Runnable {
continue; continue;
} }
log.debug("%s 【%s】开始流程 %s", getWhich(), pair.license, supermarket_id); log.debug("%s 【%s】开始流程 %s", getWhich(), pair.license);
setCurrentLicense(pair.license); // 设定当前流程中的车辆 setCurrentLicense(pair.license); // 设定当前流程中的车辆
@ -169,13 +160,7 @@ public class InController extends Controller implements Runnable {
} }
// 盐港的雷达离地磅比较远,要多等一会儿 // 盐港的雷达离地磅比较远,要多等一会儿
// TODO这里的等待时间应该改成从配置文件获取 Thread.sleep(getScaleWaitTime());
if(supermarket_id == 6){
Thread.sleep(10000);
}else{
// 获取到地感线圈状态后,等待 5 秒后开始称重
Thread.sleep(5000);
}
double weight = 0; double weight = 0;
int tryCount = 0; int tryCount = 0;

View File

@ -11,8 +11,8 @@ import java.io.IOException;
public class OutController extends Controller implements Runnable { public class OutController extends Controller implements Runnable {
private static Log log = Log.getLog(InController.class); private static Log log = Log.getLog(InController.class);
public OutController(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc) { public OutController(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc, int scaleWaitTime) {
super(which, camera, scale, led, plc); super(which, camera, scale, led, plc, scaleWaitTime);
} }
@Override @Override
@ -159,7 +159,7 @@ public class OutController extends Controller implements Runnable {
} }
// 获取到地感线圈状态后,等待 5 秒后开始称重 // 获取到地感线圈状态后,等待 5 秒后开始称重
Thread.sleep(5000); Thread.sleep(getScaleWaitTime());
double weight = 0; double weight = 0;
int tryCount = 0; int tryCount = 0;

View File

@ -252,6 +252,8 @@ public class LEDThread extends Device implements Runnable {
} catch (Exception e) { } catch (Exception e) {
if (e.getMessage().contains("connect timed out")) { if (e.getMessage().contains("connect timed out")) {
log.error("LED %s %s 连接超时", getId(), getIp()); log.error("LED %s %s 连接超时", getId(), getIp());
} else if (e.getMessage().contains("Host unreachable")) {
log.error("LED %s %s 无法连接", getId(), getIp());
} else { } else {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }

View File

@ -91,7 +91,7 @@ public class Config extends JFinalConfig {
public static DeviceThread deviceThread = new DeviceThread(); public static DeviceThread deviceThread = new DeviceThread();
public static SocketIOService socketio = null; public static SocketIOService socketio = null;
private static boolean client_run = true; private static boolean client_run = true;
public static final String CLINET_VERSION = "20201016"; public static final String CLINET_VERSION = "20201017";
public static String getRootPath() { public static String getRootPath() {
return PathKit.getWebRootPath() return PathKit.getWebRootPath()
@ -327,8 +327,8 @@ public class Config extends JFinalConfig {
CliCacheData.SUP = Supermarket.dao.findById(configprop.getInt("current.supermarket_id")); CliCacheData.SUP = Supermarket.dao.findById(configprop.getInt("current.supermarket_id"));
if (CliCacheData.SUP == null) { if (CliCacheData.SUP == null) {
System.out.println("没有获取到有效的砂站信息,检查配置是否正确"); System.out.println("没有获取到有效的砂站信息,检查配置是否正确。退出系统");
log.error("没有获取到有效的砂站信息,检查配置是否正确"); log.error("没有获取到有效的砂站信息,检查配置是否正确。退出系统");
try { try {
Thread.sleep(10000); Thread.sleep(10000);
@ -337,6 +337,10 @@ public class Config extends JFinalConfig {
} }
System.exit(0); System.exit(0);
} else {
log.info("====================================================");
log.info("============= 启动 %s %s 服务 =================", CliCacheData.SUP.getId(), CliCacheData.SUP.getName());
log.info("====================================================");
} }
StockSyncService.me.initSupermarketStock(); StockSyncService.me.initSupermarketStock();

View File

@ -16,6 +16,8 @@ socketio.port=12002
#当前部署本地程序的砂站id #当前部署本地程序的砂站id
current.supermarket_id=6 current.supermarket_id=6
#落杆后,等待上磅的时间
default_scale_wait_time=5000
#打印用到的配置信息 #打印用到的配置信息
print.vendor=浠水县长投环保有限公司 print.vendor=浠水县长投环保有限公司

View File

@ -16,6 +16,8 @@ socketio.port=12002
#当前部署本地程序的砂站id #当前部署本地程序的砂站id
current.supermarket_id=6 current.supermarket_id=6
#落杆后,等待上磅的时间
default_scale_wait_time=5000
#打印用到的配置信息 #打印用到的配置信息
print.vendor=浠水县长投环保有限公司 print.vendor=浠水县长投环保有限公司