|
|
#include "card.h"
|
|
|
#include "axis.h"
|
|
|
#include "log.h"
|
|
|
|
|
|
using std::pair;
|
|
|
|
|
|
CardService* CardService:: m_pInstance = NULL;
|
|
|
CardService* CardService::GetInstance()
|
|
|
{
|
|
|
if (!m_pInstance) m_pInstance = new CardService();
|
|
|
return m_pInstance;
|
|
|
}
|
|
|
|
|
|
void CardService::ReleaseInstance()
|
|
|
{
|
|
|
FREE_ANY(m_pInstance);
|
|
|
}
|
|
|
|
|
|
CardService::CardService(void)
|
|
|
{
|
|
|
for(ushort i = 0; i < MAXCARD; i++)
|
|
|
{
|
|
|
m_pCard[i] = new CCard(i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
CardService::~CardService(void)
|
|
|
{
|
|
|
for(int i = 0; i < MAXCARD; i++)
|
|
|
{
|
|
|
FREE_ANY(m_pCard[i]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int CardService::OpenCard(ushort cardIndex)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_INPUT_PARAM);
|
|
|
return m_pCard[cardIndex]->Open();
|
|
|
}
|
|
|
|
|
|
int CardService::CloseCard(ushort cardIndex)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_INPUT_PARAM);
|
|
|
return m_pCard[cardIndex]->Close();
|
|
|
}
|
|
|
|
|
|
int CardService::GetStatus(ushort cardIndex)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, EDev_NOINIT);
|
|
|
return m_pCard[cardIndex]->_bOpened ? EDev_IDLE : EDev_NOINIT;
|
|
|
}
|
|
|
|
|
|
int CardService::AxisReset(ushort cardIndex, ushort axisIndex)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisReset(axisIndex);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisZeroPos(ushort cardIndex, ushort axisIndex)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisZeroPos(axisIndex);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisIsMoving(ushort cardIndex, ushort axisIndex)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, 0);
|
|
|
return m_pCard[cardIndex]->AxisIsMoving(axisIndex);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisStop(ushort cardIndex, ushort axisIndex, int stopType)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisStop(axisIndex, stopType);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisSetSpeed(ushort cardIndex, ushort axisIndex, double vel)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisSetSpeed(axisIndex, vel);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisGetPos(ushort cardIndex, ushort axisIndex, EMPosType postype, double* pval)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisGetPos(axisIndex, postype, pval);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisSetPos(ushort cardIndex, ushort axisIndex, long pos)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisSetPos(axisIndex, pos);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisHome(ushort cardIndex, ushort axisIndex, ushort homeType, long pos, long offset, double vel)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisHome(axisIndex, homeType, pos, offset, vel);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisMoveJog(ushort cardIndex, ushort axisIndex, int dir, double vel, double acc, double dec)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisMoveJog(axisIndex, dir, vel, acc, dec);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisMovePos(ushort cardIndex, ushort axisIndex, long pos, double vel, double acc, double dec)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisMovePos(axisIndex, pos, vel, acc, dec);
|
|
|
}
|
|
|
|
|
|
int CardService::AxisMoveOffset(ushort cardIndex, ushort axisIndex, long offset, double vel, double acc, double dec)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->AxisMoveOffset(axisIndex, offset, vel, acc, dec);
|
|
|
}
|
|
|
|
|
|
int CardService::ReadBit(ushort cardIndex, ushort in_index, short di_type)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, 0);
|
|
|
return m_pCard[cardIndex]->ReadBit(in_index, (EIOType)di_type);
|
|
|
}
|
|
|
|
|
|
int CardService::ReadOutBit(ushort cardIndex, ushort out_index, short do_type)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, 0);
|
|
|
return m_pCard[cardIndex]->ReadBit(out_index, (EIOType)do_type);
|
|
|
}
|
|
|
|
|
|
int CardService::WriteOutBit(ushort cardIndex, ushort out_index, ushort val, short do_type)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->WriteOutBit(out_index, val, (EIOType)do_type);
|
|
|
}
|
|
|
|
|
|
int CardService::ReadAdc(ushort cardIndex, ushort index, double* pval)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->ReadADC(index, pval);
|
|
|
}
|
|
|
|
|
|
int CardService::WriteAdc(ushort cardIndex, ushort index, double val)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->WriteADC(index, val);
|
|
|
}
|
|
|
|
|
|
int CardService::CreateCrd(ushort cardIndex, ushort *pAxisIndex, ushort axisCnt)
|
|
|
{
|
|
|
int ret = 0;
|
|
|
int index = 0;
|
|
|
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
|
|
|
ret = m_pCard[cardIndex]->CreateCrd(pAxisIndex, axisCnt, index);
|
|
|
|
|
|
RETURN_CHK_NOPRT(!ret, ret);
|
|
|
|
|
|
return cardIndex * MAXCRD + index; //ÿ<>ſ<EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
|
|
}
|
|
|
|
|
|
int CardService::AddLinePos(int crdID, double *ppos, ushort nsize, double vel, double acc, double endvel)
|
|
|
{
|
|
|
int index = 0;
|
|
|
ushort cardIndex = 0;
|
|
|
|
|
|
index = ConvertcrdIndex(cardIndex, crdID);
|
|
|
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_INPUT_PARAM);
|
|
|
|
|
|
return m_pCard[cardIndex]->AddLinePos(index, ppos, vel, acc, endvel);
|
|
|
}
|
|
|
|
|
|
int CardService::AddArcPos(int crdID, double *ppos1, double *ppos2, double *ppos3, ushort nsize, double vel, double acc, double endvel)
|
|
|
{
|
|
|
int index = 0;
|
|
|
ushort cardIndex = 0;
|
|
|
|
|
|
index = ConvertcrdIndex(cardIndex, crdID);
|
|
|
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_INPUT_PARAM);
|
|
|
|
|
|
return m_pCard[cardIndex]->AddArcPos(index, ppos1, ppos2, ppos3, vel, acc, endvel);
|
|
|
}
|
|
|
|
|
|
int CardService::CrdStartMove(int crdID)
|
|
|
{
|
|
|
int index = 0;
|
|
|
ushort cardIndex = 0;
|
|
|
|
|
|
index = ConvertcrdIndex(cardIndex, crdID);
|
|
|
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_INPUT_PARAM);
|
|
|
|
|
|
return m_pCard[cardIndex]->CrdStartMove(index);
|
|
|
}
|
|
|
|
|
|
int CardService::CrdStatus(int crdID, int *progress)
|
|
|
{
|
|
|
int index = 0;
|
|
|
ushort cardIndex = 0;
|
|
|
|
|
|
index = ConvertcrdIndex(cardIndex, crdID);
|
|
|
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, 0);
|
|
|
|
|
|
return m_pCard[cardIndex]->CrdStatus(index, progress);
|
|
|
}
|
|
|
|
|
|
int CardService::CloseCrd(int crdID)
|
|
|
{
|
|
|
int index = 0;
|
|
|
ushort cardIndex = 0;
|
|
|
|
|
|
index = ConvertcrdIndex(cardIndex, crdID);
|
|
|
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_INPUT_PARAM);
|
|
|
|
|
|
return m_pCard[cardIndex]->CloseCrd(index);
|
|
|
}
|
|
|
|
|
|
int CardService::SendCustomCommand(ushort cardIndex, const char* msg, char* res/* = 0*/)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->SendCustomCommand(msg, res);
|
|
|
}
|
|
|
|
|
|
int CardService::RecvCustomCommand(ushort cardIndex, const char* msg, char* res/* = 0*/, int timeout/* = 0*/)
|
|
|
{
|
|
|
RETURN_CHK_NOPRT(cardIndex < MAXCARD, ERR_NO_INIT);
|
|
|
return m_pCard[cardIndex]->RecvCustomCommand(msg, res, timeout);
|
|
|
}
|
|
|
|
|
|
const char* _pszcmddesc =
|
|
|
"<EFBFBD≯߿<EFBFBD><EFBFBD>ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>.\n"
|
|
|
"*PS: <20>ֶ<EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD>˷ָ<CBB7><D6B8><EFBFBD>','<27><><EFBFBD>ⲻ<EFBFBD><E2B2BB><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>Ŀո<C4BF>.\n"
|
|
|
"reset <20><><EFBFBD><EFBFBD>״̬\n"
|
|
|
"pause <20><>ͣ\n"
|
|
|
"continue <20><>ͣ<EFBFBD>ָ<EFBFBD>\n"
|
|
|
"backlash axis,offset <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>,axis<69><73>ʾ<EFBFBD><CABE><EFBFBD>Ŵ<EFBFBD>0<EFBFBD><30>ʼ;offset<65><74>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,Ϊ0ʱ<30><CAB1>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>,<2C><>λ:<3A><><EFBFBD><EFBFBD>\n"
|
|
|
"arrive axis,bon <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>鵽λ<E9B5BD>ź<EFBFBD>.axis<69><73>ʾ<EFBFBD><CABE><EFBFBD>Ŵ<EFBFBD>0<EFBFBD><30>ʼ;bonΪ1<CEAA><31>ʾ<EFBFBD><CABE><EFBFBD>飬<EFBFBD><E9A3AC><EFBFBD><EFBFBD><F2B2BBBC><EFBFBD>\n"
|
|
|
"writeda index,val <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ͨ<EFBFBD><CDA8><EFBFBD>ĵ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>ֵ. index<65><78>ʾͨ<CABE><CDA8><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ;val<61><6C>ʾ<EFBFBD><CABE>ѹֵ(С<><D0A1>)\n"
|
|
|
;
|
|
|
|
|
|
int CardService::GetCommandDesc(char* pszcmddesc)
|
|
|
{
|
|
|
int len = (int)strlen(_pszcmddesc);
|
|
|
|
|
|
if (!pszcmddesc) return len;
|
|
|
|
|
|
comm_strcpy(pszcmddesc, _pszcmddesc);
|
|
|
return len;
|
|
|
}
|