📄 simplepcconnect.java
字号:
public class SimplePCConnect
{
public native String getModuleInformation();
public native boolean initializePCConnect(int nInitializeStatus);
public native void uninitializePCConnect();
public native boolean openPCConnect(int deviceNumber,String license,String scAddress);
public native boolean reopenPCConnect(int deviceNumber);
public native void closePCConnect(int deviceNumber);
public native boolean getAuthorization(int deviceNumber);
public native void setStatusReceiptRequested(boolean bStatusReceiptRequested);
public native void setRejectDuplicated(boolean bRejectDuplicated);
public native void SetProtocolIdentification(byte bProtocolIdentification);
public native void clearContent();
public native boolean setBinaryContent(String hexString,boolean bHeaderIndication);
public native boolean setUTF8Content(String string,boolean bImmediately);
public native boolean set7BitContent(String string);
public native boolean setWAPPushService(String reference,String description,boolean bImmediately);
public native boolean setWAPPushBookmark(String reference,String description);
public native boolean setWAPGPRSSetting(String reference,String description);
public native boolean setWAPMMSSetting(String reference,String description);
public native boolean setWAPMMSIndication(String from,int size,String reference);
public native boolean sendInformation(int deviceNumber,String terminalAddress,String content);
public native boolean sendContent(int deviceNumber,String terminalAddress);
public native String receiveContent(int deviceNumber);
public native int getStatus(int deviceNumber);
public native int getError(int deviceNumber);
static
{
System.loadLibrary("SimplePCConnect");
}
public static void main(String[] args)
{
try
{
//Create class.
SimplePCConnect pcConnect = new SimplePCConnect();
//Print.
System.out.println("SimplePCConnect已经创建!");
//Print module information.
System.out.println(pcConnect.getModuleInformation());
//Initialize module.
if(pcConnect.initializePCConnect(0))
{
//Print.
System.out.println("初始化SimplePCConnect成功!");
//Device number.
int deviceNumber = 4;
//Print.
System.out.println("准备打开串口:COM" + deviceNumber + "!");
//Open pc connect.
if(pcConnect.openPCConnect(4,"243BABCF4269AAD2E2461F3C84B946F6","13800100500"))
{
//Print.
System.out.println("串口已经打开:COM" + deviceNumber + "!");
//Check authronization.
if(pcConnect.getAuthorization(deviceNumber))
{
//Print.
System.out.println("该设备已经获得授权!");
}
else
{
//Print.
System.out.println("该设备尚未获得授权!");
}
//Result.
boolean result = false;
//Clear content.
pcConnect.clearContent();
//Set the 7Bit content.
//result = pcConnect.set7BitContent("Hello world !");
//Set the UTF8 content.
result = pcConnect.setUTF8Content("您好!",false);
//Set the binary content.
//result = pcConnect.setBinaryContent("0605041583158300480E011F07C00FC1F003E0F820FC20107E08041F044E03902700E409C07234016D9A6C59B6802C09B092446C22490D900890904400220909103C01E89E7E7917803C43E015208104A807C284100A40A502500821855008408102100AA1841008407E0210082143E0102000040807C230006018381806000C0D01800600600180B0",true);
//Set the wap push content.
//result = pcConnect.setWAPPushService("http://simpleteam.com:8081/servlet/com.simpleteam.gateway.jsp.wap.WAPWelcome","我的站点",false);
//Set the wap push bookmark.
//result = pcConnect.setWAPPushBookmark("http://simpleteam.com:8081/servlet/com.simpleteam.gateway.jsp.wap.WAPWelcome","我的书签");
//Set the wap gprs setting.
//result = pcConnect.setWAPGPRSSetting("http://simpleteam.com:8081/servlet/com.simpleteam.gateway.jsp.wap.WAPWelcome","我的设置");
//Set the wap mms setting.
//result = pcConnect.setWAPMMSSetting("http://simpleteam.com:8081/servlet/com.simpleteam.gateway.jsp.wap.MMSDelivery","我的设置");
//Set the wap mms indication.
//result = pcConnect.setWAPMMSIndication("13501026991",522,"http://simpleteam.com:8081/servlet/com.simpleteam.gateway.jsp.wap.MMSWelcome");
//Get current time.
long current = System.currentTimeMillis();
//Report.
String report = "信息已经成功发送!";
//Send content.
if(!pcConnect.sendContent(deviceNumber,"13501026991"))
{
//Check status.
switch(pcConnect.getStatus(deviceNumber))
{
case 1:
//Print.
report = "串口设备失效!";
break;
case 2:
//Print.
report = "AT指令执行成功!";
break;
case 3:
//Print.
report = "AT指令执行错误!";
break;
case 4:
//Print.
report = "GSM网络执行指令错误!";
break;
case 5:
//Print.
report = "硬件设备错误!";
break;
}
}
//Get error.
int error = pcConnect.getError(deviceNumber);
//Print.
System.out.println(report + "(code=" + error + ")");
//Print.
System.out.println("耗时:" + (System.currentTimeMillis() - current) + "ms");
//Close pc connect.
pcConnect.closePCConnect(deviceNumber);
//print.
System.out.println("关闭串口:COM" + deviceNumber + "!");
}
else
{
//Print.
System.out.println("串口打开失败!");
}
//Uninitialize module.
pcConnect.uninitializePCConnect();
//Print.
System.out.println("关闭SimplePCConnect成功!");
}
else
{
//Print.
System.out.println("初始化SimplePCConnect失败!");
}
}
catch(Exception e)
{
System.out.println("SimplePCConnect.main : " + e.getMessage());
System.out.println("SimplePCConnect.main : unexpected exit !");
}
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -