You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
6.5 KiB
C++
226 lines
6.5 KiB
C++
// motor_gugao.cpp : 定义 DLL 应用程序的导出函数。
|
|
//
|
|
#include "dev.h"
|
|
#include "log.h"
|
|
#include "CardService.h"
|
|
|
|
#pragma comment(lib, "log.lib")
|
|
#pragma comment(lib, "config.lib")
|
|
#pragma comment(lib, "sysapi.lib")
|
|
|
|
bool g_bInit = false;
|
|
EXPORT_C void WINAPI init()
|
|
{
|
|
ZERO_CHK(!g_bInit);
|
|
g_bInit = true;
|
|
ins->Init();
|
|
}
|
|
|
|
EXPORT_C void WINAPI deinit()
|
|
{
|
|
ZERO_CHK(g_bInit);
|
|
g_bInit = false;
|
|
CardService::ReleaseInstance();
|
|
}
|
|
|
|
EXPORT_C int WINAPI get_dev_info(TDevInfo* pDev)
|
|
{
|
|
const char* sz_desc[] = {"捕获回原", "伺服捕获回原", "普通回原", "index回原"};
|
|
|
|
RETURN_CHK_NOPRT(pDev, ERR_INPUT_PARAM);
|
|
|
|
memset(pDev, 0, sizeof(TDevInfo));
|
|
strcpy(pDev->id, "GTS");
|
|
strcpy(pDev->desc, "固高8轴控制卡");
|
|
pDev->axisCnt = MAXAXIS;
|
|
pDev->ioCnt = MAXIO;
|
|
pDev->adCnt = MAXAD;
|
|
pDev->homeCnt = sizeof(sz_desc) / sizeof(char*);
|
|
for(int i = 0; i < pDev->homeCnt; i++)
|
|
{
|
|
strcpy(pDev->homep.data[i], sz_desc[i]);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
EXPORT_C int WINAPI init_dev(ushort cardIndex, TParam* param)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->OpenCard(cardIndex);
|
|
}
|
|
|
|
EXPORT_C int WINAPI uninit_dev(ushort cardIndex)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->CloseCard(cardIndex);
|
|
}
|
|
|
|
EXPORT_C int WINAPI get_status(ushort cardIndex)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, EDev_NOINIT);
|
|
return ins->GetStatus(cardIndex);
|
|
}
|
|
|
|
EXPORT_C int WINAPI send_custom_msg(ushort cardIndex, const char* msg, char* res/* = 0*/)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->SendCustomCommand(cardIndex, msg, res);
|
|
}
|
|
|
|
EXPORT_C int WINAPI recv_custom_msg(ushort cardIndex, const char* msg, char* res, int timeout/* = 0*/)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->RecvCustomCommand(cardIndex, msg, res, timeout);
|
|
}
|
|
|
|
EXPORT_C int WINAPI get_command_desc(char* pszcmddesc)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->GetCommandDesc(pszcmddesc);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_reset(ushort cardIndex, ushort axisIndex)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisReset(cardIndex, axisIndex);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_zero_pos(ushort cardIndex, ushort axisIndex)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisZeroPos(cardIndex, axisIndex);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_home(ushort cardIndex, ushort axisIndex, ushort homeType, double pos, double offset, double vel)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisHome(cardIndex, axisIndex, homeType,
|
|
double_to_int(pos), double_to_int(offset), vel);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_is_moving(ushort cardIndex, ushort axisIndex)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, 0);
|
|
return ins->AxisIsMoving(cardIndex, axisIndex);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_set_speed(ushort cardIndex, ushort axisIndex, double vel, double acc, double dec)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisSetSpeed(cardIndex, axisIndex, vel);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_set_pos(ushort cardIndex, ushort axisIndex, double pos)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisSetPos(cardIndex, axisIndex, double_to_int(pos));
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_stop(ushort cardIndex, ushort axisIndex, int type)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisStop(cardIndex, axisIndex, type);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_move_pos(ushort cardIndex, ushort axisIndex, double pos, double vel, double acc, double dec)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisMovePos(cardIndex, axisIndex, double_to_int(pos), vel, acc, dec);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_move_offset(ushort cardIndex, ushort axisIndex, double offset, double vel, double acc, double dec)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisMoveOffset(cardIndex, axisIndex, double_to_int(offset), vel, acc, dec);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_move_jog(ushort cardIndex, ushort axisIndex, int dir, double vel, double acc, double dec)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisMoveJog(cardIndex, axisIndex, dir, vel, acc, dec);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_read(ushort cardIndex, ushort in_index, EIOType dio_type)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, 0);
|
|
return ins->ReadBit(cardIndex, in_index, dio_type);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_write(ushort cardIndex, ushort out_index, ushort val, EIOType do_type)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->WriteOutBit(cardIndex, out_index, val, do_type);
|
|
}
|
|
|
|
EXPORT_C int WINAPI axis_get_pos(ushort cardIndex, ushort axisIndex, EMPosType postype, double *pval)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AxisGetPos(cardIndex, axisIndex, postype, pval);
|
|
}
|
|
|
|
EXPORT_C int WINAPI create_crd(ushort cardIndex, ushort *pAxisIndex, ushort nsize)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->CreateCrd(cardIndex, pAxisIndex, nsize);
|
|
}
|
|
|
|
EXPORT_C int WINAPI add_line_pos(int crdID, double *ppos, ushort nsize, double vel, double acc, double endvel)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AddLinePos(crdID, ppos, nsize, vel, acc, endvel);
|
|
}
|
|
|
|
EXPORT_C int WINAPI add_arc_pos(int crdID, double *ppos1, double *ppos2, double *ppos3, ushort nsize, double vel, double acc, double endvel)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->AddArcPos(crdID, ppos1, ppos2, ppos3, nsize, vel, acc, endvel);
|
|
}
|
|
|
|
EXPORT_C int WINAPI crd_move(int crdID)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->CrdStartMove(crdID);
|
|
}
|
|
|
|
EXPORT_C int WINAPI crd_is_moving(int crdID, int *progress)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, 0);
|
|
return ins->CrdStatus(crdID, progress);
|
|
}
|
|
|
|
EXPORT_C int WINAPI close_crd(int crdID)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->CloseCrd(crdID);
|
|
}
|
|
|
|
EXPORT_C int WINAPI read_in(ushort cardIndex, ushort in_index)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, 0);
|
|
return ins->ReadBit(cardIndex, in_index, IOT_COMIN);
|
|
}
|
|
|
|
EXPORT_C int WINAPI read_out(ushort cardIndex, ushort out_index)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, 0);
|
|
return ins->ReadOutBit(cardIndex, out_index, IOT_COMOUT);
|
|
}
|
|
|
|
EXPORT_C int WINAPI write_out(ushort cardIndex, ushort out_index, ushort val)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->WriteOutBit(cardIndex, out_index, val, IOT_COMOUT);
|
|
}
|
|
|
|
EXPORT_C int WINAPI read_ad(ushort cardIndex, ushort index, double* pVal)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->ReadAdc(cardIndex, index, pVal);
|
|
}
|
|
|
|
EXPORT_C int WINAPI write_ad(ushort cardIndex, ushort index, double val)
|
|
{
|
|
RETURN_CHK_NOPRT(g_bInit, ERR_NO_INIT);
|
|
return ins->WriteAdc(cardIndex, index, val);
|
|
}
|