プログラムの実行中にライブラリのネイティブ関数 OpenSSPComPortUSB() を呼び出して、ポート \.\COM208 を開くことができないポップアップを取得します。PortNumber = 7; を渡すと、\.\COM208 が返される理由 以下は Java コードです。私の目標はポート COM7 を開いて、スマート ホーパーとのシリアル通信を開始することです。
// 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;