| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package com.mes.ui;
- import com.mes.netty.NettyClient;
- public class test {
- public static NettyClient nettyClient;
- // 输入函数
- public static java.util.Scanner scanner = new java.util.Scanner(System.in);
- public static void main(String[] args) {
- try {
- // 初始化MesClient的配置信息
- initMesClientConfig();
-
- // 初始化TCP连接
- initTcpConnection();
- // 循环,当输入1时发送报文
- while (true) {
- String input = scanner.nextLine();
- if (input.equals("1")) {
- // 发送模拟质量检查数据
- DataUtil.checkQualityByGw(nettyClient, "509900661376119990FC21100050", "user20","OP190A");
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- // 初始化MesClient的配置信息
- private static void initMesClientConfig() throws Exception {
- // 调用MesClient的readProperty方法来初始化配置
- // 由于readProperty是private的,我们需要通过反射来调用
- java.lang.reflect.Method method = MesClient.class.getDeclaredMethod("readProperty");
- method.setAccessible(true);
- method.invoke(null);
-
- System.out.println("配置信息:");
- System.out.println("工位号:" + MesClient.mes_gw);
- System.out.println("服务器IP:" + MesClient.mes_server_ip);
- System.out.println("TCP端口:" + MesClient.mes_tcp_port);
- }
-
- // 初始化TCP连接
- public static void initTcpConnection() {
- try {
- if (nettyClient == null) {
- // 初始化TCP连接
- nettyClient = new NettyClient();
-
- // 创建一个简单的同步消息
- String msg = "SYNR" + String.format("%6s", MesClient.mes_gw).replace(' ', '0');
- // 调用run方法连接服务器
- nettyClient.run(msg);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
|