fixed bc mode v2
This commit is contained in:
79
bcmil.cpp
79
bcmil.cpp
@@ -1,18 +1,17 @@
|
||||
#include <QDebug>
|
||||
#include "bcmil.h"
|
||||
#include "WDMTMKv2.cpp"
|
||||
//#include <windows.h>
|
||||
|
||||
//TTmkEventData tmkEvD;
|
||||
HANDLE hBcEvent;
|
||||
//HANDLE hRtEvent;
|
||||
TTmkEventData tmkEvD;
|
||||
HANDLE hEvent;
|
||||
|
||||
int nTmk;
|
||||
unsigned long dwGoodStarts = 0, dwBusyStarts = 0, dwErrStarts = 0, dwStatStarts = 0;
|
||||
unsigned long dwStarts = 0L;
|
||||
TMK_DATA wSubAddr, wState, wStatus;
|
||||
|
||||
MIL::MIL(int dev_index) //open the driver, configuration, create event
|
||||
//Open the driver, configuration, create event
|
||||
MIL::MIL(int dev_index)
|
||||
{
|
||||
qDebug() << "MIL constructor";
|
||||
if (TmkOpen())
|
||||
@@ -39,6 +38,15 @@ MIL::MIL(int dev_index) //open the driver, configuration, create event
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (!hEvent)
|
||||
{
|
||||
qDebug() << "CreateEvent() error";
|
||||
closeAllrt();
|
||||
}
|
||||
ResetEvent(hEvent);
|
||||
tmkdefevent(hEvent, TRUE);
|
||||
}
|
||||
|
||||
/*int MIL::WaitInt(TMK_DATA wCtrlCode)
|
||||
@@ -96,7 +104,7 @@ MIL::MIL(int dev_index) //open the driver, configuration, create event
|
||||
//printf("\nGood: %ld, Busy: %ld, Error: %ld, Status: %ld\n", dwGoodStarts, dwBusyStarts, dwErrStarts, dwStatStarts);
|
||||
bcreset();
|
||||
//Close all opened things
|
||||
CloseHandle(hBcEvent);
|
||||
CloseHandle(hEvent);
|
||||
tmkdone(ALL_TMKS);
|
||||
TmkClose();
|
||||
}*/
|
||||
@@ -104,14 +112,41 @@ MIL::MIL(int dev_index) //open the driver, configuration, create event
|
||||
void MIL::closeAllrt()
|
||||
{
|
||||
qDebug() << "Close All";
|
||||
//printf("\nGood: %ld, Busy: %ld, Error: %ld, Status: %ld\n", dwGoodStarts, dwBusyStarts, dwErrStarts, dwStatStarts);
|
||||
rtreset();
|
||||
//Close all opened things
|
||||
CloseHandle(hBcEvent);
|
||||
CloseHandle(hEvent);
|
||||
tmkdone(ALL_TMKS);
|
||||
TmkClose();
|
||||
}
|
||||
|
||||
bool MIL::GetEvent(unsigned short Timeout)
|
||||
{
|
||||
if (tmkselect(this->m_TmkIndex))
|
||||
{
|
||||
qDebug() << "tmkselect() error";
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (WaitForSingleObject(hEvent, Timeout))
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
qDebug() << "Interrupt";
|
||||
ResetEvent(hEvent);
|
||||
tmkgetevd(&tmkEvD);
|
||||
return true;
|
||||
break;
|
||||
|
||||
case WAIT_TIMEOUT:
|
||||
//qDebug() << "No new messages";
|
||||
return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
qDebug() << "Interrupt wait error";
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MIL::~MIL()
|
||||
{
|
||||
qDebug() << "MIL destructor";
|
||||
@@ -147,44 +182,26 @@ RT_MIL::RT_MIL(int dev_index, unsigned short Addr): MIL(dev_index)
|
||||
qDebug() << "RT_MIL constructor";
|
||||
this->m_Addr = Addr;
|
||||
|
||||
//Find first configured device
|
||||
for (nTmk = 0; nTmk <= MAX_TMK_NUMBER; ++nTmk)
|
||||
if (!tmkselect(nTmk))
|
||||
break;
|
||||
if (nTmk > MAX_TMK_NUMBER)
|
||||
{
|
||||
qDebug() << "tmkselect error";
|
||||
closeAllrt();
|
||||
}
|
||||
//Try to reset in RT mode
|
||||
if (rtreset())
|
||||
{
|
||||
qDebug() << "rtreset error";
|
||||
qDebug() << "rtreset() error";
|
||||
closeAllrt();
|
||||
}
|
||||
|
||||
//Set RT address, set flag mode, enable data irqs
|
||||
rtdefaddress(Addr);
|
||||
rtdefmode(rtgetmode()|RT_FLAG_MODE);
|
||||
//rtdefmode(rtgetmode()&~RT_FLAG_MODE);
|
||||
rtdefmode(0);
|
||||
rtdefirqmode(rtgetirqmode()&~RT_DATA_BL);
|
||||
|
||||
//Ready to receive, not ready to transmit
|
||||
for (wSubAddr = 1; wSubAddr <= 30; ++wSubAddr)
|
||||
{
|
||||
//Ready to receive, not ready to transmit
|
||||
rtdefsubaddr(RT_RECEIVE, wSubAddr);
|
||||
rtclrflag();
|
||||
rtdefsubaddr(RT_TRANSMIT, wSubAddr);
|
||||
rtclrflag();
|
||||
}
|
||||
|
||||
hBcEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (!hBcEvent)
|
||||
{
|
||||
qDebug() << "create event error";
|
||||
closeAllrt();
|
||||
}
|
||||
ResetEvent(hBcEvent);
|
||||
tmkdefevent(hBcEvent, TRUE);
|
||||
}
|
||||
|
||||
RT_MIL::~RT_MIL()
|
||||
|
Reference in New Issue
Block a user