USB-2066数据采集卡,用自带的程序能够正常读取到数据,而我自己用它给的ReadAD()函数也能成功运行,但是读上来的数据全是32767(换算下就是0),这是为什么啊?代码基本一致,设置也没差,我2个程序同时运行,自带的程序读取的数据是正常的,而我的依旧是32767。
就是这个函数:
USB2066__ReadAD(hDevice, inBuffer, samcnt);
hDevice是设备编号,samcnt是采样数,inBuffer是数据存储数组,3个都没问题,函数也正常运行了,就是读上来的数据不对。自带的代码这段函数前后都没有其他任何东西,就单纯这个函数,我断点进去看,函数运行完,inBuffer里面就有正常的数据,而我的函数进去看就全是32767.
自带程序代码截取部分(C++语言写的):
typedef struct _USB2066_PARA_INIT
{
LONG lADFreq; //采样率
LONG TriggerMode; //触发模式
LONG TriggerSource; //触发源
LONG TriggerDelay; //触发延时
LONG TriggerLength; //触发长度
LONG TriggerLevel; //模拟触发电平
LONG lEnCh[8]; //通道使能
} USB2066_PARA_INIT,*PUSB2066_PARA_INIT;
main()里面:
hDevice = USB2066_Link(0);//连接采集卡
USB2066_PARA_INIT para_init;//初始化数组
赋值部分就不贴上了,都一样的。
USB2066_InitAD(hDevice,¶_init)//初始化
PUSHORT inBuffer = NULL;
ULONG status=FALSE;
inBuffer = new USHORT[samcnt];
USB2066_ReadAD(hDevice,inBuffer,samcnt);
我的代码(C# 写的)
[DllImport("USB2066.dll", SetLastError = true, EntryPoint = "USB2066_Link")]
public static extern IntPtr USB2066_Link(uint i);
[DllImport("USB2066.dll", SetLastError = true, EntryPoint = "USB2066_InitAD")]
public static extern bool USB2066_InitAD(IntPtr hDevice, IntPtr para_init);
[DllImport("USB2066.dll", SetLastError = true, EntryPoint = "USB2066_ReadAD")]
public static extern bool USB2066_ReadAD(IntPtr hDevice, ushort[] inBuffer, uint nCount);
public struct _USB2066_PARA_INIT
{
public int lADFreq; //采样率
public int TriggerMode; //触发模式
public int TriggerSource; //触发源
public int TriggerDelay; //触发延时
public int TriggerLength; //触发长度
public int TriggerLevel; //模拟触发电平
public int[] lEnCh;
}
main()里面:
hDevice = USB2066_Link(0);
_USB2066_PARA_INIT para_init = new _USB2066_PARA_INIT
{
lADFreq = 1000000, //采样率
TriggerMode = 0,
TriggerSource = 0,
TriggerDelay = 0, //触发延时,仅延时触发有效,以基准时钟为单位
TriggerLength = 6912,//6912, //触发长度
TriggerLevel = 2457,//触发电平
lEnCh = new int[8]
};
para_init.lEnCh[0] = 1;
int psize = Marshal.SizeOf(para_init);
IntPtr ptrIn = Marshal.AllocHGlobal(psize);
Marshal.StructureToPtr(para_init, ptrIn, true);
USB2066_InitAD(hDevice, ptrIn)
ushort[] inBuffer = new ushort[samcnt];
USB2066_ReadAD(hDevice, inBuffer, samcnt);
求救!!!