| | |
| | | |
| | | namespace SERVO { |
| | | CMaster* g_pMaster = NULL; |
| | | |
| | | unsigned __stdcall ReadBitsThreadFunction(LPVOID lpParam) |
| | | { |
| | | if (g_pMaster != NULL) { |
| | | return g_pMaster->ReadBitsProc(); |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | void CALLBACK MasterTimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime) |
| | | { |
| | | if (g_pMaster != NULL) { |
| | |
| | | { |
| | | m_listener = {nullptr, nullptr, nullptr}; |
| | | m_bDataModify = FALSE; |
| | | m_hEventReadBitsThreadExit[0] = ::CreateEvent(NULL, TRUE, FALSE, NULL); |
| | | m_hEventReadBitsThreadExit[1] = ::CreateEvent(NULL, TRUE, FALSE, NULL); |
| | | m_hReadBitsThreadHandle = nullptr; |
| | | m_nReadBitsThreadAddr = 0; |
| | | } |
| | | |
| | | CMaster::~CMaster() |
| | |
| | | delete item; |
| | | } |
| | | m_listEquipment.clear(); |
| | | |
| | | if (m_hEventReadBitsThreadExit[0] != nullptr) { |
| | | ::CloseHandle(m_hEventReadBitsThreadExit[0]); |
| | | m_hEventReadBitsThreadExit[0] = nullptr; |
| | | } |
| | | |
| | | if (m_hEventReadBitsThreadExit[1] != nullptr) { |
| | | ::CloseHandle(m_hEventReadBitsThreadExit[1]); |
| | | m_hEventReadBitsThreadExit[1] = nullptr; |
| | | } |
| | | } |
| | | |
| | | void CMaster::setListener(MasterListener listener) |
| | |
| | | SetTimer(NULL, 1, 250, (TIMERPROC)MasterTimerProc); |
| | | |
| | | |
| | | m_hReadBitsThreadHandle = (HANDLE)_beginthreadex(NULL, 0, SERVO::ReadBitsThreadFunction, this, |
| | | 0, &m_nReadBitsThreadAddr); |
| | | |
| | | |
| | | LOGI("<Master>初始化完成."); |
| | | return 0; |
| | | } |
| | | |
| | | int CMaster::term() |
| | | { |
| | | SetEvent(m_hEventReadBitsThreadExit[0]); |
| | | ::WaitForSingleObject(m_hEventReadBitsThreadExit[1], INFINITE); |
| | | |
| | | LOGI("<Master>正在结束程序."); |
| | | for (auto item : m_listEquipment) { |
| | | item->term(); |
| | |
| | | saveCache(); |
| | | |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | unsigned CMaster::ReadBitsProc() |
| | | { |
| | | while (1) { |
| | | // 待退出信号或时间到 |
| | | int nRet = ::WaitForSingleObject(m_hEventReadBitsThreadExit[0], 1000); |
| | | if (nRet == WAIT_OBJECT_0) { |
| | | break; |
| | | } |
| | | |
| | | for (auto item : m_listEquipment) { |
| | | if (item->getID() == EQ_ID_Bonder1) { |
| | | const StationIdentifier& station = item->getStation(); |
| | | MemoryBlock& block = item->getReadBitBlock(); |
| | | |
| | | int nRet = m_cclink.ReadData2(station, (DeviceType)block.type, |
| | | block.start, block.size, block.buffer); |
| | | if (0 == nRet) { |
| | | item->onReceiveLBData(block.buffer, block.size); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | SetEvent(m_hEventReadBitsThreadExit[1]); |
| | | |
| | | |
| | | // _endthreadex(0); |
| | | TRACE("CMaster::ReadBitsProc 线程退出\n"); |
| | | return 0; |
| | | } |
| | | |
| | |
| | | pEquipment->setID(EQ_ID_Bonder1 + index); |
| | | pEquipment->setName(index == 0 ? "Bonder 1" : "Bonder 2"); |
| | | pEquipment->setDescription(index == 0 ? "Bonder 1." : "Bonder 2."); |
| | | pEquipment->setStation(1, index == 0 ? 3 : 4); |
| | | // pEquipment->setStation(1, index == 0 ? 3 : 4); |
| | | pEquipment->setStation(0, 255); |
| | | pEquipment->setReadBitBlock(index == 0 ? 0x4600 : 0x4c00, |
| | | index == 0 ? 0x4c00 : 0x5200); |
| | | addToEquipmentList(pEquipment); |
| | |
| | | // 按一定频率扫描LB数据 |
| | | static int i = 0; |
| | | i++; |
| | | /* |
| | | if (i % (4 * 1) == 0) { |
| | | |
| | | for (auto item : m_listEquipment) { |
| | | const StationIdentifier& station = item->getStation(); |
| | | MemoryBlock& block = item->getReadBitBlock(); |
| | | if (item->getID() == EQ_ID_Bonder1) { |
| | | const StationIdentifier& station = item->getStation(); |
| | | MemoryBlock& block = item->getReadBitBlock(); |
| | | |
| | | int nRet = m_cclink.ReadData2(station, (DeviceType)block.type, |
| | | block.start, block.size, block.buffer); |
| | | if (0 == nRet) { |
| | | item->onReceiveLBData(block.buffer, block.size); |
| | | int nRet = m_cclink.ReadData2(station, (DeviceType)block.type, |
| | | block.start, block.size, block.buffer); |
| | | if (0 == nRet) { |
| | | item->onReceiveLBData(block.buffer, block.size); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | |
| | | |
| | | // 自动保存缓存 |