ITAPI3发送和接收数据 [英] ITAPI3 Sending and Receiving Data
问题描述
所以我试图创建一个应用程序将调用一个远程调制解调器,并做一些数据传输(自定义数据的字节数组的形式)。
So I am attempting to create an application that will call a remote modem and do some data transfer (custom data in the form of byte arrays).
我使用JulMar的ITapi3包装和C#4.0上运行的Windows 7 64位操作系统(编译为86)。
I am using JulMar's ITapi3 wrapper and c# 4.0 running on Windows 7 64Bit OS (Compiling as x86).
我的应用已经使得手机通话和断开如我所料,但我无法真正跨线发送数据。目前我有以下的code在CallStateChanged事件时,呼叫状态连接
I have the application making the phone call and disconnecting as I expect but I am having trouble actually sending data across the line. currently I have the following code in the CallStateChanged event when the call state is connected
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实际上是一个参考调制解调器的端口?
This doesn't seem to be actually sending the data or recieving any valid data from the remote site. Is there something I am missing? Is there a way to check whether the SafeFileHandle being used is actually a reference to the modem's port?
我尝试使用内置的SerialPort类的。NET我连接后,但我得到一个错误的端口的问题是由另一个进程使用(我假设TAPI上有一个锁。)
I tried using the builtin SerialPort class for .NET after I am connected but I get an error that the port in question is in use by another process (I am assuming TAPI has a lock on it.)
我向所有人开放的建议。
I am open to all suggestions.
感谢你在前进。
推荐答案
好吧,我想出什么问题了。显然,我的格式,我发送到远程调制解调器和错误,而不是远程站点,告诉我,这是只是完全忽略我的信息数据。
Ok I figured out what the issue was. Apparently I was formatting the data I was sending to the remote modem incorrectly and rather than the remote site telling me that it was simply ignoring my message altogether.
所以,code以上会为发送和C#异步接收通过调制解调器线数据。
So the code above will work for sending and receiving data asynchronously over a modem line in C#.
这篇关于ITAPI3发送和接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!