Abnormal exit from middlet | Telit Cinterion IoT Developer Community
February 13, 2018 - 2:00pm, 4068 views
Hi!
I am using an EHS6 module. ATI response command:
Cinterion
EHS6
REVISION 03.001
My middlet checks if there is a SIM card in the slot. If SIM card is not found, the middlet should stop without restarting the module, so the user can access the file system or enter AT commands via serial port.
However, after exiting from the midlet using "notifyDestroyed()", the middlet exits, but the serial port is blocked (as if the middlet was still running), until the watchdog restarts the module . The code:
String response = ata.send("AT+CCID" + "\r"); // getting card id
messWrite(response);
if (response.indexOf("ERROR") > 0) // checking response
{
messWrite("No SIM card present! Exiting application");
runthreads=false;
exitMIDlet();
}
else
{
.. rest of the program
}
public void exitMIDlet() {
messWrite("From exitMIDlet! Exiting application!");
notifyDestroyed();
}
Also, when I try to use a brute-force solution with:
System.exit(0);
I get an exception: java.lang.SecurityException: 118
Thank you in advance for your help.
Endre
Hello,
Generally you should care in your application to release all resource that you use if no longer needed. You should call destroyApp() method to stop the MIDlet and put the code to release all resources inside that method (which includes closing the CommConnection instances) and then in the end call notifyDestroyed() method.
Besides that to make it possible that destreoyApp() can be called by the system (for example when you use AT^SJAM=2 command to stop the MIDlet) you should leave startApp() method after initializing your MIDlet and put the application logic in a separate thread. Until startApp() method execution is not finished destroyApp() will not be automatically called.
Best regards,
Bartłomiej
Thank you for your quick reply, I was on holiday so I will try to fix this problem using your advice these days.
Endre
Hello!
I tried everytyhing You said, but still after destroyApp(true) is called, the app hungs a minute or two in the terminal, and than the module is rebooted.
Autostart is on.
The next experiment was to open a brand new project with the HelloWorld application. Until CommConnection ,InputStream,OutputStream is not used, the middle exits gracefully, the terminal stays free to enter at commands.
But when I use these components, it hungs on exit again. In the destroyApp function I close CommConnection ,InputStream,OutputStream, but still it won`t help.
The example (that hungs) project is pasted below.
Thank you in advance.
Endre.
**************************************************************
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.CommConnection;
import javax.microedition.io.Connector;
public class HelloWorld3 extends MIDlet {
CommConnection rs232CommConn;
InputStream rs232InStream;
OutputStream rs232OutStream;
public HelloWorld3() {
// Default constructor
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
try {
rs232OutStream.write("destroyApp()".getBytes());
rs232OutStream.close();
rs232InStream.close();
rs232CommConn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();
}
protected void pauseApp() {
// this method is not used in the M2M applications
}
protected void startApp() throws MIDletStateChangeException {
try {
String strCOM = "comm:COM0;baudrate=115200;autocts=off;autorts=off";
rs232CommConn = (CommConnection) Connector.open(strCOM);
rs232InStream = rs232CommConn.openInputStream();
rs232OutStream = rs232CommConn.openOutputStream();
rs232OutStream.write("App started 1!".getBytes());
Thread.sleep(3000);
rs232OutStream.write("App started 2a!".getBytes());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
destroyApp(true);
}
}
Hello,
In the real project you should leave startApp() after initiation but this is just a demo.
Nevertheless I have run your code on my module and everything was fine. ASC0 was accessible for AT commands just after the MIDlet exited.
I understand that your module is rebooted by watchdog which is fine.
And is the ASC0 interface available when the MIDlet is not started? Maybe there is System.out redirected to ASC0 and that 's why it's not available.
Can you paste AT^SCFG? and ATI1 commands outputs?
Regards,
Bartłomiej
Hello,
Thank you for your response and effort to help me. I am sending the AT^SCFG? and ATI1 responses on my module:
https://www.dropbox.com/sh/ywrjdyay3yu3db7/AACcDp4atJMDvrTbep1dTYVRa?dl=0
I shared a txt file, since the spam filter wouldnt accept the post with the response.
Regards,
Endre
Hello,
Here's your output:
AT^SCFG?
^SCFG: "Audio/Loop","0"
^SCFG: "Call/ECC","0"
^SCFG: "Call/Ecall/AckTimeout","5000"
^SCFG: "Call/Ecall/Callback","0"
^SCFG: "Call/Ecall/CallbackTimeout","43200000"
^SCFG: "Call/Ecall/Msd","0000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000"
^SCFG: "Call/Ecall/Pullmode","0"
^SCFG: "Call/Ecall/SessionTimeout","20000"
^SCFG: "Call/Ecall/StartTimeout","5000"
^SCFG: "Call/Speech/Codec","0"
^SCFG: "GPRS/AutoAttach","enabled"
^SCFG: "Gpio/mode/ASC1","gpio"
^SCFG: "Gpio/mode/DAI","gpio"
^SCFG: "Gpio/mode/DCD0","gpio"
^SCFG: "Gpio/mode/DSR0","gpio"
^SCFG: "Gpio/mode/DTR0","gpio"
^SCFG: "Gpio/mode/FSR","gpio"
^SCFG: "Gpio/mode/HSIC","gpio"
^SCFG: "Gpio/mode/PULSE","gpio"
^SCFG: "Gpio/mode/PWM",
^SCFG: "Gpio/mode/RING0","gpio"
^SCFG: "Gpio/mode/SPI","gpio"
^SCFG: "Gpio/mode/SYNC","std"
^SCFG: "Ident/Manufacturer","Cinterion"
^SCFG: "Ident/Product","EHS6"
^SCFG: "MEShutdown/Fso","0"
^SCFG: "MEShutdown/sVsup/threshold","0","0"
^SCFG: "MEopMode/CFUN","0","1"
^SCFG: "MEopMode/Dormancy","0","0"
^SCFG: "MEopMode/SoR","off"
^SCFG: "Radio/Band","511"
^SCFG: "Radio/Mtpl","0"
^SCFG: "Radio/OutputPowerReduction","0"
^SCFG: "Serial/Interface/Allocation","0","0"
^SCFG: "Serial/USB/DDD","0","0","0409","1E2D","0058","Cinterion Wireless Modules","EHx",""
^SCFG: "Tcp/IRT","3"
^SCFG: "Tcp/MR","10"
^SCFG: "Tcp/OT","6000"
^SCFG: "Tcp/WithURCs","on"
^SCFG: "Trace/Syslog/OTAP","0"
^SCFG: "URC/Ringline","local"
^SCFG: "URC/Ringline/ActiveTime","2"
^SCFG: "Userware/Autostart","1"
^SCFG: "Userware/Autostart/Delay","20"
^SCFG: "Userware/DebugInterface","0.0.0.0","0.0.0.0","0"
^SCFG: "Userware/DebugMode","off"
^SCFG: "Userware/Passwd",
^SCFG: "Userware/Stdout","null",,,,"off"
^SCFG: "Userware/Watchdog","1"
ATI1
Cinterion
EHS6
REVISION 03.001
A-REVISION 00.000.31
System.out is off so it's not the problem. As I understand you are not using the terminal (EHS6T). Because for the terminal you should be using hardware flow control and I can see in your code that in Java you set no RTS/CTS flow control. Please also check AT^SPOW output.
I think that you could update your firmware version to the latest one (A-REVISION 00.000.55, which I was also using for my test) and then check again. Your current version is quite old.
Regards,
Bartłomiej
Hello,
My SPOW response:
AT^SPOW?
^SPOW: 1,0,0
I changed autorts=on and autocts=on, and it worked! Tha appleet exits gracefully.
Thank you very much for your support.
Endre