Archive for February, 2008

As I’m sure you know, various Siemens modems modules are programmable in Java. Some time ago I wrote several posts about programming these modems. I specifically wrote an example, which was posted in instalments, where I used an MTX65+G as a base (remember it’s a GPRS terminal modem with integrated GPS) and where we saw how to develop a small GPS locator. Among other things the application basically consisted of a modem receiving a specific SMS message and returning another SMS with the GPS position.

That was an example based on SMS, but maybe at some point we need to store information within the device itself.

Gestión de ficheros modems Siemens


Why would I want to store information in the modem if I can send it via GPRS or SMS?

Imagine if you collect the GPS position every ten seconds. You can send the position to a remote server in real time via GPRS, but you may not need to send the real-time position in all situations (which is definitely cheaper). There may be situations where you want to be able to control the position at all times, but in others you simply want to collect positions to deal with them or send them later on.

This is if we are talking about GPS modems like the XT65 or the MTX65+G. But it also makes sense if we are talking about the TC65 (and the TC65T and MTX65) as they have digital inputs, analog inputs and various types of buses (SPI, I2C, RS232 etc.). They are also often used for collecting information from devices or external sensors like temperature/flow/pressure sensors and they can collect information from PLCs. You can also send information immediately after receiving it (whether it interests us or not), or at the end of the day or whenever we want.

Can I not store information in the RAM memory? 

Well yes, you can do that. But it’s as if you are working with Word and you don’t save anything for days. You have it stored in the RAM memory but if something unexpected happens like a power failure or a problem with the application, you could lose the information. Not to mention that the data saved in the RAM can’t be very big.

So how can I store information? 

Well you do it in the same way as you save your program’s Java files in the modem’s FLASH memory. You can create files from your Java application to save, add and read information when you need to.

The following is a small fragment of a Java code so that you can see how to save and read information using files that are stored in the device’s Flash memory.

//Let’s create a FileConnection class object and specify
//the name of the file to open, we will put file.txt
FileConnection objFileConnection = (FileConnection)“file:///a:/file.txt”);

//If the file doesn’t exist we send it to create it
if (!objFileConnection.exists())

//We create a DataOutputStream class object
//in order to write data in the file
DataOutputStream objDataOutputStream =

//Let’s write a text in the file that we have just opened
//(or created)
objDataOutputStream.write(“Hello from blogElectronica”.getBytes());

//We send everythin in the previous buffer in order to close it.

//We close the object

//Now we read the data. We create a DataInputStream class object
DataInputStream objDataInputStream =

//We create an array to store the data from the read file.
//We will do it from the file’s data size because
//we know there’s not much
byte[] data = new byte[objDataInputStream.available()];

//If there is data, which in our case there will be…
if (objDataInputStream.available() > -1)
//We read and save all of the file’s data
//in the array that we have created, 0, objDataInputStream.available());

//We remove it via the console to see it
System.out.println(new String(data));

//Close the objects

catch (IOException ioe)

By the way don’t forget to do the following imports at the beginning of the program.

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import java.util.Enumeration;

All of the above applies to Siemens modems TC65, TC65T, XT65, MTX65 and MTX65+G, distributed by  Matrix in Spain.

I hope that you have found this post interesting and useful. See you next time ;)  

Comments 28 Comments »