我正在嘗試創建一個應用程序,它將調用遠程調制解調器並執行一些數據傳輸(字節數組形式的自定義數據)。ITAPI3發送和接收數據
我正在使用JulMar的ITapi3包裝器和在Windows 7 64位操作系統上運行的c#4.0(編譯爲x86)。
我有應用程序打電話和斷開,因爲我期望,但我實際上發送數據跨越線路麻煩。目前,我有在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是否實際上是對調制解調器端口的引用?
我嘗試使用內置SerialPort類的.NET我連接,但是我得到一個錯誤,在該端口是由另一個進程使用(我假設TAPI上有一個鎖。)
後我接受所有建議。
還是沒有答案?我現在正在以某種方式查看從已建立的調用創建的SerialPort對象。我可以獲取Comm端口名稱並創建SerialPort對象,但當我嘗試打開它時,它當然是關閉的。當然,我得到一個錯誤,它被另一個進程TAPI使用。 – Chris 2011-06-17 15:34:57