#include "stdafx.h"
|
#include "CMaster.h"
|
|
namespace SERVO {
|
CMaster* g_pMaster = NULL;
|
void CALLBACK MasterTimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
|
{
|
if (g_pMaster != NULL) {
|
g_pMaster->onTimer(nTimerid);
|
}
|
}
|
|
CMaster::CMaster()
|
{
|
|
}
|
|
CMaster::~CMaster()
|
{
|
for (auto item : m_listEquipment) {
|
delete item;
|
}
|
m_listEquipment.clear();
|
}
|
|
int CMaster::init()
|
{
|
LOGI("<Master>ÕýÔÚ³õʼ»¯...");
|
|
|
// cclink
|
if (m_cclink.Connect(CC_LINK_IE_CONTROL_CHANNEL(1)) != 0) {
|
LOGE("Á¬½ÓCC-Linkʧ°Ü.");
|
return -1;
|
}
|
else {
|
LOGI("Á¬½ÓCC-Link³É¹¦.");
|
BoardVersion version{};
|
int nRet = m_cclink.GetBoardVersion(version);
|
if (nRet == 0) {
|
LOGI("°æ±¾ÐÅÏ¢£º%s.", version.toString().c_str());
|
}
|
else {
|
LOGE("»ñÈ¡CC-Link°æ±¾ÐÅϢʧ°Ü.");
|
}
|
|
BoardStatus status;
|
nRet = m_cclink.GetBoardStatus(status);
|
if (nRet == 0) {
|
LOGI("״̬£º%s.", status.toString().c_str());
|
}
|
else {
|
LOGE("»ñÈ¡CC-Link״̬ʧ°Ü.");
|
}
|
}
|
|
|
// ³õʼ»¯Ìí¼Ó¸÷×ÓÉ豸
|
{
|
CEFEM* pEquipment = new CEFEM();
|
pEquipment->setName("EFEM(ROBOT)");
|
pEquipment->setDescription("EFEM(ROBOT).");
|
pEquipment->setReadBitBlock(0x4000, 0x45ff);
|
pEquipment->setStation(1, 2);
|
addEquipment(pEquipment);
|
LOGE("ÒÑÌí¼Ó¡°EFEM(ROBOT)¡±.");
|
}
|
/*
|
{
|
CBonder* pBonder = new CBonder();
|
pBonder->setName("Bonder 1");
|
pBonder->setDescription("Bonder 1.");
|
pBonder->setReadBitBlock(0x4600, 0x4bff);
|
pBonder->setStation(1, 3);
|
addEquipment(pBonder);
|
LOGE("ÒÑÌí¼Ó¡°Bonder 1¡±.");
|
}
|
*/
|
|
// ¶¨Ê±Æ÷
|
g_pMaster = this;
|
SetTimer(NULL, 1, 250, (TIMERPROC)MasterTimerProc);
|
|
|
LOGI("<Master>³õʼ»¯Íê³É.");
|
return 0;
|
}
|
|
int CMaster::term()
|
{
|
return 0;
|
}
|
|
int CMaster::addEquipment(CEquipment* pEquipment)
|
{
|
m_listEquipment.push_back(pEquipment);
|
return 0;
|
}
|
|
void CMaster::onTimer(UINT nTimerid)
|
{
|
for (auto item : m_listEquipment) {
|
item->onTimer(nTimerid);
|
}
|
|
|
// ÒÔÏÂΪ²âÊÔ´úÂë
|
static int i = 0;
|
i++;
|
if (i % (4 * 1) == 0) {
|
|
for (auto item : m_listEquipment) {
|
const StationIdentifier& station = item->getStation();
|
MemoryBlock& block = item->getReadBitBlock();
|
|
char szBuffer[1024];
|
int nRet = m_cclink.ReadData2(station, (short)block.type,
|
block.start, block.size, szBuffer);
|
for (unsigned int i = 0; i < block.size; i++) {
|
if(szBuffer[i] != 0)
|
TRACE("%d[%x]\n", i, szBuffer[i]);
|
}
|
TRACE("nRet=%d\n", nRet);
|
}
|
}
|
}
|
}
|