MesClient.java 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.github.s7connector.api.S7Connector;
  5. import com.github.s7connector.api.S7Serializer;
  6. import com.github.s7connector.api.factory.S7ConnectorFactory;
  7. import com.github.s7connector.api.factory.S7SerializerFactory;
  8. import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
  9. import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
  10. import com.mes.component.MesRadio;
  11. import com.mes.component.MesWebView;
  12. import com.mes.netty.NettyClient;
  13. import com.mes.util.DateLocalUtils;
  14. import com.mes.util.HttpUtils;
  15. import com.mes.util.JdbcUtils;
  16. import javafx.embed.swing.JFXPanel;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import javax.swing.*;
  20. import javax.swing.border.EmptyBorder;
  21. import javax.swing.event.ChangeEvent;
  22. import javax.swing.event.ChangeListener;
  23. import java.awt.*;
  24. import java.awt.event.ActionEvent;
  25. import java.awt.event.ActionListener;
  26. import java.awt.event.MouseAdapter;
  27. import java.awt.event.MouseEvent;
  28. import java.io.BufferedReader;
  29. import java.io.IOException;
  30. import java.io.InputStream;
  31. import java.io.InputStreamReader;
  32. import java.sql.ResultSet;
  33. import java.sql.SQLException;
  34. import java.sql.Statement;
  35. import java.time.LocalDateTime;
  36. import java.util.List;
  37. import java.util.Map;
  38. import java.util.ArrayList;
  39. import java.util.Properties;
  40. import java.util.Timer;
  41. import java.util.TimerTask;
  42. import java.util.concurrent.ExecutorService;
  43. import java.util.concurrent.Executors;
  44. public class MesClient extends JFrame {
  45. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  46. public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
  47. public static String mes_gw = ""; // 工位号
  48. public static String mes_gw_des = "液冷板FSW"; // 工位名称
  49. public static String mes_server_ip = ""; // 服务器IP地址
  50. public static int mes_tcp_port = 3000; // TCP服务端口
  51. public static int mes_heart_beat_cycle = 10; // 心跳周期
  52. public static int mes_heart_icon_cycle = 1;
  53. public static String mes_line_sn = ""; // 产线编号
  54. //TCP连接
  55. public static NettyClient nettyClient;
  56. //TCP连接状态
  57. public static boolean tcp_connect_flag = false;
  58. //TCP连接请求
  59. public static boolean connect_request_flag = false;
  60. //session
  61. public static String sessionid = "";
  62. public static JPanel contentPane;
  63. public static MesClient mesClientFrame;
  64. public static JTabbedPane tabbedPane;
  65. public static JScrollPane indexScrollPaneA;
  66. public static JScrollPane searchScrollPane;
  67. public static JScrollPane searchScrollPaneDj;
  68. public static Boolean check_quality_result = false;
  69. public static Integer work_status = 0;
  70. public static JButton heart_beat_menu;
  71. public static JButton status_menu;
  72. public static JButton user_menu;
  73. public static int scan_type = 0;
  74. public static JButton finish_ok_bt;
  75. public static JButton finish_ng_bt;
  76. public static JTextField product_sn;
  77. public static JButton f_scan_data_bt_1;
  78. public static String user20 = "";
  79. public static JFrame welcomeWin;
  80. public static JPanel indexPanelB;
  81. public static MesWebView jfxPanel = null;
  82. public static JPanel indexPanelC;
  83. public static MesWebView jfxPanel2 = null;
  84. public static MesRadio mesRadioHj;
  85. public static JTable table;
  86. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  87. public static Object[][] rowData = null;
  88. public static JLabel fxlabel;
  89. public static JLabel fxlabel2;
  90. public static Integer fxlabel2Flag = 0;
  91. // public static String plcUrl = "192.168.88.89"; // 180AF
  92. public static String plcUrl = "192.168.88.99"; // 180BE 280AB
  93. public static S7PLC s7PLC = new S7PLC(EPlcType.SINUMERIK_828D, plcUrl);
  94. public static S7Connector s7Connector = null;
  95. public static Integer tjFlag = 0; // 0=未扫码 1=已扫码,设备未运行 2=设备运行中 3=设备运行结束,结果未提交到MES
  96. public static Integer tjStatus = 0; // 0=重置 1=提交失败
  97. public static Integer tjTime = 0; // 0=未超过限制时间 1=超过限制时间
  98. public static Integer yxTime = 0;
  99. public static String tjResult = "OK"; // 加工结果,只要不急停就算加工完成
  100. public static String tjFlagText2 = "设备运行中";
  101. public static String tjFlagText3 = "设备运行结束,提交结果中";
  102. public static String tjFlagText4 = "结果已上传MES,请扫下一件";
  103. public static String tjFlagText5 = "已扫码,等待设备运行";
  104. public static String tjFlagTextErr = "结果上传MES失败,请重试";
  105. //MES屏蔽开关
  106. public static boolean mes_flag = false; //是否屏蔽MES true=屏蔽MES false=不屏蔽MES
  107. public static JButton mesbtn;
  108. public static String programNo = "";
  109. // 设备实时参数
  110. public static double actSpindleSpeed = 0; // 主轴转速
  111. public static double feedRate = 0; // 进给速度
  112. // 数据缓存
  113. public static List<String> deviceParams = new ArrayList<>();
  114. // 显示组件
  115. public static JLabel spindleSpeedLabel;
  116. public static JLabel feedRateLabel;
  117. public static JLabel torqueLabel;
  118. public static Integer curPoint = 0;
  119. public static List<String> curPointX = new ArrayList<>();
  120. public static List<String> curPointY = new ArrayList<>();
  121. public static void main(String[] args) {
  122. if (LockUtil.getInstance().isAppActive() == true){
  123. // JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
  124. return;
  125. }
  126. EventQueue.invokeLater(new Runnable() {
  127. @Override
  128. public void run() {
  129. try{
  130. //读文件配置
  131. readProperty();
  132. s7PLC.setConnectTimeout(500);
  133. s7PLC.setReceiveTimeout(500);
  134. // 显示界面
  135. mesClientFrame = new MesClient();
  136. mesClientFrame.setVisible(false);
  137. JdbcUtils.getConn();
  138. welcomeWin = new LoginFarme();
  139. welcomeWin.setVisible(true);
  140. getMaterailData();
  141. startUpDeviceParamsTimer();
  142. monitorDevice();
  143. fswCheckPoint();
  144. }catch (Exception e){
  145. e.printStackTrace();
  146. }
  147. }
  148. });
  149. }
  150. //读配置文件
  151. private static void readProperty() throws IOException{
  152. String enconding = "UTF-8";
  153. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  154. Properties pro = new Properties();
  155. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  156. pro.load(br);
  157. mes_gw = pro.getProperty("mes.gw");
  158. mes_server_ip = pro.getProperty("mes.server_ip");
  159. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  160. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  161. mes_line_sn = pro.getProperty("mes.line_sn");
  162. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  163. log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  164. }
  165. // 初始化TCP
  166. public static void initTcpConnection() {
  167. try {
  168. if(nettyClient==null) {
  169. //初始化TCP连接
  170. nettyClient = new NettyClient();
  171. //TCP连接状态
  172. tcp_connect_flag = false;
  173. //设置TCP请求状态
  174. connect_request_flag = true;
  175. DataUtil.synrTcp(nettyClient,mes_gw);
  176. }
  177. } catch (Exception e) {
  178. // TODO Auto-generated catch block
  179. e.printStackTrace();
  180. }
  181. }
  182. //启动心跳包程序
  183. public static java.util.Timer heartBeatTimer;
  184. public static java.util.Timer heartBeatIconTimer;
  185. public static boolean iconREDFlag = true;
  186. public static void startHeartBeatTimer() {
  187. if(heartBeatTimer!=null) {
  188. heartBeatTimer.cancel();
  189. }
  190. heartBeatTimer = new java.util.Timer();
  191. heartBeatTimer.schedule(new TimerTask() {
  192. public void run() {
  193. if(nettyClient!=null&&tcp_connect_flag) {
  194. //System.out.println("发送心跳报文");
  195. DataUtil.heartBeat(nettyClient,mes_gw);
  196. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  197. }
  198. }
  199. }, 100,mes_heart_beat_cycle*1000);
  200. //心跳显示图标
  201. if(heartBeatIconTimer!=null) {
  202. heartBeatIconTimer.cancel();
  203. }
  204. heartBeatIconTimer = new Timer();
  205. heartBeatIconTimer.schedule(new TimerTask() {
  206. public void run() {
  207. if(tcp_connect_flag) {
  208. if(iconREDFlag) {
  209. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  210. iconREDFlag = false;
  211. }else {
  212. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  213. iconREDFlag = true;
  214. }
  215. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  216. heart_beat_menu.repaint();
  217. }else {
  218. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  219. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  220. heart_beat_menu.repaint();
  221. //若未连接则尝试连接
  222. if(nettyClient!=null&&!tcp_connect_flag){
  223. System.out.println("TCP已断开");
  224. //TCP重新同步连接
  225. if(!connect_request_flag) {
  226. //System.out.println("TCP重新同步连接");
  227. //设置TCP请求状态,只重新同步连接一次
  228. connect_request_flag = true;
  229. DataUtil.synrTcp(nettyClient,mes_gw);
  230. }
  231. }
  232. }
  233. }
  234. }, 100,mes_heart_icon_cycle*1000);
  235. }
  236. // 设备参数读取定时器
  237. public static java.util.Timer deviceParamTimer;
  238. public static void startDeviceParamTimer() {
  239. if(deviceParamTimer != null) {
  240. deviceParamTimer.cancel();
  241. }
  242. deviceParamTimer = new java.util.Timer();
  243. deviceParamTimer.schedule(new TimerTask() {
  244. public void run() {
  245. try {
  246. if (work_status == 1){
  247. // 读取转速和进给
  248. actSpindleSpeed = S7Util.readActSpindleSpeed(s7PLC);
  249. feedRate = S7Util.readFeedRate(s7PLC);
  250. final double torque = S7Util.readTorque(s7PLC);
  251. // 更新UI
  252. final double spindle = actSpindleSpeed;
  253. final double feed = feedRate;
  254. SwingUtilities.invokeLater(() -> {
  255. spindleSpeedLabel.setText(String.format("转速: %.1f rpm", spindle));
  256. feedRateLabel.setText(String.format("进给: %.1f mm/min", feed));
  257. torqueLabel.setText(String.format("扭矩: %.1f ", torque));
  258. });
  259. // 存储数据
  260. final String currentSn = product_sn.getText();
  261. if(currentSn != null && !currentSn.isEmpty()) {
  262. String record_time = DateLocalUtils.getCurrentTime();
  263. deviceParams.add(actSpindleSpeed + "|" + feedRate + "|" + torque + "|" + record_time);
  264. if(deviceParams.size() == 60) {
  265. try {
  266. JdbcUtils.insertDeviceParamData(mes_gw, mes_line_sn, currentSn, JSON.toJSONString(deviceParams));
  267. log.info("设备参数数据已存储: " + currentSn);
  268. deviceParams = new ArrayList<>();
  269. }catch (Exception e) {
  270. log.info("存储设备参数异常: " + e.getMessage());
  271. }
  272. }
  273. }
  274. }
  275. } catch (Exception e) {
  276. log.info("读取设备参数异常: " + e.getMessage());
  277. }
  278. }
  279. }, 100, 500); // 首次延迟100ms,之后每500ms执行
  280. }
  281. // 设备参数上传定时器
  282. public static java.util.Timer upDeviceParamsTimer;
  283. public static void startUpDeviceParamsTimer() {
  284. if(upDeviceParamsTimer != null) {
  285. upDeviceParamsTimer.cancel();
  286. }
  287. upDeviceParamsTimer = new java.util.Timer();
  288. upDeviceParamsTimer.schedule(new TimerTask() {
  289. public void run() {
  290. try{
  291. List<Map<String, Object>> prods = JdbcUtils.getDeviceParams();
  292. System.out.println("prods:"+ JSON.toJSONString(prods));
  293. if(prods.size() > 0){
  294. JSONObject retObj = DataUtil.upDeviceParams(JSON.toJSONString(prods));
  295. if(retObj != null && retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
  296. for(Map<String, Object> prodReq : prods) {
  297. JdbcUtils.updateDeviceParamSync(Integer.valueOf(prodReq.get("id").toString()), 1);
  298. }
  299. log.info("设备参数数据上传成功,数量: " + prods.size());
  300. }
  301. }
  302. }catch (Exception e){
  303. log.info("上传设备参数异常: " + e.getMessage());
  304. }
  305. }
  306. }, 1000, 30*1000); // 首次延迟1秒,之后每30秒执行
  307. }
  308. public static java.util.Timer fswCheckPointTimer;
  309. public static void fswCheckPoint() {
  310. if(fswCheckPointTimer != null) {
  311. fswCheckPointTimer.cancel();
  312. }
  313. fswCheckPointTimer = new java.util.Timer();
  314. fswCheckPointTimer.schedule(new TimerTask() {
  315. public void run() {
  316. try{
  317. if(work_status == 1 && fxlabel2Flag == 1){ // 获取点位
  318. boolean ret = S7Util.getParamFlag();
  319. if(ret){
  320. curPoint += 1;
  321. curPointX.add(String.valueOf(S7Util.readXPosition()));
  322. curPointY.add(String.valueOf(S7Util.readYPosition()));
  323. }
  324. if(curPoint == 4){
  325. String pointx1 = "";
  326. String pointx2 = "";
  327. String pointx3 = "";
  328. String pointx4 = "";
  329. String pointy1 = "";
  330. String pointy2 = "";
  331. String pointy3 = "";
  332. String pointy4 = "";
  333. int i = 0;
  334. for(String str : curPointX){
  335. if(i == 0){
  336. pointx1 = str;
  337. }else if(i == 1){
  338. pointx2 = str;
  339. }else if(i == 2){
  340. pointx3 = str;
  341. }else if(i == 3){
  342. pointx4 = str;
  343. }
  344. i++;
  345. }
  346. int j = 0;
  347. for(String str : curPointX){
  348. if(i == 0){
  349. pointy1 = str;
  350. }else if(i == 1){
  351. pointy2 = str;
  352. }else if(i == 2){
  353. pointy3 = str;
  354. }else if(i == 3){
  355. pointy4 = str;
  356. }
  357. j++;
  358. }
  359. JSONObject retObj = DataUtil.saveFswPoint(product_sn.getText(),pointx1+"_"+pointy1,pointx2+"_"+pointy2,pointx3+"_"+pointy3,pointx4+"_"+pointy4);
  360. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  361. MesClient.curPointX.clear();
  362. MesClient.curPointY.clear();
  363. MesClient.curPoint = 0;
  364. }
  365. }
  366. }
  367. }catch (Exception e){
  368. log.info("异常: " + e.getMessage());
  369. }
  370. }
  371. }, 1000, 500); // 首次延迟1秒,之后每30秒执行
  372. }
  373. //设置tcp连接状态显示
  374. public static void setTcpStatus() {
  375. if(tcp_connect_flag) {
  376. status_menu.setText("已连接MES服务器");
  377. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  378. heart_beat_menu.repaint();
  379. }else {
  380. status_menu.setText("未连接MES服务器");
  381. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  382. heart_beat_menu.repaint();
  383. }
  384. }
  385. public static void initWarehouseData(){
  386. resetScanA();
  387. }
  388. public static void resetScanA() {
  389. work_status = 0;
  390. check_quality_result = false;
  391. MesClient.finish_ok_bt.setEnabled(false);
  392. MesClient.finish_ng_bt.setEnabled(false);
  393. product_sn.setText("");
  394. MesClient.fxlabel.setText("");
  395. MesClient.fxlabel.setVisible(false);
  396. MesClient.programNo = "";
  397. MesClient.tjFlag = 0;
  398. MesClient.tjTime = 0;
  399. MesClient.yxTime = 0;
  400. MesClient.f_scan_data_bt_1.setEnabled(true);
  401. MesClient.status_menu.setText("请扫工件码");
  402. S7Util.sendStartSignal(true);
  403. MesClient.curPointX.clear();
  404. MesClient.curPointY.clear();
  405. MesClient.curPoint = 0;
  406. updateMaterailData();
  407. // shiftUserCheck();
  408. }
  409. public static int userLoginHours;//用户登录所处小时
  410. //换班用户信息检查
  411. private static void shiftUserCheck() {
  412. LocalDateTime now = LocalDateTime.now();
  413. // 判断时间范围
  414. if (userLoginHours >= 8 && userLoginHours < 20) {
  415. int hour = now.getHour();
  416. if (hour >= 20 || hour < 8) {
  417. logoff();
  418. }
  419. } else {
  420. int hour = now.getHour();
  421. if (hour >= 8 && hour < 20) {
  422. logoff();
  423. }
  424. }
  425. }
  426. public static void resetScanB() {
  427. }
  428. //获取用户20位
  429. public static void getUser() {
  430. user20 = user_menu.getText().toString();
  431. String space_tmp1 = "";
  432. if(user20.length()<20) {
  433. for(int i=0;i<20-user20.length();i++) {
  434. space_tmp1 = space_tmp1 + " ";
  435. }
  436. }
  437. user20 = user20 + space_tmp1;
  438. }
  439. //获取barcode内容36位
  440. public static String getBarcode(String barcodeTmp) {
  441. String barcodeRet = barcodeTmp;
  442. if(barcodeTmp.equalsIgnoreCase("")) {
  443. return "";
  444. }else {
  445. if(barcodeTmp.length()<36) {
  446. String space = "";
  447. for(int i=0;i<36-barcodeTmp.length();i++) {
  448. space = space + " ";
  449. }
  450. barcodeRet = barcodeTmp + space;
  451. }
  452. }
  453. return barcodeRet;
  454. }
  455. public static void scanBarcode() {
  456. if(work_status == 1){
  457. JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  458. return;
  459. }
  460. String scanBarcodeTitle = "";
  461. switch(scan_type) {
  462. case 1:
  463. product_sn.setText("");
  464. scanBarcodeTitle = "请扫工件码";
  465. break;
  466. }
  467. //弹窗扫工件码
  468. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  469. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  470. //获取用户
  471. getUser();
  472. //获取扫码内容36位
  473. String barcode36 = getBarcode(scanBarcode);//处理36为码
  474. //工位号
  475. String gw = "";
  476. switch(scan_type) {
  477. case 1:
  478. product_sn.setText(scanBarcode);
  479. break;
  480. }
  481. //刷新界面
  482. mesClientFrame.repaint();
  483. if(!tcp_connect_flag) {
  484. MesClient.setMenuStatus("设备未连接Mes服务器",-1);
  485. // JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  486. return;
  487. }
  488. //弹框扫码,如果和规定的工装编号一致才可以继续
  489. String scanBarcode1 = JOptionPane.showInputDialog(null, "请扫工装二维码");
  490. if (!scanBarcode1.equalsIgnoreCase("OP280A")){
  491. //菜单栏给出提示信息
  492. MesClient.setMenuStatus("请扫正确的工装二维码",-1);
  493. return;
  494. }
  495. // 查询工件质量
  496. Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
  497. if(!sendret){
  498. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  499. // JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  500. return;
  501. }
  502. }else {
  503. MesClient.setMenuStatus("请扫工件码,请重试",-1);
  504. // JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  505. return;
  506. }
  507. }
  508. public static void logoff() {
  509. // welcomeWin.setVisible(true);
  510. mesClientFrame.setVisible(false);
  511. System.exit(0);
  512. nettyClient = null;
  513. // if(heartBeatTimer!=null) {
  514. // heartBeatTimer.cancel();
  515. // }
  516. // if(heartBeatIconTimer!=null) {
  517. // heartBeatIconTimer.cancel();
  518. // }
  519. tcp_connect_flag = false;
  520. connect_request_flag = false;
  521. }
  522. public MesClient() {
  523. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  524. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  525. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  526. setBounds(0, 0, 1024, 768);
  527. JMenuBar menuBar = new JMenuBar();
  528. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  529. setJMenuBar(menuBar);
  530. JMenu fileMenu = new JMenu("用户");
  531. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  532. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  533. menuBar.add(fileMenu);
  534. JMenuItem exitMenuItem = new JMenuItem("退出");
  535. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  536. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  537. fileMenu.add(exitMenuItem);
  538. exitMenuItem.addMouseListener(new MouseAdapter() {
  539. @Override
  540. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  541. super.mouseClicked(e);
  542. //dispose();
  543. logoff();
  544. }
  545. });
  546. JMenu settingMenu = new JMenu("设置");
  547. //settingMenu.setVisible(false);
  548. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  549. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  550. menuBar.add(settingMenu);
  551. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  552. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  553. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  554. resetTcpMenu.addMouseListener(new MouseAdapter() {
  555. @Override
  556. public void mousePressed(MouseEvent e) {
  557. super.mouseClicked(e);
  558. //重连mes
  559. nettyClient.future.channel().close();
  560. }
  561. });
  562. settingMenu.add(resetTcpMenu);
  563. JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
  564. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  565. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  566. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  567. @Override
  568. public void mousePressed(MouseEvent e) {
  569. super.mouseClicked(e);
  570. if(work_status == 1 && (tjFlag == 2 && tjFlag == 3)){
  571. DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20);
  572. }else{
  573. resetScanA();
  574. }
  575. }
  576. });
  577. settingMenu.add(resetTcpMenu_1);
  578. JMenuItem mes_block_menu = new JMenuItem("MES屏蔽");
  579. mes_block_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  580. mes_block_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  581. mes_block_menu.addMouseListener(new MouseAdapter() {
  582. @Override
  583. public void mousePressed(MouseEvent e) {
  584. super.mouseClicked(e);
  585. Color currentColor = mes_block_menu.getBackground();
  586. // 判断是否为绿色
  587. if (Color.GREEN.equals(currentColor)) {
  588. // 还原成默认颜色(一般是 null 或菜单条的背景色)
  589. mes_block_menu.setBackground(UIManager.getColor("MenuItem.background"));
  590. mes_flag = false;
  591. } else {
  592. // 设置为绿色
  593. mes_block_menu.setBackground(Color.GREEN);
  594. mes_flag = true;
  595. }
  596. }
  597. });
  598. settingMenu.add(mes_block_menu);
  599. JMenuItem resetTcpMenu_2 = new JMenuItem("程序点检");
  600. resetTcpMenu_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  601. resetTcpMenu_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  602. resetTcpMenu_2.addMouseListener(new MouseAdapter() {
  603. @Override
  604. public void mousePressed(MouseEvent e) {
  605. super.mouseClicked(e);
  606. // resetScanA();
  607. boolean ret = fxlabel2Flag == 1?false:true;
  608. if(fxlabel2Flag == 1){
  609. fxlabel2Flag = 0;
  610. }else{
  611. fxlabel2Flag = 1;
  612. }
  613. fxlabel2.setVisible(ret);
  614. }
  615. });
  616. settingMenu.add(resetTcpMenu_2);
  617. contentPane = new JPanel();
  618. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  619. setContentPane(contentPane);
  620. contentPane.setLayout(new BorderLayout(0, 0));
  621. JToolBar toolBar = new JToolBar();
  622. contentPane.add(toolBar, BorderLayout.NORTH);
  623. JLabel equipment_statu_label = new JLabel("状态:");
  624. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  625. equipment_statu_label.setForeground(Color.BLACK);
  626. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  627. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  628. toolBar.add(equipment_statu_label);
  629. status_menu = new JButton("设备未连接MES服务器");
  630. if(tcp_connect_flag) {
  631. status_menu.setText("已连接MES服务器");
  632. status_menu.setForeground(Color.GREEN);
  633. }else {
  634. status_menu.setText("未连接MES服务器");
  635. status_menu.setForeground(Color.DARK_GRAY);
  636. }
  637. status_menu.addActionListener(new ActionListener() {
  638. public void actionPerformed(ActionEvent e) {
  639. }
  640. });
  641. status_menu.setForeground(Color.GREEN);
  642. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  643. status_menu.setBackground(Color.BLACK);
  644. toolBar.add(status_menu);
  645. JLabel space_1 = new JLabel(" ");
  646. toolBar.add(space_1);
  647. JLabel heart_beat_status_label = new JLabel("心跳:");
  648. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  649. heart_beat_status_label.setForeground(Color.BLACK);
  650. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  651. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  652. toolBar.add(heart_beat_status_label);
  653. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  654. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  655. heart_beat_menu.setForeground(Color.GREEN);
  656. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  657. heart_beat_menu.setBackground(Color.BLACK);
  658. toolBar.add(heart_beat_menu);
  659. JLabel space_2 = new JLabel(" ");
  660. toolBar.add(space_2);
  661. JLabel user_status_label = new JLabel("登录用户:");
  662. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  663. user_status_label.setForeground(Color.BLACK);
  664. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  665. user_status_label.setBackground(Color.LIGHT_GRAY);
  666. toolBar.add(user_status_label);
  667. user_menu = new JButton("JinJuShi");
  668. user_menu.setForeground(Color.GREEN);
  669. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  670. user_menu.setBackground(Color.BLACK);
  671. toolBar.add(user_menu);
  672. JLabel space_3 = new JLabel(" ");
  673. toolBar.add(space_3);
  674. JLabel space_4 = new JLabel(" ");
  675. toolBar.add(space_4);
  676. mesbtn = new JButton("MES已开启");
  677. mesbtn.setBackground(Color.GREEN);
  678. mesbtn.setForeground(Color.WHITE);
  679. mesbtn.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  680. toolBar.add(mesbtn);
  681. mesbtn.addActionListener(new ActionListener() {
  682. public void actionPerformed(ActionEvent e) {
  683. String pass = "503833";
  684. // Boolean ret = S7Util.getMesStatus();
  685. //弹窗扫工件码
  686. String scanBarcode = JOptionPane.showInputDialog(null, "请输入密码");
  687. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")&&scanBarcode.equals(pass)) {
  688. MesClient.mes_flag = !MesClient.mes_flag;
  689. // S7Util.sendMesStatus(!ret); // 屏蔽
  690. formatMesStatus();
  691. }else{
  692. MesClient.setMenuStatus("密码错误",-1);
  693. }
  694. }
  695. });
  696. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  697. tabbedPane.setMinimumSize(new Dimension(400, 50));
  698. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  699. contentPane.add(tabbedPane);
  700. //首页
  701. JPanel indexPanelA = new JPanel();
  702. indexScrollPaneA = new JScrollPane(indexPanelA);
  703. indexPanelA.setLayout(null);
  704. fxlabel2 = new JLabel("程序点检中");
  705. fxlabel2.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  706. fxlabel2.setBounds(81, 0, 810, 70);
  707. fxlabel2.setForeground(Color.RED);
  708. fxlabel2.setHorizontalAlignment(SwingConstants.CENTER);
  709. fxlabel2.setVisible(false);
  710. indexPanelA.add(fxlabel2);
  711. product_sn = new JTextField();
  712. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  713. product_sn.setEditable(false);
  714. product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  715. product_sn.setBounds(81, 70, 602, 70);
  716. indexPanelA.add(product_sn);
  717. product_sn.setColumns(10);
  718. f_scan_data_bt_1 = new JButton("扫码");
  719. f_scan_data_bt_1.addActionListener(new ActionListener() {
  720. public void actionPerformed(ActionEvent e) {
  721. scan_type = 1;
  722. scanBarcode();
  723. }
  724. });
  725. f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  726. f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  727. f_scan_data_bt_1.setBounds(693, 70, 198, 70);
  728. indexPanelA.add(f_scan_data_bt_1);
  729. // String[] hjtitles = new String[]{"焊机1","焊机2","焊机3"};
  730. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  731. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  732. // mesRasdioHj.setSize(500,50);
  733. // mesRadioHj.setBounds(190,170,500,50);
  734. // indexPanelA.add(mesRadioHj);
  735. fxlabel = new JLabel("该工件为返修件,请仔细检查");
  736. fxlabel.setFont(new Font("微软雅黑", Font.PLAIN, 38));
  737. fxlabel.setBounds(81, 170, 810, 70);
  738. fxlabel.setForeground(Color.RED);
  739. fxlabel.setHorizontalAlignment(SwingConstants.CENTER);
  740. fxlabel.setVisible(false);
  741. indexPanelA.add(fxlabel);
  742. finish_ok_bt = new JButton("OK");
  743. finish_ok_bt.setEnabled(false);
  744. finish_ok_bt.addActionListener(new ActionListener() {
  745. public void actionPerformed(ActionEvent e) {
  746. if(work_status == 1 && check_quality_result){
  747. String sn = getBarcode(product_sn.getText());
  748. getUser();
  749. String qret = "OK";
  750. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
  751. if(!sendret){
  752. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  753. return;
  754. }else{
  755. MesClient.resetScanA();
  756. MesClient.scan_type = 1;
  757. MesClient.scanBarcode();
  758. MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
  759. }
  760. }
  761. }
  762. });
  763. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  764. finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  765. finish_ok_bt.setBounds(185, 291, 240, 80);
  766. finish_ok_bt.setEnabled(false);
  767. indexPanelA.add(finish_ok_bt);
  768. finish_ng_bt = new JButton("NG");
  769. finish_ng_bt.setEnabled(false);
  770. finish_ng_bt.addActionListener(new ActionListener() {
  771. public void actionPerformed(ActionEvent e) {
  772. if(work_status == 1 && check_quality_result){
  773. String sn = getBarcode(product_sn.getText());
  774. getUser();
  775. String qret = "NG";
  776. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
  777. if(!sendret){
  778. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  779. return;
  780. }else{
  781. MesClient.resetScanA();
  782. MesClient.scan_type = 1;
  783. MesClient.scanBarcode();
  784. MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
  785. }
  786. }
  787. }
  788. });
  789. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  790. finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  791. finish_ng_bt.setBounds(508, 291, 240, 80);
  792. finish_ng_bt.setEnabled(false);
  793. indexPanelA.add(finish_ng_bt);
  794. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  795. tabbedPane.setEnabledAt(0, true);
  796. // searchScrollPane = new JScrollPane((Component) null);
  797. indexPanelC = new JPanel();
  798. searchScrollPaneDj = new JScrollPane(indexPanelC);
  799. indexPanelC.setLayout(null);
  800. // 转速显示
  801. spindleSpeedLabel = new JLabel("转速: 0 rpm");
  802. spindleSpeedLabel.setBounds(81, 200, 400, 40);
  803. spindleSpeedLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  804. indexPanelA.add(spindleSpeedLabel);
  805. // 进给显示
  806. feedRateLabel = new JLabel("进给: 0 mm/min");
  807. feedRateLabel.setBounds(320, 200, 400, 40);
  808. feedRateLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  809. indexPanelA.add(feedRateLabel);
  810. // 扭矩显示
  811. torqueLabel = new JLabel("扭矩: 0");
  812. torqueLabel.setBounds(600, 200, 400, 40);
  813. torqueLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  814. indexPanelA.add(torqueLabel);
  815. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  816. indexPanelB = new JPanel();
  817. searchScrollPane = new JScrollPane(indexPanelB);
  818. indexPanelB.setLayout(null);
  819. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  820. tabbedPane.addChangeListener(new ChangeListener() {
  821. @Override
  822. public void stateChanged(ChangeEvent e) {
  823. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  824. int selectedIndex = tabbedPane.getSelectedIndex();
  825. System.out.println("selectedIndex:"+selectedIndex);
  826. if(selectedIndex == 1){
  827. }
  828. }
  829. });
  830. }
  831. public static void setMenuStatus(String msg,int error){
  832. if(error == 0){
  833. MesClient.status_menu.setForeground(Color.GREEN);
  834. }else{
  835. MesClient.status_menu.setForeground(Color.RED);
  836. }
  837. MesClient.status_menu.setText(msg);
  838. }
  839. public static void getMaterailData(){
  840. try{
  841. JSONObject retObj = DataUtil.getBindMaterail();
  842. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  843. java.util.List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  844. int i = 0;
  845. rowData = new Object[arrs.size()][7];
  846. for (BindMaterialResp bindMaterialResp:arrs){
  847. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  848. rowData[i][1] = bindMaterialResp.getBatchSn();
  849. rowData[i][2] = bindMaterialResp.getLastTimes();
  850. rowData[i][3] = "";
  851. rowData[i][4] = bindMaterialResp.getCraft();
  852. rowData[i][5] = bindMaterialResp.getMaterialId();
  853. rowData[i][6] = bindMaterialResp.getType();
  854. i++;
  855. }
  856. bindBatchPanel();
  857. }
  858. }catch (Exception e){
  859. log.info(e.getMessage());
  860. }
  861. }
  862. public static void updateMaterailData(){
  863. try{
  864. JSONObject retObj = DataUtil.getBindMaterail();
  865. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  866. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  867. int i = 0;
  868. for (BindMaterialResp bindMaterialResp:arrs){
  869. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  870. rowData[i][1] = bindMaterialResp.getBatchSn();
  871. rowData[i][2] = bindMaterialResp.getLastTimes();
  872. rowData[i][3] = "";
  873. rowData[i][4] = bindMaterialResp.getCraft();
  874. rowData[i][5] = bindMaterialResp.getMaterialId();
  875. rowData[i][6] = bindMaterialResp.getType();
  876. i++;
  877. }
  878. MesClient.table.repaint();
  879. }
  880. }catch (Exception e){
  881. log.info(e.getMessage());
  882. }
  883. }
  884. // 绑定物料批次码
  885. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  886. //弹窗扫工件码
  887. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  888. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  889. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  890. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  891. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  892. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  893. updateMaterailData();
  894. }else{
  895. if(retObj.get("result")==null){
  896. MesClient.setMenuStatus("请求失败,请重试",-1);
  897. }else{
  898. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  899. MesClient.setMenuStatus(retObj.getString("message"),-1);
  900. }
  901. }
  902. }
  903. }
  904. }
  905. public static void bindBatchPanel(){
  906. JPanel indexPanelBB = new JPanel();
  907. JPanel panel = new JPanel();
  908. panel.setBounds(0, 0, 990, 550);
  909. // panel.setBounds(81, 50, 810, 479);
  910. indexPanelBB.add(panel);
  911. panel.setLayout(new GridLayout(0, 1, 0, 0));
  912. table = new JTable(rowData, columnNames){
  913. public boolean isCellEditable(int row, int column) {
  914. if(column == 3){
  915. return true;
  916. }
  917. return false;
  918. }
  919. };
  920. table.setRowHeight(40);
  921. table.setEnabled(true);
  922. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  923. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  924. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  925. JScrollPane scrollPane = new JScrollPane(table);
  926. panel.add(scrollPane);
  927. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  928. indexPanelBB.setLayout(null);
  929. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  930. }
  931. public static java.util.Timer monitorDeviceTimer;
  932. public static void monitorDevice() {
  933. if(monitorDeviceTimer != null) {
  934. monitorDeviceTimer.cancel();
  935. }
  936. monitorDeviceTimer = new java.util.Timer();
  937. monitorDeviceTimer.schedule(new TimerTask() {
  938. public void run() {
  939. try{
  940. formatMesStatus();
  941. }catch (Exception e){
  942. e.printStackTrace();
  943. }
  944. try {
  945. initS7();
  946. if (mes_flag){
  947. S7Util.getDeviceShield();
  948. }else{
  949. if (work_status == 0){
  950. boolean ss = S7Util.getDeviceStart();
  951. if(!ss){
  952. S7Util.sendStartSignal(true);
  953. }
  954. }
  955. S7Util.getDeviceState();
  956. }
  957. } catch (Exception e) {
  958. log.info(e.getMessage());
  959. }
  960. }
  961. }, 1000, 1000); // 首次延迟1秒,之后每30秒执行
  962. }
  963. public static void formatMesStatus(){
  964. // Boolean ret = S7Util.getMesStatus();
  965. Boolean ret = MesClient.mes_flag;
  966. if(ret){ // MES屏蔽
  967. mesbtn.setBackground(Color.RED);
  968. mesbtn.setText("MES已屏蔽");
  969. }else{
  970. mesbtn.setBackground(Color.GREEN);
  971. mesbtn.setText("MES已开启");
  972. }
  973. }
  974. public static void initS7(){
  975. try {
  976. if(s7Connector == null) {
  977. //PLC地址
  978. String ipAddress = plcUrl;
  979. //默认端口
  980. // int port = 102;
  981. int rack=0;
  982. int slot=3;
  983. int timeout=1000;
  984. s7Connector=
  985. S7ConnectorFactory
  986. .buildTCPConnector()
  987. .withHost(ipAddress)
  988. // .withPort(port) //optional
  989. // .withRack(rack) //optional
  990. // .withSlot(slot) //optional
  991. .withTimeout(timeout) //连接超时时间
  992. .build();
  993. S7Serializer s7Serializer2L = S7SerializerFactory.buildSerializer(s7Connector);
  994. }
  995. } catch (Exception e) { // 如果连接失败保存失败再次尝试连接一次
  996. s7Connector = null;
  997. e.printStackTrace();
  998. }
  999. }
  1000. }