Which port should I open for GSM modem?
I remember someone had posted the port allocation for different device before. Can someone shares that information again?
thanks,
- David :shock:
Code:
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
HANDLE hCom;
char * xpos;
char rsltstr[5];
DWORD CellId;
int bufpos;
DCB dcb;
COMMTIMEOUTS to;
DWORD nWritten;
DWORD event;
DWORD nRead;
static char outbuf[20], buf[256];
BYTE comdevcmd[2]= {0x84, 0x00};
hCom= CreateFile(L"COM2:",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (hCom==NULL || hCom==INVALID_HANDLE_VALUE)
{
hCom= NULL;
return -1;
}
/* HANDLE hRil= CreateFile(L"RIL1:",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (hRil==NULL || hRil==INVALID_HANDLE_VALUE)
{
hRil= NULL;
return -1;
}
*/
if (!GetCommState(hCom, &dcb))
{
return -2;
}
dcb.BaudRate= CBR_115200;
dcb.ByteSize= 8;
dcb.fParity= false;
dcb.StopBits= ONESTOPBIT;
if (!SetCommState(hCom, &dcb))
{
return -3;
}
if (!EscapeCommFunction(hCom, SETDTR))
{
return -4;
}
if (!EscapeCommFunction(hCom, SETRTS))
{
return -5;
}
if (!GetCommTimeouts(hCom, &to))
{
return -6;
}
to.ReadIntervalTimeout= 0;
to.ReadTotalTimeoutConstant= 200;
to.ReadTotalTimeoutMultiplier= 0;
to.WriteTotalTimeoutConstant= 20000;
to.WriteTotalTimeoutMultiplier= 0;
if (!SetCommTimeouts(hCom, &to))
{
return -7;
}
if (!SetCommMask(hCom, EV_RXCHAR))
{
return -8;
}
DWORD rildevresult=0,nReturned=0;
// DeviceIoControl(hRil, 0x03000314L,0,0, &rildevresult, sizeof(DWORD), &nReturned,0);
// HANDLE Ev=CreateEvent(NULL,TRUE,0,L"RILDrv_DataMode");
// SetEvent(Ev);
if (!DeviceIoControl (hCom,0xAAAA5679L, comdevcmd, sizeof(comdevcmd),0,0,0,0))
{
return -9;
}
bufpos = 0;
strcpy(outbuf,"AT+creg=2\r");
if (!WriteFile(hCom, outbuf, 10, &nWritten, NULL))
{
return -10;
}
if (nWritten != 10)
{
return -11;
}
if (!WaitCommEvent(hCom, &event, NULL))
{
return -12;
}
while(1)
{
if (!ReadFile(hCom, buf+bufpos, 256 - bufpos, &nRead, NULL))
{
return -13;
}
if (nRead == 0)
break;
bufpos += nRead;
if (bufpos >= 256)
break;
}
strcpy(outbuf,"AT+creg?\r");
if (!WriteFile(hCom, outbuf, 9, &nWritten, NULL))
{
return -14;
}
if (nWritten != 9)
{
return -15;
}
if (!WaitCommEvent(hCom, &event, NULL))
{
return -16;
}
while(1)
{
if (!ReadFile(hCom, buf+bufpos, 256 - bufpos, &nRead, NULL))
{
return -17;
}
if (nRead == 0)
break;
bufpos += nRead;
if (bufpos >= 256)
break;
}
puts(buf);
rildevresult = 0;
// DeviceIoControl(hRil, 0x03000318L,0,0, &rildevresult, sizeof(DWORD), &nReturned,0);
// ResetEvent(Ev);
// CloseHandle(Ev);
// CloseHandle(hRil);
if (!EscapeCommFunction(hCom, CLRDTR))
{
return -4;
}
if (hCom!=NULL)
{
CloseHandle(hCom);
hCom= NULL;
}
return CellId;
}
the commented lines force RIL to shut up and not send its commands to modem.
To communicate with modem you should open COM2, set 115200/8/N/1, send ioctl 0xAAAA5679.
I had problems when reading data from modem. When it sends a huge block (for example an output to AT%VER command) some bytes are lost and other are changed to garbage. Maybe this is a hardware problem in my imate, because the same program worked on Rover S1 without bugs.
P.S. The code I've posted is taken from this forum.
Post subject: Re: GSM modem port
Thanks for information. I am using iMate too.
Indeed the returned data are very strange. I actually had failure for "EscapeCommFunction(hCom, SETRTS)".
Did you try to dial with a number?
I got "NO CARRIER" while issing a ATD command.
- David
Re: Post subject: Re: GSM modem port
davidchu2000 said:
Did you try to dial with a number?
I got "NO CARRIER" while issing a ATD command.
Click to expand...
Click to collapse
I use TAPI functions to establish a data call. I don't think that you can use COM1 for ATD commands and receive data after connection. Internally COM9 is used after data connection is established. But I've successfully used "ATDnumber;" to make a call. Though it is much easier to use SHMakeCall function.
Hi mamaich,
I have to port a modem application for data transfering.
I can make a call using ATD through com2. Are you saying that I cannot use the same port for data communication?
I have to use COM9 instead?
- David
I don't know. You should test this yourself. For some reason TAPI or RIL opens COM9 after data connection.
Are you able to answer a data call by listening to com2? (or thru TAPI)
- David
I answer call through TAPI without problems. You should kill cprog.exe application on the incoming data call so that it does not popup.
Is anyone experience with pick a call? I can make a call but my program couln't detect an incoming call (when dialing with DATAMODEM using TAPI).
Best regards,
A. Riazi
To receive data call you should terminate cprog.exe. Look into cryptophone source code for more information.
I didn't see any code for terminating cprog.exe, only I saw one line of code to hide "Incoming call..." window. Would you please say in which source of the CryptoPhone, they did this?
Best regards,
A. Riazi
I keep refering back to this topic, wishing I were clever enough to make the XDA modem visable under C# - but I have failed miserably!
Has anybody managed to this, either by talking to COM2: or by using TAPI? All I want is to establish a data call (NOT IP!) for a POS application.
I would worship the ground you walk on if you can help me over my blockage!
Can someone explain how TAPI is implemented to do data calls ??? I am programming in MFC / eVC++ ... Thanks for ur help guys !!!
Which TAPI function do u use to establish a data call ??? is there anywhere i can get the list of all of them ?? cheers guys
Is it possible to programmatically detect when telephone is in use on XDA2, and if so how? Examples using API calls would be great as our app is developed in eVB3 and eVC3.
Thanks
Hi,
You can use the ConnectionManager api and make the connection asyncrous so your main window will be notified with connection events, for example, when the event is received do something like this:
LRESULT DoCommMgrEventMain(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {
DWORD dwStatus;
ConnMgrConnectionStatus(hConnection, &dwStatus);
switch(dwStatus) {
case CONNMGR_STATUS_UNKNOWN:
Log(SEVERIDAD_INFO, TEXT("Unknown"));
break;
case CONNMGR_STATUS_CONNECTED:
Log(SEVERIDAD_INFO, TEXT("Connected."));
break;
case CONNMGR_STATUS_DISCONNECTED:
Log(SEVERIDAD_INFO, TEXT("Disconnected"));
break;
case CONNMGR_STATUS_CONNECTIONFAILED:
Log(SEVERIDAD_INFO, TEXT("Connection has failed and cannot be reestablished"));
break;
case CONNMGR_STATUS_CONNECTIONCANCELED:
Log(SEVERIDAD_INFO, TEXT("User-aborted connection"));
break;
case CONNMGR_STATUS_CONNECTIONDISABLED:
Log(SEVERIDAD_INFO, TEXT("Connection is ready to connect but disabled"));
break;
case CONNMGR_STATUS_NOPATHTODESTINATION:
Log(SEVERIDAD_INFO, TEXT("No path could be found to the destination"));
break;
case CONNMGR_STATUS_WAITINGFORPATH:
Log(SEVERIDAD_INFO, TEXT("Waiting for a path to the destination"));
break;
case CONNMGR_STATUS_WAITINGFORPHONE:
Log(SEVERIDAD_INFO, TEXT("Voice call is in progress"));
break;
case CONNMGR_STATUS_WAITINGCONNECTION:
Log(SEVERIDAD_INFO, TEXT("Attempting to connect"));
break;
case CONNMGR_STATUS_WAITINGFORRESOURCE:
Log(SEVERIDAD_INFO, TEXT("Resource is in use by another connection"));
break;
case CONNMGR_STATUS_WAITINGFORNETWORK:
Log(SEVERIDAD_INFO, TEXT("No path to the destination could be found"));
break;
case CONNMGR_STATUS_WAITINGDISCONNECTION:
Log(SEVERIDAD_INFO, TEXT("Connection is being brought down"));
break;
case CONNMGR_STATUS_WAITINGCONNECTIONABORT:
Log(SEVERIDAD_INFO, TEXT("Aborting connection attempt"));
break;
}
if ((dwStatus == CONNMGR_STATUS_CONNECTIONFAILED) ||
(dwStatus == CONNMGR_STATUS_CONNECTIONCANCELED) ||
(dwStatus == CONNMGR_STATUS_DISCONNECTED)){
if (bDesconectar != TRUE) {
Sleep(10000);
DoMainCommandConnect(hWnd, wMsg, wParam, lParam);
}
else {
bDesconectar = FALSE;
}
}
else {
if (dwStatus == CONNMGR_STATUS_WAITINGFORPHONE) {
// ops llamada telefonica.
// Aqui deberiamos dar por terminada la conexion con el servidor
}
}
return 0;
}
Using connection manager I can now get a gprs connection and perform xmlhttp transfers. While this is in progress the calls to the API function ConnMgrConnectionStatus return CONNMGR_STATUS_CONNECTED. However, if I make a telephone call to the XDA and monitor the ConnMgrConnectionStatus, it returns CONNMGR_STATUS_DISCONNECTED rather than CONNMGR_STATUS_WAITINGFORPHONE which I would have expected. Once the phone call is ended ConnMgrConnectionStatus returns CONNMGR_STATUS_CONNECTED once again.
Any ideas as to what is happening?
Thanks.
Some source code from Ateksoft!
http://www.ateksoft.com/dev/flashlight.htm
My experiments with extra brightness on the Magician have shown that MS saves this state somewhere else. If you don't change this place as well the real place (GPIO) is reset every 5 seconds or so.
Damn, my current Opera installation adds this to every post:
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #ffffcc; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }
Hey,
I recently bought a TyTN, and was wondering.. is it possible to change the mac address on it (not physically, but in wm5)?
I know it can be done in windows 2k/xp, and I've read about others doing it in VM2003.. Haven't been able to figure anything out on VM5 tho.
Anyone who might be able to help out there?
Ps. The reasons for switching the mac address, if anyone is concerned, is that it's easier to switch it, rather then having to go around contacting the administrators of the 5 networks I use during a standard month and having it added everywhere... Might have to do it, but dont want to if it can be avoided
Guess it's not possible
Well... under Windows XP it's doable with a registry entry... so why not under WinCE?
Again, this is due to Opera:
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #ffffcc; background-image: none; color: #000000; font-family: Verdana, "Lucida Grande", Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }
That's what I thought.. but unless the key is not supposed to be called "NetworkdAddress", I can't seem to figure it out :/
Tried it in every possible place I could think of placing the key in the registry without any changes (did a soft-reset after each try, hopefully enough)
Could someone name me the various types of video encoding/resolution type available for encoding/resolution video recording purposes in android? Like mp4, etc...
Now that i think of it is it possible for me to retrieve my phone's camera resolution for user to use for preferences purposes? Does it have to do with flatten something thingy, i'm not quite sure what its called..
If so how should i retrieve a particular phone's resolution for ListPreference?? Can someone guide me on this?
This is the java file that performs the recording process
Code:
public class ServiceRecording extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
private SurfaceView surfaceView;
private SurfaceHolder surfaceHolder;
public static Camera ServiceCamera;
public static boolean recordingStatus;
@Override
public void onCreate() {
super.onCreate();
recordingStatus = false;
ServiceCamera = CameraTest.MainCamera;
surfaceView = CameraTest.surfaceView;
surfaceHolder = CameraTest.surfaceHolder;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
if (recordingStatus == false)
startRecording();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
stopRecording();
//camera.stopPreview();
recordingStatus = false;
//camera.release();
}
private MediaRecorder mediaRecorder;
private final int maxDurationInMs = 20000;
private static final String TAG = "Exception";
public boolean startRecording(){
try {
Toast.makeText(getBaseContext(), "Recording Started", Toast.LENGTH_SHORT).show();
try{
ServiceCamera.reconnect();
ServiceCamera.unlock();
}
catch(Exception e){
}
mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(ServiceCamera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mediaRecorder.setMaxDuration(maxDurationInMs);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
//mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH_mm_ss");
Date date = new Date();
File dirlist = new File(Environment.getExternalStorageDirectory() + "/VideoList");
if(!(dirlist.exists()))
dirlist.mkdir();
File TempFile = new File(Environment.getExternalStorageDirectory() + "/VideoList", dateFormat.format(date) + ".3gp");
mediaRecorder.setOutputFile(TempFile.getPath());
mediaRecorder.setVideoSize(surfaceView.getWidth(),surfaceView.getHeight());
//mediaRecorder.setVideoFrameRate(videoFramesPerSecond);
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.prepare();
mediaRecorder.start();
recordingStatus = true;
return true;
}
catch (IllegalStateException e) {
Log.d(TAG,e.getMessage());
e.printStackTrace();
return false;
}
catch (IOException e) {
Log.d(TAG,e.getMessage());
e.printStackTrace();
return false;
}
}
public void stopRecording() {
Toast.makeText(getBaseContext(), "Recording Stopped", Toast.LENGTH_SHORT).show();
mediaRecorder.reset();
mediaRecorder.release();
recordingStatus = false;
}
}
My Tab1Activity.java file which initialized the preference but how am i going to allow the storage of user data for configuring the camera setting
Code:
[CODE]public class Tab1Activity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.tab1);
}
}
[/CODE]
This is the xml file which uses preferences but i'm kinna face with the problem on how am i going to retrieve the available phone resolution to allow the user to configure at the ListPreference area..
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Video">
<CheckBoxPreference
android:title="Audio"
android:defaultValue="True"
android:summary="Select w/o Audio"
android:key="AudioPref" />
<ListPreference
android:title="Video Encoder"
android:summary="Select the video encoding type"
android:key="EncodingPref"
android:defaultValue="3gp"
android:entries="@array/EncodingType"
android:entryValues="@array/updateEncodingType" />
<ListPreference
android:title="Video Resolution"
android:summary="Select the video resolution"
android:key="ResolutionPref"
android:defaultValue="1"
android:entries="@array/VideoResolution"
android:entryValues="@array/updateVideoResolution" />
</PreferenceCategory>
</PreferenceScreen>
Could someone guide me along this??
I'm not really sure what you're asking, nor what the code you've displayed has to do with it.
Have you checked out the CamcorderProfile class?
http://developer.android.com/reference/android/media/CamcorderProfile.html
Q1. What are the available different forms of video encoding type available in android for user to choose from? Because i'm currently doing a video recording app which i wanted to use ListPreference to allow user to dynamically choose what type of encoding is available.
Q2. I wanted to know is there any easy way to retrieve video resolution on the actual phone? Because different phone has different phone resolution's compatibility, so i wanted to retrieve the resolution data and display the different resolutions dynamically into my ListPreference for user selection... Does it have to do with a method name "flatten()" i don't quite know what is the method... I'm kinna new in java/android, can someone guide me on how should i do that?
My mainActivity.java file
Code:
public class CameraTest extends Activity implements SurfaceHolder.Callback {
private static final String TAG = "Exception";
public static SurfaceView surfaceView;
public static SurfaceHolder surfaceHolder;
public static Camera MainCamera;
private static boolean previewRunning;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
surfaceView = (SurfaceView)findViewById(R.id.surface_camera);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
//getparameters
Button btnStart = (Button) findViewById(R.id.button4);
btnStart.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
startService(new Intent(getApplicationContext(), ServiceRecording.class));
}
});
Button btnStop = (Button) findViewById(R.id.button5);
btnStop.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
stopService(new Intent(getApplicationContext(), ServiceRecording.class));
}
});
Button btnSetting = (Button) findViewById(R.id.button2);
btnSetting.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(getApplicationContext(), SettingActivity.class));
}
});
}
public static boolean ServiceStatus;
@Override
public void surfaceCreated(SurfaceHolder holder) {
if(ServiceRecording.recordingStatus)
{
stopService(new Intent(getApplicationContext(), ServiceRecording.class));
try {
Thread.sleep(4000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
MainCamera = ServiceRecording.ServiceCamera;
startService(new Intent(getApplicationContext(), ServiceRecording.class));
}
else{
MainCamera = Camera.open();
if (MainCamera != null) {
Camera.Parameters params = MainCamera.getParameters();
params.setPreviewSize(320, 240);
params.setPreviewFormat(PixelFormat.JPEG);
MainCamera.setParameters(params);
try {
MainCamera.setPreviewDisplay(holder);
}
catch (IOException e)
{
e.printStackTrace();
}
MainCamera.startPreview();
previewRunning = true;
}
else {
Toast.makeText(getApplicationContext(), "Camera not available!", Toast.LENGTH_LONG).show();
finish();
}
}
if (previewRunning) {
MainCamera.stopPreview();
}
/*ServiceStatus = ServiceRecording.recordingStatus;
if(ServiceStatus == true)
{
stopService(new Intent(getApplicationContext(), ServiceRecording.class));
if (MainCamera != null) {
Camera.Parameters params = MainCamera.getParameters();
MainCamera.setParameters(params);
MainCamera.startPreview();
}
}*/
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder){
MainCamera.stopPreview();
previewRunning = false;
MainCamera.release();
}
}
My Preference.xml file
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Video">
<CheckBoxPreference
android:title="Audio"
android:defaultValue="True"
android:summary="Select w/o Audio"
android:key="AudioPref" />
<ListPreference
android:title="Video Encoder"
android:defaultValue="3gp"
android:summary="Select a video encoding type"
android:key="EncodingPref"
android:entries="@array/EncodingType"
android:entryValues="@array/updateEncodingType"
android:dialogTitle="Video Encoding Formats" />
<ListPreference
android:title="Video Resolution"
android:defaultValue="1"
android:summary="Select the video resolution"
android:key="ResolutionPref"
android:entries="@array/VideoResolution"
android:entryValues="@array/updateVideoResolution"
android:dialogTitle="Video Resolution" />
</PreferenceCategory>
</PreferenceScreen>
Can someone guide on how am i going to obtain my dynamic video resolution for every single phone instead of using the hard-coding xml method into my ListPreferenes??