How to Send and Recieve data

Jun 13, 2011 at 3:06 PM

So I am having trouble with something that I am sure is extremely basic and I shouldn't be struggling with.


I am trying to send and recieve data once my call is connected.  I have been trying to simply modify the existing Outgoing call sample provided in the ITapi3 samples projects.  I can't seem to get any sort of terminal to actually be created.  I constantly get a null pointer when calling requestterminal () on the call object.  I have tried several different types of Media and Several different directions for requesting the terminal to no avail.  I have also tried using GetID on the TCall object but I don't know what to do after that....

I just want send and recieve some byte arrays for data to the remote modem. 


Please help.

Jun 14, 2011 at 3:34 PM

Ok so I have done some more "fiddling" with things and I think I have gotten farther but I still don't think it is working.

I am using the outgoingSample project provided and I have added some code to the callstate event

on connected I call SendDataByFileStream which looks like the following.

  var handleArray = callForData.GetID("comm/datamodem");

            var byteContents = BitConverter.ToInt64(handleArray, 0);
            ////temporary Handle array
            IntPtr myPointer =new IntPtr(byteContents);

            ////var pinnedArray = GCHandle.Alloc(handleArray, GCHandleType.Pinned);
            ////var pointer = pinnedArray.AddrOfPinnedObject();
            var commHandle = new SafeFileHandle(myPointer, true);
               //now init filestream
                _dataTransferOutFileStream = new FileStream(commHandle, FileAccess.ReadWrite, 2048, true);

                //start by writing the login message to the modem
                var buffer = CreatePasswordMessage();
           IAsyncResult result= _dataTransferOutFileStream.BeginWrite(buffer, 0, buffer.Length,null,null);

            while (!result.IsCompleted)
                //wait for completion of sending login message.

                //now we are done with sending login message 

                //wait 5 seconds 
                //do the same type of thing for the read or whether it was sucessful.
            var readBuffer = new byte[2048];
            IAsyncResult readResult = _dataTransferOutFileStream.BeginRead(readBuffer, 0, 2048,null,null);
            while (!readResult.IsCompleted)

                //read is complete.

           int readCount = _dataTransferOutFileStream.EndRead(readResult);

                Debug.WriteLine("Read Complete Count of Bytes Read: {0} Content of First Byte: {1} ",new object[]{readCount,readBuffer[0]});

            catch (Exception ex)
                return false;


            return true;

The code executes successfully but I expect some data to be retrieved from the remote modem but I am getting 0 for the first byte (it shouldn't be 0).

Please help.

Apr 6, 2013 at 11:37 AM
I tried your code but also nothing is received at the remote modem, did you find the problem ?
I think to make my work on AT commands, may be it will be better since i will not need the TAPI library.
Apr 6, 2013 at 12:30 PM
My issue ended up being the format of the message I was sending was incorrect. We were using a proprietay messaging format and the devices I was connecting to were not responding unless I formatted the message correctly. To the best of my memory the code above should work.

What specifically are you trying to accomplish?
Apr 8, 2013 at 8:00 AM
Thank you Chris.

I want to send / Receive data between 2 PCs using two modems.
First steps (dial, answer ) using Julmar.ITapi3 succeeded but sending data by writing on the filestream retrieved from address handle does not success. I create a thread for reading data and it does not succeed , and the event CallMedia does not fire, do you suggest any method to do it.

Thank you in advance.

Apr 8, 2013 at 3:08 PM
I would suggest looking at the traffic going on the modem on both machines (or at least the machines you have access to). HHD Software has a Device Monitoring Studio that will allow you monitor the traffic on modems which may be helpful to see if there is any data being sent. I assume you have created both the answering client and the dialing client and are controlling the data passed between them. If so try just sending a simple string like Hello World and have the answering client not require any sort of special message format, or authentication or any sort, and output the message it receives.

If you want to provide some code I can look at it for any glaring issues, or gotchas that I encountered that I am not remembering off hand.
Apr 9, 2013 at 8:08 AM
Thank you Chris for your answer,
I fix the problem, I'm trying send small message like "Hello world" but it was not received until i minimized the size of filestream.
So thank you for all your suggestion.