本帖最后由 丶初吻给了奶嘴 于 2017-3-31 20:18 编辑
- // XGTMotion.h : XGTMotion DLL 的主头文件
- //
- #pragma once
- #ifndef AFX_GTMOTION_DLL
- #ifndef AFX_GTMOTION_IMPORT
- #define AFX_GTMOTION_IMPORT __declspec(dllexport)
- #endif
- #else
- #ifndef AFX_GTMOTION_IMPORT
- #define AFX_GTMOTION_IMPORT __declspec(dllimport)
- #endif
- #endif
- #define X_CAPTURE_HOME 1 // HOME 捕获回零(以机械原点为零点)
- #define X_CAPTURE_INDEX 2 // INDEX 捕获回零(以机械原点+偏移量为零点)
- #define X_CAPTURE_ROTATE 3 // ROTATE 旋转回零(无正负限位捕获原点)
- #define X_POS_PRF 1 // 规划位置(非编码器)
- #define X_POS_ENC 2 // 实际位置(编码器)
- #define MC_LIMIT_POSITIVE 0
- #define MC_LIMIT_NEGATIVE 1
- #define MC_ALARM 2
- #define MC_HOME 3
- #define MC_GPI 4
- #define MC_GPO 12
- #define MC_ARRIVE 5
- //! 轴参数
- typedef struct AxisPara
- {
- int nHomeType; // 回零方式
- double dbScrew; // 丝杆节距(mm)
- long nPerCycle; // 多少脉冲 = 丝杆节距
- double dbFastHomeVel; // 高速回零速度
- double dbFastHomeAcc; // 高速回零加速度
- double dbLowHomeVel; // 低速回零速度
- double dbLowHomeAcc; // 低速回零加速度
- double dbMoveVel; // 目标速度
- double dbMoveAcc; // 目标加速度
- double dbMoveDec; // 目标减速度
- double dbStartVel; // 起跳速度
- int nSmoothTime; // 平滑时间
- int nSleep; // 到位延时
- double dbLimitPos; // 正向软限位
- double dbLimitNeg; // 负向软限位
- double dbBacklash; // 反向间隙
- wchar_t szCalibFile[MAX_PATH]; // 校正文件
- AxisPara()
- {
- nHomeType = 0;
复制代码- // XGTMotion.cpp : 定义 DLL 的初始化例程。
- //
- #include "stdafx.h"
- #include "XGTMotion.h"
- #include "gts.h"
- #pragma comment(lib, "gts.lib")
- //////////////////////////////////////////////////////////////////////////
- // CXGTMotionBase
- #ifndef Char2WChar
- #define Char2WChar(lpMultiByteStr,cbMultiByte,lpWideCharStr,cbWideChar) \
- MultiByteToWideChar(CP_ACP/*代码页*/, 0, lpMultiByteStr/*ANSI字符串*/, cbMultiByte/*ANSI字符串大小*/, lpWideCharStr/*Unicode字符串缓冲区*/, cbWideChar/*Unicode字符串字符串缓冲区*/)
- #endif
- #ifndef WChar2Char
- #define WChar2Char(lpWideCharStr,cbWideChar,lpMultiByteStr,cbMultiByte) \
- WideCharToMultiByte(CP_ACP/*代码页*/, 0, lpWideCharStr/*Unicode字符串*/, cbWideChar/*Unicode字符串大小*/, lpMultiByteStr/*ANSI字符串缓冲区*/, cbMultiByte/*ANSI字符串缓冲区大小*/, NULL, NULL)
- #endif
- #ifndef CLOSE_EGT
- #define CLOSE_EGT(rtn) if (0 != rtn) GT_Close()
- #endif
- #ifndef CHECK_RTN
- #define CHECK_RTN(nRtn, strFun, __LINE__) \
- do \
- { \
- CString strTemp(_T("")); \
- switch (nRtn) \
- { \
- case 0: \
- break; \
- case 1: \
- strTemp.Format(_T("%s error return with %d\r\n指令执行错误:请检查当前指令的执行条件是否满足"), _T(strFun), nRtn); \
- MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
- return FALSE; \
- case 2: \
- strTemp.Format(_T("%s error return with %d\r\nLicense不支持:如果需要此功能,请与生产厂商联系"), _T(strFun), nRtn); \
- MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
- return FALSE; \
- case 7: \
- strTemp.Format(_T("%s error return with %d\r\n指令参数错误:请检查当前指令输入参数的取值"), _T(strFun), nRtn); \
- MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
- return FALSE; \
- case -1: \
- strTemp.Format(_T("%s error return with %d\r\n主机和运动控制器通迅失败:\r\n1. 是否正确安装运动控制器驱动程序\r\n2. 检查运动控制器是否接插牢靠\r\n3. 更换主机\r\n4. 更换控制器"), _T(strFun), nRtn); \
- MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
- return FALSE; \
- case -6: \
- strTemp.Format(_T("%s error return with %d\r\n打开控制器失败:\r\n1. 是否正确安装运动控制器驱动程序\r\n2. 是否调用了2次GT_Open指令\r\n3. 其他程序是否已经打开运动控制器"), _T(strFun), nRtn); \
- MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
- return FALSE; \
- case -7: \
- strTemp.Format(_T("%s error return with %d\r\n运动控制器没有响应:更换运动控制器"), _T(strFun), nRtn); \
- MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
- return FALSE; \
- default: \
- strTemp.Format(_T("%s error return with %d\r\n未知错误:未知错误"), _T(strFun), nRtn); \
- MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
- return FALSE; \
- } \
- } while (FALSE)
- #endif
- #ifndef CHECK_BOOL
- #define CHECK_BOOL(x) \
- do \
- { \
- if (!x) \
- return FALSE; \
- } while (FALSE)
- #endif
- #define MAX_RIGHT 99999999
- #define MAX_LEFT -99999999
- #define MAX_AXIS 8
- //////////////////////////////////////////////////////////////////////////
- // CXGTMotionBase
- class CXGTMotionBase
- {
- friend class CXGTMotion;
- public:
- CXGTMotionBase(void);
- ~CXGTMotionBase(void);
- BOOL Stop(int nAxis);
- BOOL MoveTo(int nAxis, long nPulsePos, double dbPulseVel, double dbPulseAcc, double dbPulseDec, double dbStartVel, short nSmoothTime);
- BOOL MoveToNoWait(int nAxis, long nPulsePos, double dbPulseVel, double dbPulseAcc, double dbPulseDec, double dbStartVel, short nSmoothTime);
- BOOL WaitAxisStop(int nAxis);
- BOOL CapturePos(int nAxis, int nCaptureType, long &nCapturePulsePos, double dbPulsePos, double dbPulseVel, double dbPulseAcc, double dbPulseDec, double dbStartVel, short nSmoothTime);
- private:
- BOOL m_bOpenOk; // 记录运动控制卡是否打开
- CString m_strModulePath; // 可执行文件目录
- AxisPara m_axispara[8]; // 各轴参数
- };
- CXGTMotionBase::CXGTMotionBase(void)
- {
- wchar_t pszFile[MAX_PATH];
- GetModuleFileName(NULL, pszFile, MAX_PATH);
- CString strFile = pszFile;
- int index = strFile.ReverseFind('\\');
- m_strModulePath = strFile.Left(index + 1);
- m_bOpenOk = FALSE;
- }
- CXGTMotionBase::~CXGTMotionBase(void)
- {
- }
- BOOL CXGTMotionBase::Stop(int nAxis)
- {
- short rtn = 0;
- long status = 0;
- rtn = GT_Stop(1 << (nAxis - 1), 0);
- CHECK_RTN(rtn, "GT_Stop", __LINE__);
- do {
- rtn = GT_GetSts(nAxis, &status);
复制代码
|
|