我试图创建将调用一个远程调制解调器,并做一些数据传输(在字节数组的形式自定义数据)的应用程序。
我使用JulMar的ITapi3包装和C#4.0的Windows 7 64位操作系统上运行(编译为86)。
我的应用已经使得手机通话和断开如我所料,但我有麻烦居然穿越线路发送数据。 目前,我有在CallStateChanged事件下面的代码呼叫状态连接时
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);
try
{
//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.
Thread.Sleep(10);
}
//now we are done with sending login message
_dataTransferOutFileStream.EndWrite(result);
//wait 5 seconds
Thread.Sleep(5000);
//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)
{
Thread.Sleep(10);
}
//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)
{
Debug.WriteLine(ex.ToString());
return false;
}
finally
{
commHandle.Close();
}
return true;
这似乎并没有被实际发送的数据或从远程站点recieving任何有效数据。 有什么我失踪? 有没有一种方法来检查正在使用的SafeFileHandle是否实际上是对调制解调器的端口的参考?
我试图使用.NET内建SerialPort类,我连接,但是我得到一个错误,在该端口是由另一个进程使用后(我假设TAPI上有一个锁。)
我向所有人开放的建议。