views:

851

answers:

3

For some reasons I need to be able to access the internal modem of a Windows Mobile smartphone (a HTC s740 with WM version 6.1). What I want is to be able to access it like it was a serial port in order to give AT-commands.

I have code that uses the TAPI Line interface and lineGetID() to get a "handle" on which I shuld be able to do ReadFile()/WriteFile(). Sadly I have not gotten it to work.

What I do currently is:

  1. Initialize TAPI with lineInitializeEx()

  2. Open the Line with lineOpen()

  3. Iterate through each available device and get info. Currently I am selecting the "UNIMODEM"/"Hayes compatible on COM1" device. But maybe I should choose the "TAPI cellular service"/"Cellular Line" instead? I have tried the "Cellular Line" device with the same result.

  4. Use lineGetID() on the selected device to get a handle.

  5. Do WriteFile("AT\r") and then directly do a ReadFile(), which should give me a "OK" back if it really was the modem I accessed.

  6. Realize that it doesn't work and get annoyed...

But this has so far been a no-go.

Does anyone have any idea on how to do it?

I am doing this in Native WIN32 C++ on Windows Mobile 6 SDK.

UPDATE: I have so far managed to get a data connection between two phones using RIL, which gives me a serial port handle to write and read from. BUT, I still would like to be able to interact directly with the modem to send AT-commands. So, the bounty I am starting only concerns getting direct access to the modem in order to give AT-commands. My investigations so far indicates that this was possible in previous versions of Windows Mobile (by opening COM2 and/or COM9 and slaying RIL, or something like that) but I have not yet seen code which works on WM6.

A: 

I'm not sure that you can use handle from lineGetID with WriteFile/ReadFile functions. These are low-level functions that (probably) can't be used with TAPI.

I would try to open COM port with CreateFile, get the handle and then use WriteFile and ReadFile functions. There is an old classic article in MSDN (Serial Communications in Win32), which describes this technique.

However, I'm not experienced with Windows Mobile programming, so I'm not sure that it will work for you.

Wacek
lineGetID() returns a handle. What should I do with it if not read and write to it?Using CreateFile would be awesome, but then I need to be sure that every Windows Mobile device in the world uses the same COM-port for its modem.
kigurai
From MSDN page about lineGetID: "The lineGetID function returns a device identifier for the specified device class associated with the selected line, address, or call". For me, it doesn't look like a handle. Speaking about modem port - you must find the proper one. I would try to call CreateFile (with OPEN_EXISTING flag) on any COM-port starting from COM1. If it opens, send "AT" and wait for an answer. If it comes you're home, if not try the next port.Maybe this link (http://forum.sysinternals.com/forum_posts.asp?TID=4544) will help you.
Wacek
It is definately possible to get a handle for the open port as described here: http://msdn.microsoft.com/en-us/library/ms734853(VS.85).aspx
kigurai
A: 

Hi Kigurai,

I have a similar need for this functionality with my htc touch HD. If you nut this problem out would you be able to let me know how to do this. It would be much appreciated.

justinvk
Sorry, still no luck, and I have left the problem behind me. I solved it by writing my own AT command parser that used the available API's for telephony to do their work.
kigurai
+1  A: 

You probably can't do this. The interface to the radio isn't necessarily a COM port - the AT commands are often emulated. Even if you could get a handle to the COM port, how would you synchronize with the activity that the built in connection manager is performing.

Stewart