MOBITEK STK API version 5.0 End of Support Notice

MOBITEK® STK API version 5 is no longer supported effective on 26th of October, 2017. Please upgrade to version 6.

More Information

How to Write a Multi-Threaded Java Code with MOBITEK Q24 STK API

SUMMARY OF SUPPORT for MOBITEK Q24 STK MODEM



 

Product:
  1.  MOBITEK Q24 STK MODEM HUB
  2. MOBITEK STK API version 6.3

Which programming language are you using?

  • JAVA
  • JRE version: 7.0-b147
  • JACOB versio: 1.14.3

OS

Windows 7, 64 it
SIM CARD: M-PESA
Description of Problem: We are unable to start multiple modems at once. We have written our application using JAVA, and we are using threads for each modem. The first one works fine, but the next ones fail to connect. The application complain about access.
Final Solution: We do no have Java programme in our team. We will try our best to assist you by pointing you to the right direction.The recommended way is to create an executable (.exe) for each STK modem. E.g. 8 STK modems will have 8 exe. This is easiest and safest. Threading requires programmer having good understanding of thread coding.
The “MobitekSTK6.dll” is apartment threaded. Refer to http://danadler.com/jacob/JacobThreading.html
“If you are using a component that declares itself as ThreadingModel “Apartment” (you can find this out by looking in the registry under its CLSID), and you plan to create, use and destroy this component in one thread – then you are following the rules of an STA and you can declare the thread as an STA thread.”We suggest that you code according to single threaded apartment (STA) instead of multi-threaded apartment (MTA). This means:-

  • all threads must be independent of other each other
  • thread 1 cannot call or pass values to thread 2

Please refer to
ScriptTest.java – creates an STA for the ScriptControl component and runs all its method calls from that STA.”

More Information

 

Java Sample Code for MOBITEK STK API version 6.3 — Send and Read SMS

Introduction

STK refers to SIM Tookit or SIM Tool Kit.

SAT refers to SIM Application Toolkit

Both terms are interchangeable.

Java Sample Code

Declaring variables

 static Variant vMOBITEK;
 static boolean bMOBITEK;
 static int iMOBITEK;
 static String sMOBITEK;

//construct objects for each class in "MobitekSTK6.dll"

static ActiveXComponent Modem = new ActiveXComponent ("MobitekSTK6.Modem");
static ActiveXComponent STKAPI = new ActiveXComponent ("MobitekSTK6.SIMToolKit");
static ActiveXComponent SMS = new ActiveXComponent ("MobitekSTK6.SMS");

To send SMS in java

