yangys
2024-02-02 b82c71a3e3a97a78bd18ff598d27f3062600d22a
mdc-parent/mdc-collect/src/main/java/com/qianwen/mdc/utils/Lsv2Util.java
@@ -1,152 +1,121 @@
/*     */ package com.qianwen.mdc.utils;
/*     */
/*     */ import org.eclipse.swt.ole.win32.OleAutomation;
/*     */ import org.eclipse.swt.ole.win32.Variant;
/*     */
/*     */
/*     */
/*     */ public class Lsv2Util
/*     */ {
/*     */   public static final String lsv2Ctrl3ProgId = "{F9EE051D-C65D-4480-8E35-76F10FAB15C6}";
/*     */
/*     */   private static Variant execute(OleAutomation oleAutomation, String methodName) {
/*  13 */     return execute(oleAutomation, methodName, null);
/*     */   }
/*     */
/*     */   private static Variant execute(OleAutomation oleAutomation, String methodName, Variant[] args) {
/*  17 */     int mid = getID(oleAutomation, methodName);
/*     */
/*  19 */     return execute(oleAutomation, mid, args);
/*     */   }
/*     */   private static Variant execute(OleAutomation oleAutomation, int mid, Variant[] args) {
/*     */     Variant rtnv;
/*  23 */     if (mid < 0) {
/*  24 */       return null;
/*     */     }
/*     */
/*     */
/*  28 */     if (args == null) {
/*  29 */       rtnv = oleAutomation.invoke(mid);
/*     */     } else {
/*  31 */       rtnv = oleAutomation.invoke(mid, args);
/*     */     }
/*     */
/*  34 */     return rtnv;
/*     */   }
/*     */
/*     */   private static int getID(OleAutomation oleAutomation, String name) {
/*     */     try {
/*  39 */       int[] ids = oleAutomation.getIDsOfNames(new String[] { name });
/*  40 */       if (ids == null) {
/*  41 */         return -1;
/*     */       }
/*     */
/*  44 */       return ids[0];
/*  45 */     } catch (RuntimeException e) {
/*  46 */       e.printStackTrace();
/*     */
/*     */
/*  49 */       return -1;
/*     */     }
/*     */   }
/*     */   public static String getLastError(OleAutomation oleAutomation) {
/*  53 */     String methodName = "LastError";
/*     */
/*  55 */     return execute(oleAutomation, methodName).getString();
/*     */   }
/*     */
/*     */   public static String getLastErrorString(OleAutomation oleAutomation) {
/*  59 */     String methodName = "LastErrorString";
/*     */
/*  61 */     return execute(oleAutomation, methodName).getString();
/*     */   }
/*     */
/*     */   public static boolean connect(OleAutomation oleAutomation) {
/*  65 */     String methodName = "Connect";
/*     */
/*  67 */     return execute(oleAutomation, methodName).getBoolean();
/*     */   }
/*     */
/*     */   public static boolean testConnection(OleAutomation oleAutomation) {
/*  71 */     String methodName = "TestConnection";
/*  72 */     Variant[] args = { new Variant(2) };
/*     */
/*  74 */     return execute(oleAutomation, methodName, args).getBoolean();
/*     */   }
/*     */
/*     */   public static boolean disConnect(OleAutomation oleAutomation) {
/*  78 */     String methodName = "DisConnect";
/*     */
/*  80 */     return execute(oleAutomation, methodName).getBoolean();
/*     */   }
/*     */
/*     */   public static boolean reConnect(OleAutomation oleAutomation) {
/*  84 */     String methodName = "ReConnect";
/*     */
/*  86 */     return execute(oleAutomation, methodName).getBoolean();
/*     */   }
/*     */
/*     */   public static void setMedium(OleAutomation oleAutomation, int medium) {
/*  90 */     String methodName = "Medium";
/*  91 */     Variant[] args = { new Variant(medium) };
/*     */
/*  93 */     execute(oleAutomation, methodName, args);
/*     */   }
/*     */
/*     */   public static void setIPAddress(OleAutomation oleAutomation, String ipAddress) {
/*  97 */     String methodName = "IPAddress";
/*  98 */     Variant[] args = { new Variant(ipAddress) };
/*     */
/* 100 */     execute(oleAutomation, methodName, args);
/*     */   }
/*     */
/*     */   public static void setPort(OleAutomation oleAutomation) {
/* 104 */     String methodName = "Port";
/*     */
/* 106 */     execute(oleAutomation, methodName);
/*     */   }
/*     */
/*     */   public static void setTransferMode(OleAutomation oleAutomation, Integer mode) {
/* 110 */     String methodName = "TransferMode";
/* 111 */     Variant[] args = { new Variant(mode.intValue()) };
/*     */
/* 113 */     execute(oleAutomation, methodName, args);
/*     */   }
/*     */
/*     */   public static void setHostFunction(OleAutomation oleAutomation, Boolean hostFunction) {
/* 117 */     String methodName = "HostFunction";
/* 118 */     Variant[] args = { new Variant(hostFunction.booleanValue()) };
/*     */
/* 120 */     execute(oleAutomation, methodName, args);
/*     */   }
/*     */
/*     */   public static String getVersionTNC(OleAutomation oleAutomation) {
/* 124 */     String methodName = "VersionTNC";
/*     */
/* 126 */     return execute(oleAutomation, methodName).getString();
/*     */   }
/*     */
/*     */
/*     */
/*     */   public static String getProgramName(OleAutomation oleAutomation) {
/* 132 */     String methodName = "ReceiveDNCInfo";
/* 133 */     short type = 3;
/* 134 */     int InfoPara = 0;
/* 135 */     Variant[] args = { new Variant(type), new Variant(InfoPara) };
/*     */
/* 137 */     return execute(oleAutomation, methodName, args).getString();
/*     */   }
/*     */
/*     */   public static String receiveMemBlock(OleAutomation oleAutomation, short type, short address, short count) {
/* 141 */     String methodName = "ReceiveMemBlock";
/* 142 */     Variant[] args = { new Variant(type), new Variant(address), new Variant(count) };
/*     */
/* 144 */     return execute(oleAutomation, methodName, args).getString();
/*     */   }
/*     */ }
package com.qianwen.mdc.utils;
/* Location:              D:\yangys\mdm\老代码\mdcplugin\mdc-plugin-0.0.1-SNAPSHOT-删除lib.jar!\BOOT-INF\classes\cn\net\hx\md\\utils\Lsv2Util.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.Variant;
public class Lsv2Util {
  public static final String lsv2Ctrl3ProgId = "{F9EE051D-C65D-4480-8E35-76F10FAB15C6}";
  private static Variant execute(OleAutomation oleAutomation, String methodName) {
    return execute(oleAutomation, methodName, null);
  }
  private static Variant execute(OleAutomation oleAutomation, String methodName, Variant[] args) {
    int mid = getID(oleAutomation, methodName);
    return execute(oleAutomation, mid, args);
  }
  private static Variant execute(OleAutomation oleAutomation, int mid, Variant[] args) {
    Variant rtnv;
    if (mid < 0)
      return null;
    if (args == null) {
      rtnv = oleAutomation.invoke(mid);
    } else {
      rtnv = oleAutomation.invoke(mid, args);
    }
    return rtnv;
  }
  private static int getID(OleAutomation oleAutomation, String name) {
    try {
      int[] ids = oleAutomation.getIDsOfNames(new String[] { name });
      if (ids == null)
        return -1;
      return ids[0];
    } catch (RuntimeException e) {
      e.printStackTrace();
      return -1;
    }
  }
  public static String getLastError(OleAutomation oleAutomation) {
    String methodName = "LastError";
    return execute(oleAutomation, methodName).getString();
  }
  public static String getLastErrorString(OleAutomation oleAutomation) {
    String methodName = "LastErrorString";
    return execute(oleAutomation, methodName).getString();
  }
  public static boolean connect(OleAutomation oleAutomation) {
    String methodName = "Connect";
    return execute(oleAutomation, methodName).getBoolean();
  }
  public static boolean testConnection(OleAutomation oleAutomation) {
    String methodName = "TestConnection";
    Variant[] args = { new Variant(2) };
    return execute(oleAutomation, methodName, args).getBoolean();
  }
  public static boolean disConnect(OleAutomation oleAutomation) {
    String methodName = "DisConnect";
    return execute(oleAutomation, methodName).getBoolean();
  }
  public static boolean reConnect(OleAutomation oleAutomation) {
    String methodName = "ReConnect";
    return execute(oleAutomation, methodName).getBoolean();
  }
  public static void setMedium(OleAutomation oleAutomation, int medium) {
    String methodName = "Medium";
    Variant[] args = { new Variant(medium) };
    execute(oleAutomation, methodName, args);
  }
  public static void setIPAddress(OleAutomation oleAutomation, String ipAddress) {
    String methodName = "IPAddress";
    Variant[] args = { new Variant(ipAddress) };
    execute(oleAutomation, methodName, args);
  }
  public static void setPort(OleAutomation oleAutomation) {
    String methodName = "Port";
    execute(oleAutomation, methodName);
  }
  public static void setTransferMode(OleAutomation oleAutomation, Integer mode) {
    String methodName = "TransferMode";
    Variant[] args = { new Variant(mode.intValue()) };
    execute(oleAutomation, methodName, args);
  }
  public static void setHostFunction(OleAutomation oleAutomation, Boolean hostFunction) {
    String methodName = "HostFunction";
    Variant[] args = { new Variant(hostFunction.booleanValue()) };
    execute(oleAutomation, methodName, args);
  }
  public static String getVersionTNC(OleAutomation oleAutomation) {
    String methodName = "VersionTNC";
    return execute(oleAutomation, methodName).getString();
  }
  public static String getProgramName(OleAutomation oleAutomation) {
    String methodName = "ReceiveDNCInfo";
    short type = 3;
    int InfoPara = 0;
    Variant[] args = { new Variant(type), new Variant(InfoPara) };
    return execute(oleAutomation, methodName, args).getString();
  }
  public static String receiveMemBlock(OleAutomation oleAutomation, short type, short address, short count) {
    String methodName = "ReceiveMemBlock";
    Variant[] args = { new Variant(type), new Variant(address), new Variant(count) };
    return execute(oleAutomation, methodName, args).getString();
  }
}