リモートモデムを呼び出してデータ転送(バイト配列の形式のカスタムデータ)を実行するアプリケーションを作成しようとしています。
私はJulMarのITapi3ラッパーとWindows764ビットOS(x86としてコンパイル)で実行されているc#4.0を使用しています。
アプリケーションが期待どおりに電話をかけたり切断したりしていますが、実際に回線を介してデータを送信するのに問題があります。現在、コール状態が接続されているときの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;
これは、実際にデータを送信したり、リモートサイトから有効なデータを受信したりしているようには見えません。足りないものはありますか?使用されているSafeFileHandleが実際にモデムのポートへの参照であるかどうかを確認する方法はありますか?
接続後に.NET用の組み込みSerialPortクラスを使用しようとしましたが、問題のポートが別のプロセスで使用されているというエラーが表示されます(TAPIがロックされていると想定しています)。
私はすべての提案を受け入れます。