public static void sendMessage()
 //SV: to send SMS; maximum 160 characters 
 {

 //########### turn delivery status report on #######################
 //call API to turn delivery status report on
 vMOBITEK = SMS.invoke("DeliveryReportOn");
 //the return value of "DeliveryReportOn" is a boolean
 bMOBITEK = vMOBITEK.getBoolean();
 //AQ : therefore assign bMOBITEK as return value of "DeliveryReportOn" 
 if (bMOBITEK)
 {
 System.out.println("Delivery status report is turned on.");
 }
 else
 {
 System.out.println("Delivery status report is NOT turned on!");
 }
 //########### end: turn delivery status report on #######################
 
 //------------------ send SMS ----------------------------------------
 //set value of property;
 //"ToNumber" is the recipient's number;
 SMS.setProperty("ToNumber", "0176096718");
 //"ToMessage" is the SMS to be send to the recipient; maximum 160 characters
 SMS.setProperty("ToMessage", "Hello from JAVA with SMS API version 7. Test no. 6");
 //AQ : call API to send new message
 vMOBITEK = SMS.invoke("SendSMS");
 //AQ : the return value of "SendSMS" is a boolean
 bMOBITEK = vMOBITEK.getBoolean();
 //AQ : therefore assign bMOBITEK as return value of "SendSMS" 
 if (bMOBITEK)
 {
 System.out.println("Message sent!");
 
 //try 3 times
 for (int i=1; i<=3; i++) 
 {
 try {
 //AQ : call API to get delivery report
 vMOBITEK = SMS.invoke("GetDeliveryReport");
 //AQ : the return value of "GetDeliveryReport" is a boolean
 //AQ : therefore assign bMOBITEK as return value of "GetDeliveryReport"
 bMOBITEK = vMOBITEK.getBoolean();
 if (bMOBITEK)
 {
 //when "GetDelIveryStatusReport = True", then get value of properties
 int DRStatus = SMS.getPropertyAsInt("DRStatus"); 
 String DRMNRecipient = SMS.getPropertyAsString("DRMNRecipient");
 String DRMsgRef = SMS.getPropertyAsString("DRMsgRef");
 String DRFDate = SMS.getPropertyAsString("DRFDate");
 String DRFTime = SMS.getPropertyAsString("DRFTime");
 String DRRDate = SMS.getPropertyAsString("DRRDate");
 String DRRTime = SMS.getPropertyAsString("DRRTime");
 
 if (DRStatus == 1)
 {
 //System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is " + DRStatus + ".");
 System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is delivered.");
 System.out.println("Your outgoing SMS was received by the SMS Centre on " + DRRDate + ", at " + DRRTime + ", and was successfully delivered to " + DRMNRecipient + ", on " + DRFDate + ", at " + DRFTime + ".");
 }
 else
 if (DRStatus == 0)
 {
 //System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is " + DRStatus + ".");
 System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is not delivered.");
 System.out.println("Your outgoing SMS was received by the SMS Centre on " + DRRDate + ", at " + DRRTime + ", and was NOT successfully delivered to " + DRMNRecipient + "."); 
 }
 else
 if (DRStatus == 2)
 {
 //System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is " + DRStatus + ".");
 System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is unknown.");
 System.out.println("Your outgoing SMS was received by the SMS Centre on " + DRRDate + ", at " + DRRTime + ", and NO status is available.");
 }
 
 break; 
 
 }
 
 else
 {
 System.out.println("No delivery status report available!"); 
 }
 
 //SV: wait for 5 seconds before looping; delivery report from GSM network takes time
 Thread.sleep(5000);
 }
 catch (InterruptedException e)
 {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 } 
 }
 else
 {
 System.out.println("Message NOT sent!");
 }
 //------------------ end: send SMS ----------------------------------------
 }

To Read SMS in java

public static void readMessage() {
 //AQ : readMessage() function is for modem to read incoming message from the sender 
 //------------------------------------------- read SMS -------------------------------------------
 //call API to read incoming SMS 
 vMOBITEK = SMS.invoke("ReadSMS");
 //AQ : the return value of "ReadSMS" is a boolean, therefore assign bMOBITEK as return value of "ReadSMS"
 bMOBITEK = vMOBITEK.getBoolean();
 //if there is new SMS, then get property
 if (bMOBITEK)
 {
 //property "MN" is the sender's mobile number 
 String InNumber = SMS.getPropertyAsString("MN");
 //property "MSG" is the sender's message
 String InMessage = SMS.getPropertyAsString("MSG");
 //property "SCTS" time of the message received by SMS Centre
 String InTime = SMS.getPropertyAsString("SCTS");
 System.out.println("Incoming SMS Read \n From: " + InNumber + "\n Message: "+ InMessage + "\n Time: " + InTime );
 }
 else
 {
 System.out.println("No incoming SMS!");
 }
 //---------------------------------------- end: read SMS ----------------------------------------- 
 }

More Information

Using MOBITEK STK API version 6.2 with Java

Installation Guide

  1. 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
  2. Install Eclipse IDE (you may use other IDE) and JRE
  3. 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

  1. Create new java project in Eclipse
  2. Include Jacob.jar in Library
  3. Create a new class and copy and paste the sample code provided
  4. 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

Continue reading