我在运行程序时调用库本机函数 OpenSSPComPortUSB() 弹出无法打开端口 \.\COM208。为什么它返回 \.\COM208 因为我已经通过 PortNumber =7; 下面是 Java 代码,我的目标是打开端口 COM7 以启动与 smart hoper 的串行通信。
// AccessITLLib.java
public class AccessITLLib
{
public static class SSP_COMMAND extends Structure
{
SSP_FULL_KEY Key;
public NativeLong BaudRate;
public byte PortNumber;
public NativeLong Timeout;
public byte SSPAddress;
public byte RetryLevel;
public byte EncryptionStatus;
public byte CommandDataLength;
public byte[] CommandData = new byte[255];
public byte ResponseStatus;
public byte ResponseDataLength;
public byte[] ResponseData = new byte[255];
public byte IgnoreError;
}
public interface ITLLib extends Library
{
ITLLib INSTANCE = (ITLLib) Native.loadLibrary("ITLSSPproc",
ITLLib.class);
public int OpenSSPComPort(SSP_COMMAND p);
public int OpenSSPComPortUSB(SSP_COMMAND p);
public int CloseSSPComPort();
public int CloseSSPComPortUSB();
}
public static void main(String[] args)
{
SSP_COMMAND commandStruct = new SSP_COMMAND();
commandStruct.BaudRate = new NativeLong(9600);
commandStruct.PortNumber =7;
commandStruct.Timeout = 500;
commandStruct.RetryLevel = 3;
commandStruct.IgnoreError = 1;
commandStruct.SSPAddress =16;
ITLLib.INSTANCE.CloseSSPComPort();
ITLLib.INSTANCE.CloseSSPComPortUSB();
ITLLib.INSTANCE.OpenSSPComPort(commandStruct);
ITLLib.INSTANCE.OpenSSPComPortUSB(commandStruct);
}
}
here are the c structures
typedef struct{
SSP_FULL_KEY Key;
unsigned long BaudRate;
unsigned long Timeout;
unsigned char PortNumber;
unsigned char SSPAddress;
unsigned char RetryLevel;
unsigned char EncryptionStatus;
unsigned char CommandDataLength;
unsigned char CommandData[255];
unsigned char ResponseStatus;
unsigned char ResponseDataLength;
unsigned char ResponseData[255];
unsigned char IgnoreError;
}SSP_COMMAND;
typedef struct{
unsigned long long FixedKey;
unsigned long long EncryptKey;
}SSP_FULL_KEY;