110,535
社区成员
发帖
与我相关
我的任务
分享
/*
原型 : int start_transmit(float rate, int frame, int DeviceId)
功能 :
发送卡准备发送和设置参数。
在多次transmit()调用的第一次之前调用一次。
参数 :
rate 发送卡输出信号的速率,bps为单位
frame 发送卡输出TS流的包长度,188或204
DeviceId 发送卡编号,0开始
返回值:
0表示成功, 负数表示失败
*/
int start_transmit(float rate, int frame, int DeviceId);
/*
原型 : int transmit(void* pBuffer,int nLength,int DeviceId)
功能 :
发送卡发送数据.可以反复多次调用,建议nLength取值在20K到2M之间
参数 :
pBuffer 待发送数据缓冲区的指针;
nLength 要发送的长度,字节单位,建议取值在20480到204800之间.
DeviceId 发送卡编号,0开始.
返回值:
实际发送的数据长度,字节单位
负数表示操作出错
*/
int transmit(void* pBuffer,int nLength, int DeviceId);
/*
原型 : int flush(int DeviceId)
功能 :
强制刷新输出缓冲区,建议在单次发送文件数据全部完成时调用
参数 :
DeviceId 发送卡编号,0开始
返回值:
实际发送的数据长度,字节单位
负数表示操作出错
*/
int flush(int DeviceId);
/*
原型 : int stop_transmit(int DeviceId)
功能 :
发送卡结束发送。
在多次bst_transmit()的最后一次之后调用一次。
参数 :
DeviceId 发送卡编号,0开始
返回值:
0表示成功, 负数表示失败
*/
stop_transmit(int DeviceId);
[DllImport("dll的名字.dll")]
public static extern Init16 transmit(IntPtr pBuffer, Int16 nLength, Int16 deviceID);
string a = "hello" ;
IntPtr pBuffer = System.Runtime.InteropServices.Marshal.StringToCoTaskMemAuto(a);
transmit(pBuffer,a.Length, 0);
string a = "hello";
int MAXLENGTH = 188;
byte[] source = Encoding.ASCII.GetBytes(a);
int totalSend = 0;
while (true)
{
byte[] buff = new byte[MAXLENGTH];
buff[0] = 0x40;
int left = source.Length - totalSend;
if (left > MAXLENGTH - 1)
{
Array.Copy(source, totalSend, buff, 1, MAXLENGTH - 1);
totalSend += MAXLENGTH - 1;
transmit(buff, MAXLENGTH, 0);
}
else
{
Array.Copy(source, totalSend, buff, 1, left);
transmit(buff, MAXLENGTH, 0);
break;
}
}
string a = "hello" ;
byte[] buff = new byte[188];
byte[0] = 0x40;
//然后再把a放到buff 这个字节数组里面发送出去 请问这该如何让实现
并且此时
IntPtr pBuffer = System.Runtime.InteropServices.Marshal.StringToCoTaskMemAuto(a);
//还能用么