dev
parent
d57c958ef0
commit
f613d1c82e
|
|
@ -178,6 +178,8 @@ public class DeviceThread extends Thread {
|
||||||
} else {
|
} else {
|
||||||
scale = new XiShuiScale(which + "_scale", scaleconf.getString("ip"), scaleconf.getIntValue("port"));
|
scale = new XiShuiScale(which + "_scale", scaleconf.getString("ip"), scaleconf.getIntValue("port"));
|
||||||
}
|
}
|
||||||
|
} else if (supermarket_id == 7) {
|
||||||
|
scale = new KeLiScale(which + "_scale", scaleconf.getString("ip"), scaleconf.getIntValue("port"));
|
||||||
} else {
|
} else {
|
||||||
scale = new XiShuiScale(which + "_scale", scaleconf.getString("ip"), scaleconf.getIntValue("port"));
|
scale = new XiShuiScale(which + "_scale", scaleconf.getString("ip"), scaleconf.getIntValue("port"));
|
||||||
}
|
}
|
||||||
|
|
@ -237,6 +239,26 @@ public class DeviceThread extends Thread {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reconnScale(String scaleId){
|
||||||
|
if (!this.scaleMap.containsKey(scaleId)) {
|
||||||
|
throw new IllegalArgumentException(scaleId + " does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
AbsScale scale = this.scaleMap.get(scaleId);
|
||||||
|
|
||||||
|
if (scale == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
scale.disconnect();
|
||||||
|
Thread.sleep(500);
|
||||||
|
scale.connect();
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Double scale(String scaleId) throws IOException {
|
public Double scale(String scaleId) throws IOException {
|
||||||
if (!this.scaleMap.containsKey(scaleId)) {
|
if (!this.scaleMap.containsKey(scaleId)) {
|
||||||
throw new IllegalArgumentException(scaleId + " does not exist");
|
throw new IllegalArgumentException(scaleId + " does not exist");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,127 @@
|
||||||
|
package com.cowr.local.ssjygl.devicectrl.device;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 柯力称重显示器
|
||||||
|
*/
|
||||||
|
public class KeLiScale extends AbsScale {
|
||||||
|
private static final int DATA_LENGTH = 8;
|
||||||
|
|
||||||
|
public KeLiScale(String id, String ip, int port) {
|
||||||
|
super(id, ip, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double weigh() throws IOException {
|
||||||
|
InputStream inputStream = socket.getInputStream();
|
||||||
|
byte[] clearBuf = new byte[inputStream.available()];
|
||||||
|
inputStream.read(clearBuf);
|
||||||
|
int errCount = 0;
|
||||||
|
|
||||||
|
String weight = "0.0";
|
||||||
|
while (true) {
|
||||||
|
if (errCount >= 10) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
errCount++;
|
||||||
|
|
||||||
|
byte[] buf = new byte[DATA_LENGTH];
|
||||||
|
int read = inputStream.read(buf);
|
||||||
|
|
||||||
|
if (read != DATA_LENGTH) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
weight = new String(Arrays.copyOfRange(buf, 2, 8));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Double.parseDouble(weight) / 1000d;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double weigh15() throws IOException {
|
||||||
|
ArrayList<String> list = new ArrayList<>();
|
||||||
|
AtomicBoolean run = new AtomicBoolean(true);
|
||||||
|
|
||||||
|
InputStream inputStream = socket.getInputStream();
|
||||||
|
byte[] clearBuf = new byte[inputStream.available()];
|
||||||
|
inputStream.read(clearBuf);
|
||||||
|
int errCount = 0;
|
||||||
|
|
||||||
|
while (run.get() && list.size() < 15) {
|
||||||
|
long st = System.currentTimeMillis();
|
||||||
|
|
||||||
|
byte[] buf = new byte[DATA_LENGTH];
|
||||||
|
int read = inputStream.read(buf);
|
||||||
|
|
||||||
|
if (read != DATA_LENGTH && errCount < 10) {
|
||||||
|
errCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String weight = new String(Arrays.copyOfRange(buf, 2, 8));
|
||||||
|
|
||||||
|
if (!pattern.matcher(weight).matches() || weight.equals("000000")) {
|
||||||
|
// System.out.println("error:" + weight);
|
||||||
|
|
||||||
|
if (errCount == 100) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
errCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// System.out.println("读一次耗时:" + (System.currentTimeMillis() - st) + ", " + Double.parseDouble(flip(weight)));
|
||||||
|
list.add(weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
String max = "0";
|
||||||
|
if (list.size() > 0) {
|
||||||
|
Map<String, Long> collect = list.stream().collect(
|
||||||
|
Collectors.groupingBy(num -> num, Collectors.counting()));
|
||||||
|
max = collect.entrySet().stream().max(Comparator.comparingLong(Map.Entry::getValue)).get().getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Double.parseDouble(max) / 1000d;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
KeLiScale s = new KeLiScale("scale", "192.168.20.30", 10001);
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean connect = s.connect();
|
||||||
|
System.out.println("connect " + connect);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
long st = System.currentTimeMillis();
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
try {
|
||||||
|
st = System.currentTimeMillis();
|
||||||
|
double weigh = s.weigh15();
|
||||||
|
System.out.println("end:" + weigh + ", tm: " + (System.currentTimeMillis() - st));
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -172,7 +172,7 @@ public class LEDThread extends Device implements Runnable {
|
||||||
byte[] z = new byte[read];
|
byte[] z = new byte[read];
|
||||||
System.arraycopy(y, 0, z, 0, read);
|
System.arraycopy(y, 0, z, 0, read);
|
||||||
// System.out.println(getId() + " LED 返回数据:" + HexDump.toHex(z));
|
// System.out.println(getId() + " LED 返回数据:" + HexDump.toHex(z));
|
||||||
// socket.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (e.getMessage().contains("Socket is not connected")) {
|
if (e.getMessage().contains("Socket is not connected")) {
|
||||||
log.error("LED %s %s 连接已断开", getId(), getIp());
|
log.error("LED %s %s 连接已断开", getId(), getIp());
|
||||||
|
|
@ -185,6 +185,15 @@ public class LEDThread extends Device implements Runnable {
|
||||||
|
|
||||||
reconn();
|
reconn();
|
||||||
} finally {
|
} finally {
|
||||||
|
try{
|
||||||
|
if(socket != null){
|
||||||
|
socket.close();
|
||||||
|
socket = null;
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage(),e);
|
||||||
|
}
|
||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -337,7 +346,7 @@ public class LEDThread extends Device implements Runnable {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
LEDThread led = new LEDThread("", "192.168.20.52", 5005);
|
LEDThread led = new LEDThread("", "192.168.20.50", 5005);
|
||||||
Thread thread = new Thread(led);
|
Thread thread = new Thread(led);
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
@ -345,6 +354,8 @@ public class LEDThread extends Device implements Runnable {
|
||||||
|
|
||||||
System.out.println("LED 启动");
|
System.out.println("LED 启动");
|
||||||
|
|
||||||
|
led.setWeightInfo("鄂A7D1P1", "1.1");
|
||||||
|
|
||||||
Thread.sleep(10000000);
|
Thread.sleep(10000000);
|
||||||
|
|
||||||
led.running = false;
|
led.running = false;
|
||||||
|
|
|
||||||
|
|
@ -275,11 +275,12 @@ public class PLC extends Device {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
PLC plc = new PLC("_plc", "192.168.20.20", 502, com.cowr.local.ssjygl.devicectrl.common.DeviceThread.defaultAddressTable);
|
PLC plc = new PLC("_plc", "192.168.20.21", 502, com.cowr.local.ssjygl.devicectrl.common.DeviceThread.defaultAddressTable);
|
||||||
plc.connect();
|
plc.connect();
|
||||||
plc.isConnected();
|
plc.isConnected();
|
||||||
plc.write("rodIn1Down");
|
// plc.write("rodIn1Down");
|
||||||
// plc.write("rodOut2Up");
|
String cmd = "rodOut2Down";
|
||||||
|
plc.write(cmd);
|
||||||
|
|
||||||
// plc.write("sensorIn2Reset");
|
// plc.write("sensorIn2Reset");
|
||||||
// plc.write("sensorOut1Reset");
|
// plc.write("sensorOut1Reset");
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,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 = "20201130";
|
public static final String CLINET_VERSION = "20201207";
|
||||||
|
|
||||||
public static String getRootPath() {
|
public static String getRootPath() {
|
||||||
return PathKit.getWebRootPath()
|
return PathKit.getWebRootPath()
|
||||||
|
|
|
||||||
|
|
@ -298,6 +298,8 @@ public class TransportDeviceService {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Config.deviceThread.reconnScale(which);
|
||||||
|
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ socketserver.port=21002
|
||||||
socketio.port=12002
|
socketio.port=12002
|
||||||
|
|
||||||
#当前部署本地程序的砂站id
|
#当前部署本地程序的砂站id
|
||||||
current.supermarket_id=1
|
current.supermarket_id=7
|
||||||
#落杆后,等待上磅的时间
|
#落杆后,等待上磅的时间
|
||||||
default_scale_wait_time=8000
|
default_scale_wait_time=8000
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
# mysql
|
## mysql
|
||||||
# GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.119' IDENTIFIED BY 'Local_1' WITH GRANT OPTION;
|
## GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.119' IDENTIFIED BY 'Local_1' WITH GRANT OPTION;
|
||||||
jdbcUrl=jdbc:mysql://rm-wz9wa070076b2uge2ro.mysql.rds.aliyuncs.com:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
|
#jdbcUrl=jdbc:mysql://rm-wz9wa070076b2uge2ro.mysql.rds.aliyuncs.com:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
|
||||||
user=dev_ssjy_xsx
|
#user=dev_ssjy_xsx
|
||||||
password=Ssjy_xs_890
|
#password=Ssjy_xs_890
|
||||||
|
|
||||||
#jdbcUrl=jdbc:mysql://192.168.20.2:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
|
jdbcUrl=jdbc:mysql://192.168.20.2:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
|
||||||
#jdbcUrl=jdbc:mysql://192.168.1.177:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
|
user=root
|
||||||
#user=root
|
password=Ssjy_xsx_890
|
||||||
#password=Ssjy_xsx_890
|
|
||||||
|
|
||||||
# redis
|
# redis
|
||||||
redis.basekey=ssjcgl_xsx_dev
|
redis.basekey=ssjcgl_xsx_dev
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ socketserver.port=21002
|
||||||
socketio.port=12002
|
socketio.port=12002
|
||||||
|
|
||||||
#当前部署本地程序的砂站id
|
#当前部署本地程序的砂站id
|
||||||
current.supermarket_id=6
|
current.supermarket_id=1
|
||||||
#落杆后,等待上磅的时间
|
#落杆后,等待上磅的时间
|
||||||
default_scale_wait_time=8000
|
default_scale_wait_time=8000
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1022,7 +1022,8 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
"select * from ordercluster t \n" +
|
"select * from ordercluster t \n" +
|
||||||
" where t.customer_id = ? \n" +
|
" where t.customer_id = ? \n" +
|
||||||
" and t.cutoff_time = ? \n" +
|
" and t.cutoff_time = ? \n" +
|
||||||
" and t.state < 5 limit 1", oldobj.getCustomerId(), cutoff_time)};
|
" and t.supermarket_id = ? \n" +
|
||||||
|
" and t.state < 5 limit 1", oldobj.getCustomerId(), cutoff_time, oldobj.getSupermarketId())};
|
||||||
|
|
||||||
boolean ret = Db.tx(new IAtom() {
|
boolean ret = Db.tx(new IAtom() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -1235,7 +1236,8 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
"select * from ordercluster t \n" +
|
"select * from ordercluster t \n" +
|
||||||
" where t.customer_name = ? \n" +
|
" where t.customer_name = ? \n" +
|
||||||
" and t.cutoff_time = ? \n" +
|
" and t.cutoff_time = ? \n" +
|
||||||
" and t.state < 5 limit 1", oldobj.getCustomerName(), cutoff_time);
|
" and t.supermarket_id = ? \n" +
|
||||||
|
" and t.state < 5 limit 1", oldobj.getCustomerName(), cutoff_time, oldobj.getSupermarketId());
|
||||||
|
|
||||||
if (forwardoldobj == null) {
|
if (forwardoldobj == null) {
|
||||||
// 新建一个
|
// 新建一个
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue