通过以太网接口实现数据采集
9v~24v直流电源接通电源
剩下根据产品使用手册查看各个接口,包括模拟量输入输出、数字量输入输出、计数器等功能。根据需要连接接口,注意接入电压值范围。
安装提供的软件,在安装目录下包含了帮助文档和测试示例。安装目录
使用板子提供的API,通过qt开发,Qt5.5 mingw 32
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/bin/ -lUSB5630E
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/bin/ -lUSB5630E
INCLUDEPATH += $$PWD/bin
DEPENDPATH += $$PWD/bin
AD模拟量输入实现代码:
USB5630E_AI_PARAM AIParam;
U32 nReadSampsPerChan = 0, nSampsPerChanRead = 0;
F64 fTimeout = 1.0; // 10秒钟超时
U32 nReadableSamps = 0;
HANDLE hDevice = INVALID_HANDLE_VALUE;
U16 nBinArray[USB5630E_AI_MAX_CHANNELS];
// 第一步 创建设备对象
hDevice = USB5630E_DEV_Create("192.168.1.4");
if(hDevice == INVALID_HANDLE_VALUE)
{
qDebug() << "DEV_Create Error";
return 0;
}
USB5630E_PORT_PARAM PortParam;
memset(&PortParam, 0, sizeof(PortParam));
for (int nIdx=0; nIdx<8; nIdx++) // 端口0
{
PortParam.CHParam[0].nFunction[nIdx] = USB5630E_PORT_FUN_DIO; // 端口0只能为DIO
PortParam.CHParam[0].nDIODir[nIdx] = USB5630E_PORT_DIR_DI; // 置为DI输入
PortParam.CHParam[0].nDIOVal[nIdx] = 0; // nDIODir为输出时有效
}
for (int nIdx=0; nIdx<8; nIdx++) // 端口1(PFI0~7)
{
PortParam.CHParam[1].nFunction[nIdx] = USB5630E_PORT_FUN_CTR; // 端口1设为CTR功能
}
for (int nIdx=0; nIdx<4; nIdx++) // 端口2(PFI8~15)
{
PortParam.CHParam[2].nFunction[nIdx*2] = USB5630E_PORT_FUN_PFIIN;// 端口2(0 2 4 6设为PFI输入)
PortParam.CHParam[2].nFunction[nIdx*2+1] = USB5630E_PORT_FUN_PFIOUT;// 端口2(1 3 5 7设为PFI输出)
}
if (!USB5630E_Port_Config(hDevice, &PortParam))
{
qDebug() << "Port_Config Error,请参考sys.log";
USB5630E_DEV_Release(hDevice);
return 0;
}
memset(&AIParam, 0, sizeof(USB5630E_AI_PARAM));
// 通道参数
AIParam.nSampChanCount = 64; //64通道全打开
for(int nChannel=0; nChannellineEdit_AI1->setText(QString::number(v1, 'f', 2)+"V");
ui->lineEdit_AI2->setText(QString::number(v2, 'f', 2)+"V");
// 第六步 停止AI采样
if(!USB5630E_AI_StopTask(hDevice))
{
qDebug() << "AI_StopTask Error\n" ;
}
// 第七步 释放AI采集任务
if(!USB5630E_AI_ReleaseTask(hDevice))
{
qDebug() << "AI_ReleaseTask Error\n" ;
}
// 第八步 释放设备对象
if(!USB5630E_DEV_Release(hDevice))
{
qDebug() << "DEV_Release Error\n" ;
}
return 0;
DA模拟量输出实现代码:
USB5630E_AO_PARAM AOParam;
U32 nWriteSampsPerChan = 0, nSampsPerChanWritten = 0;
U32 nAvailSampsPerChan = 0;
U16 nBinArray[USB5630E_AO_MAX_CHANNELS];
double fTimeout = 10.0;
HANDLE hDevice = INVALID_HANDLE_VALUE;
// 第一步 创建设备对象
hDevice = USB5630E_DEV_CreateA("192.168.1.4");
if(hDevice == INVALID_HANDLE_VALUE)
{
qDebug() << "DEV_Create Error";
return 0;
}
USB5630E_PORT_PARAM PortParam;
memset(&PortParam, 0, sizeof(PortParam));
for (int nIdx=0; nIdx<8; nIdx++) // 端口0
{
PortParam.CHParam[0].nFunction[nIdx] = USB5630E_PORT_FUN_DIO; // 端口0只能为DIO
PortParam.CHParam[0].nDIODir[nIdx] = USB5630E_PORT_DIR_DI; // 置为DI输入
PortParam.CHParam[0].nDIOVal[nIdx] = 0; // nDIODir为输出时有效
}
for (int nIdx=0; nIdx<8; nIdx++) // 端口1(PFI0~7)
{
PortParam.CHParam[1].nFunction[nIdx] = USB5630E_PORT_FUN_CTR; // 端口1设为CTR功能
}
for (int nIdx=0; nIdx<4; nIdx++) // 端口2(PFI8~15)
{
PortParam.CHParam[2].nFunction[nIdx*2] = USB5630E_PORT_FUN_PFIIN;// 端口2(0 2 4 6设为PFI输入)
PortParam.CHParam[2].nFunction[nIdx*2+1] = USB5630E_PORT_FUN_PFIOUT;// 端口2(1 3 5 7设为PFI输出)
}
if (!USB5630E_Port_Config(hDevice, &PortParam))
{
qDebug() << "Port_Config Error,请参考sys.log";
USB5630E_DEV_Release(hDevice);
return 0;
}
memset(&AOParam, 0, sizeof(USB5630E_AO_PARAM));
// 通道参数
for(int nChannel=0; nChannellineEdit_AO0->setText(QString::number(v0, 'f', 2)+"V");
ui->lineEdit_AO1->setText(QString::number(v1, 'f', 2)+"V");
ui->lineEdit_AO2->setText(QString::number(v2, 'f', 2)+"V");
ui->lineEdit_AO3->setText(QString::number(v2, 'f', 2)+"V");
// 第三步:往生成任务中写入二进制原码波形数据
nWriteSampsPerChan = 1;
if(!USB5630E_AO_WriteBinary(hDevice, nBinArray, nWriteSampsPerChan, &nSampsPerChanWritten, &nAvailSampsPerChan, fTimeout))
{
qDebug() << "AO_WriteBinary Error...\n";
}
memset(nBinArray, 0, sizeof(nBinArray));
// 第四步 停止AO生成任务
if(!USB5630E_AO_StopTask(hDevice))
{
qDebug() << "AO_StopTask Error\n";
}
// 第五步 释放AO生成任务
if(!USB5630E_AO_ReleaseTask(hDevice))
{
qDebug() << "AO_ReleaseTask Error\n";
}
// 第六步 释放设备对象
if(!USB5630E_DEV_Release(hDevice))
{
qDebug() << "DEV_Release Error\n";
}
return 0;
DO数字信号量输出实现代码:
U32 nPort = 0, nPortData = 0;
HANDLE hDevice = INVALID_HANDLE_VALUE;
// 第一步 创建设备对象
hDevice = USB5630E_DEV_CreateA("192.168.1.4");
if(hDevice == INVALID_HANDLE_VALUE)
{
qDebug() << "DEV_Create Error\n";
return 0;
}
USB5630E_PORT_PARAM PortParam;
memset(&PortParam, 0, sizeof(PortParam));
for (int nIdx=0; nIdx<8; nIdx++) // 端口0
{
PortParam.CHParam[0].nFunction[nIdx] = USB5630E_PORT_FUN_DIO; // 端口0只能为DIO
PortParam.CHParam[0].nDIODir[nIdx] = USB5630E_PORT_DIR_DO; // 置为DO
PortParam.CHParam[0].nDIOVal[nIdx] = 0; // nDIODir为输出时有效
}
for (int nIdx=0; nIdx<8; nIdx++) // 端口1(PFI0~7)
{
PortParam.CHParam[1].nFunction[nIdx] = USB5630E_PORT_FUN_DIO; // 端口0只能为DIO
PortParam.CHParam[1].nDIODir[nIdx] = USB5630E_PORT_DIR_DO; // 置为DO
PortParam.CHParam[1].nDIOVal[nIdx] = 0; // nDIODir为输出时有效
}
for (int nIdx=0; nIdx<8; nIdx++) // 端口2(PFI8~15)
{
PortParam.CHParam[2].nFunction[nIdx] = USB5630E_PORT_FUN_DIO; // 端口0只能为DIO
PortParam.CHParam[2].nDIODir[nIdx] = USB5630E_PORT_DIR_DO; // 置为DO
PortParam.CHParam[2].nDIOVal[nIdx] = 0; // nDIODir为输出时有效
}
if (!USB5630E_Port_Config(hDevice, &PortParam))
{
qDebug() << "Port_Config Error,请参考sys.log";
USB5630E_DEV_Release(hDevice);
return 0;
}
// 第三步(1):写DIO端口,置数量字输出状态
nPortData = 127; //0111 1111
nPortData = 64; //0100 0000
nPort = 0;
if(!USB5630E_DIO_WritePort(hDevice, nPort, nPortData))
{
qDebug() << "DIO_WritePort Error";
}
nPortData = 0;
if(!USB5630E_DIO_ReadPort(hDevice, nPort, &nPortData))
{
qDebug() << "USB5630E_DO_ReadPort Error";
}
qDebug() << "Read back DO Port0 Data = " << nPortData;
nPortData = 2; //0000 0010
nPort = 1;
if(!USB5630E_DIO_WritePort(hDevice, nPort, nPortData))
{
qDebug() << "DIO_WritePort Error";
}
nPortData = 0;
if(!USB5630E_DIO_ReadPort(hDevice, nPort, &nPortData))
{
qDebug() << "USB5630E_DO_ReadPort Error";
}
qDebug() << "Read back DO Port1 Data = " << nPortData;
// 第四步 释放设备对象
if(!USB5630E_DEV_Release(hDevice))
{
qDebug() << "DEV_Release Error\n";
}
return 0;