1、头文件、lib(静态链接库)、dll(动态链接库)文件添加,环境配置
①头文件:可以使用直接添加现有项,也可以在设置里面配置环境(因为在这里只有一个头文件和lib文件所以就直接使用添加现有项了)(后来发现安装的USB5538文件里面,有dll文件)
②lib文件直接就放在项目的当前目录下面,这个板卡是没dll文件的(好像其余的都是不需要dll文件的)(后来发现安装的USB5538文件里面,有dll文件)
③代码:编写包含头文件、使用lib文件
#include "USB5538.h"
#pragma comment(lib,"USB5538_32.lib")
2、代码:板卡初始化
①头文件中:设置:板卡初始化函数、设置句柄(否则我使用这个函数的时候,许多的对话框的数据成员、成员函数无法调用)(注意是bool类型的)
bool InitUSB5538();//绑卡初始化
1、问题:InitUSB5538初始化板卡是不能写在头文件中,否则会报错的,不知道为什么
答:
①因为你的写错了,调用这个类里面的成员函数看,需要添加这个类名
②源文件中:初始化中开启板卡初始化函数,并且是写在最下面,return前面
InitUSB5538();
③全局变量句柄,写在函数的上面;
HANDLE hDevice;
④全局变量:输入输出
BYTE bDISts[16];
BYTE bDOSts[16];
⑤板卡初始化函数:实现
①一定要先创建板卡
bool CMy01_MFCAndFlashDlg::InitUSB5538()
{
hDevice=USB5538_CreateDevice();//创建板卡设备
if(hDevice==INVALID_HANDLE_VALUE)//板卡无效值
{
AfxMessageBox(L"小伙子你的板卡呢?");
return false;
}
else
{
//设置输出
for (int i=0;i<16;i++)
{
bDOSts[i]=0;
}
USB5538_SetDeviceDO(hDevice,bDOSts);
return true;
}
}
3、代码:线程里面不断的得到板卡输入信号然后处理按键事件
①每一次while循环都得到里面的设备输入信号
USB5538_GetDeviceDI(hDevice,bDISts);//每一次while循环都得到里面的设备输入信号
②板卡信号的自我循环:然后获得输入信号下面写上如果输入是开的时候进行处理(注意在这里需要注意,按钮是否是常按,所以要进行之前输入状态的变量,先写上之前输入状态的全局变量)
正确的:
1、制作3个通道号
int inputChannel0;
int inputChannel1;
int inputChannel2;
2、读取通道号
a=FastReadIniValue("../Debug/Resource/Config/config.ini","InputChannels","inputChannel0",&inputChannel0,1);
if (a<0)
AfxMessageBox(L"inputChannel读取失败");
a=FastReadIniValue("../Debug/Resource/Config/config.ini","InputChannels","inputChannel1",&inputChannel1,1);
if (a<0)
AfxMessageBox(L"inputChannel读取失败");
a=FastReadIniValue("../Debug/Resource/Config/config.ini","InputChannels","inputChannel2",&inputChannel2,1);
if (a<0)
AfxMessageBox(L"inputChannel读取失败");
void ThreadFunction(void *pd)
{
CMy01_MFCAndFlashDlg *pThis=(CMy01_MFCAndFlashDlg*)pd;
m_run=true;
while (m_run==true)
{
if(FastVlcGetState(pVlc)==6)//播放视频回到待机
{
//FastVlcStop(pVlc);
dlg->MoveWindow(0,0,0,0);
FastVlcPlay(pVlc,0);
FastVlcStop(pVlc);
}
USB5538_GetDeviceDI(hDevice,bDISts);//每一次while循环都得到里面的设备输入信号
if(bDISts[inputChannel0]==inputOpen&&b_lastDISts[inputChannel0]!=inputOpen)
{
if(FastVlcGetState(pVlc)==3||FastVlcGetState(pVlc)==5)
{
dlg->MoveWindow(Dlg02_xLeft,Dlg02_yTop,Dlg02_xRight,Dlg02_yBottom);
FastVlcPlay(pVlc,0);
b_lastDISts[inputChannel0]=bDISts[inputChannel0];
}
}
else
{
b_lastDISts[inputChannel0]=bDISts[inputChannel0];
}
if(bDISts[inputChannel1]==inputOpen&&b_lastDISts[inputChannel1]!=inputOpen)
{
if(FastVlcGetState(pVlc)==3||FastVlcGetState(pVlc)==5)
{
dlg->MoveWindow(Dlg02_xLeft,Dlg02_yTop,Dlg02_xRight,Dlg02_yBottom);
FastVlcPlay(pVlc,1);
b_lastDISts[inputChannel1]=bDISts[inputChannel1];
}
}
else
{
b_lastDISts[inputChannel1]=bDISts[inputChannel1];
}
if(bDISts[inputChannel2]==inputOpen&&b_lastDISts[inputChannel2]!=inputOpen)
{
if(FastVlcGetState(pVlc)==3||FastVlcGetState(pVlc)==5)
{
dlg->MoveWindow(Dlg02_xLeft,Dlg02_yTop,Dlg02_xRight,Dlg02_yBottom);
FastVlcPlay(pVlc,2);
b_lastDISts[inputChannel2]=bDISts[inputChannel2];
}
}
else
{
b_lastDISts[inputChannel2]=bDISts[inputChannel2];
}
}
}
失误的:
BYTE b_lastDOSts[16];
BYTE b_lastDISts[16];
if(bDISts[0]==inputOpen&&b_lastDISts[0]!=inputOpen)
{
if(FastVlcGetState(pVlc)==3||FastVlcGetState(pVlc)==5)
{
dlg->MoveWindow(Dlg02_xLeft,Dlg02_yTop,Dlg02_xRight,Dlg02_yBottom);
FastVlcPlay(pVlc,0);
b_lastDISts[0]=bDISts[0];
}
}
else
{
b_lastDISts[0]=bDISts[0];
}
4、摧毁
①使用memset,里面的输出输入关闭或者开始都是从配置文件中进行读取的,目的是现场接线的话,不一定会接的正确的
memset(bDOSts,outputClose ,16);
memset(bDISts,inputClose,16);
memset(b_lastDISts,inputClose,16);
USB5538_SetDeviceDO(hDevice,bDOSts);