Installation Guide
- We’ll be assuming you have already install the MOBITEK® SIM Tool Kit Application Programming Interface (STK API) version 6.2 and the MOBITEK® Q24 STK MODEM is connected to a PC
- Install Eclipse IDE (you may use other IDE) and JRE
- Install JACOB – Unzip the file “jacob-1.14.3.zip”
– Copy these 2 files to “system32” folder:
a) jacob-1.14.3-x64.dll
b) jacob-1.14.3-x86.dll
Using the STK API in JAVA
- Create new java project in Eclipse
- Include Jacob.jar in Library
- Create a new class and copy and paste the sample code provided
- Made modification where necessary (ie Port Number, Script for the STK )
– Port number may be change in line
vMOBITEK = Modem.invoke("Init", 1);
– Script of STK may be found in Start() Function
private static void Start() {
...
...
}
// In case you are not using maxis just try to call the main menu first
// Comment the other
JAVA Sample Code FOR MOBITEK STK API
package STKAPIv6;
import com.jacob.activeX.*;
import com.jacob.com.*;
public class STKAPIv6Test {
static Variant vMOBITEK;
static boolean bMOBITEK;
static int iMOBITEK;
static String sMOBITEK;
static ActiveXComponent Modem = new ActiveXComponent ("MobitekSTK6.Modem");
static ActiveXComponent STKAPI = new ActiveXComponent ("MobitekSTK6.SIMToolKit");
public static void main(String[] args)
{
ModemInitialize();
ActivateSTK();
Start();
DeactivateSTK();
ModemDeinitialize();
System.exit(0);
}
private static void ModemInitialize() {
vMOBITEK = Modem.invoke("Init", 1);
iMOBITEK = vMOBITEK.getInt();
switch (iMOBITEK)
{
case 0 : System.out.println("GSM modem is NOT connected to computer!"); System.exit(0);
case 1 : System.out.println("GSM modem is connected to computer."); break;
case 2 : System.out.println("GSM modem is NOT connected to computer because a PIN is required!"); System.exit(0);
case 3 : System.out.println("GSM modem is NOT connected to computer because wrong PIN is entered!"); System.exit(0);
case 4 : System.out.println("GSM modem is NOT connected to computer because SIM card is blocked by network operator!"); System.exit(0);
case 5 : System.out.println("GSM modem is NOT connected to computer because SIM card has problem!"); System.exit(0);
}
vMOBITEK = Modem.invoke("IsConnectToGSM");
bMOBITEK = vMOBITEK.getBoolean();
if (bMOBITEK)
{
System.out.println("GSM modem is connected to GSM network.");
vMOBITEK = Modem.invoke("OperatorName");
sMOBITEK = vMOBITEK.getString();
System.out.println ("The operator of the GSM network is " + sMOBITEK + ".");
}
else
{
System.out.println("GSM modem is NOT connected to GSM network!");
System.exit(0);
}
}
private static void ActivateSTK() {
// TODO Auto-generated method stub
vMOBITEK = STKAPI.invoke("ActivateSTK");
System.out.println("STK Activated : " + vMOBITEK);
}
private static void Start() {
// TODO Auto-generated method stub
//SimToolKit Menu
System.out.println("=====");
//open main menu
CallMainMenu();
MainMenuSel(254); // EasyAccess
CallSubMenu();
SubMenuSel(1); // News&sport
CallSubMenu();
SubMenuSel(6); // News On Demand
CallSubMenu();
SubMenuSel(5); // Sport
CallSubMenu();
SubMenuSel(1); // Tennis
AllowSendSMS();
System.out.println("=====");
}
// = = = = = = = = = = = = = = = =
private static void CallMainMenu() {
vMOBITEK = STKAPI.invoke("MainMenuDisplay");
bMOBITEK = vMOBITEK.getBoolean();
if(bMOBITEK==true)
{
String MMName = STKAPI.getPropertyAsString("MainMenuName");
//property "MSG" is the sender's message
String MMList = STKAPI.getPropertyAsString("MainMenuList");
System.out.println(MMName+"\n"+MMList);
}
}
private static void MainMenuSel( int num) {
STKAPI.invoke("MainMenuSelect",num);
System.out.println("\n>"+num + " Selected! \n");
}
private static void CallSubMenu() {
vMOBITEK = STKAPI.invoke("SubMenuDisplay");
bMOBITEK = vMOBITEK.getBoolean();
if(bMOBITEK==true)
{
String MMName2 = STKAPI.getPropertyAsString("SubMenuName");
//property "MSG" is the sender's message
String MMList2 = STKAPI.getPropertyAsString("SubMenuList");
System.out.println(MMName2+"\n"+MMList2);
MMName2 = null;
MMList2 = null;
}
}
private static void SubMenuSel( int num) {
STKAPI.invoke("SubMenuSelect",num);
System.out.println("\n>"+num + " Selected! ");
}
private static void AllowSendSMS() {
vMOBITEK = STKAPI.invoke("SMSSentDisplay");
sMOBITEK = vMOBITEK.getString();
if( sMOBITEK == null)
System.out.println(sMOBITEK);
else
System.out.println("User has allowed STK to send out SMS");
}
// = = = = = = = = = = = = = = = =
private static void DeactivateSTK() {
// TODO Auto-generated method stub
vMOBITEK = STKAPI.invoke("DeactivateSTK");
System.out.println("STK Deactivated : " + vMOBITEK);
}
private static void ModemDeinitialize() {
// TODO Auto-generated method stub
//call API to close connection between GSM modem and computer, the return value of the API call is assigned to "SMSAPIReturnValue"
vMOBITEK = Modem.invoke("ShutDown");
//since the return value of "ModemClose" is a boolean, so extract the return value as a boolean and assign to "bSMS"
bMOBITEK = vMOBITEK.getBoolean();
if (bMOBITEK) System.out.println("Connection between GSM modem and computer is closed." );
else System.out.println("Connection between GSM modem and computer CANNOT be closed!" );
}
}
More Information
- Java Sample Code for MOBITEK STK API version 6.3 — Send and Read SMS
- Java Sample Code for MOBITEK STK API version 6.2 — InputRequest() and InputSubmit()
- How Do You Locate a SIM Card in MOBITEK Q24 STK Modem Hub?
- MOBITEK STK API version 6.3 is Released