开启左侧

固高GTS运控控制卡简单示例代码

[复制链接]
丶初吻给了奶嘴 发表于 2017-3-31 20:10:31 | 显示全部楼层 |阅读模式
本帖最后由 丶初吻给了奶嘴 于 2017-3-31 20:18 编辑
  1. // XGTMotion.h : XGTMotion DLL 的主头文件
  2. //

  3. #pragma once


  4. #ifndef AFX_GTMOTION_DLL
  5.         #ifndef AFX_GTMOTION_IMPORT
  6.                 #define AFX_GTMOTION_IMPORT __declspec(dllexport)
  7.         #endif
  8. #else
  9.         #ifndef AFX_GTMOTION_IMPORT
  10.                 #define AFX_GTMOTION_IMPORT __declspec(dllimport)
  11.         #endif
  12. #endif


  13. #define X_CAPTURE_HOME    1  // HOME   捕获回零(以机械原点为零点)
  14. #define X_CAPTURE_INDEX   2  // INDEX  捕获回零(以机械原点+偏移量为零点)
  15. #define X_CAPTURE_ROTATE  3  // ROTATE 旋转回零(无正负限位捕获原点)

  16. #define X_POS_PRF         1  // 规划位置(非编码器)
  17. #define X_POS_ENC         2  // 实际位置(编码器)

  18. #define MC_LIMIT_POSITIVE 0
  19. #define MC_LIMIT_NEGATIVE 1
  20. #define MC_ALARM          2
  21. #define MC_HOME           3
  22. #define MC_GPI            4
  23. #define MC_GPO            12
  24. #define MC_ARRIVE         5


  25. //! 轴参数
  26. typedef struct AxisPara
  27. {
  28.     int     nHomeType;              // 回零方式
  29.     double  dbScrew;                // 丝杆节距(mm)
  30.     long    nPerCycle;              // 多少脉冲 = 丝杆节距
  31.     double  dbFastHomeVel;          // 高速回零速度
  32.     double  dbFastHomeAcc;          // 高速回零加速度
  33.     double  dbLowHomeVel;           // 低速回零速度
  34.     double  dbLowHomeAcc;           // 低速回零加速度
  35.     double  dbMoveVel;              // 目标速度
  36.     double  dbMoveAcc;              // 目标加速度
  37.     double  dbMoveDec;              // 目标减速度
  38.     double  dbStartVel;             // 起跳速度
  39.     int     nSmoothTime;            // 平滑时间
  40.     int     nSleep;                 // 到位延时
  41.     double  dbLimitPos;             // 正向软限位
  42.     double  dbLimitNeg;             // 负向软限位
  43.     double  dbBacklash;             // 反向间隙
  44.     wchar_t szCalibFile[MAX_PATH];  // 校正文件

  45.     AxisPara()
  46.     {
  47.         nHomeType     = 0;
复制代码
  1. // XGTMotion.cpp : 定义 DLL 的初始化例程。
  2. //

  3. #include "stdafx.h"
  4. #include "XGTMotion.h"

  5. #include "gts.h"
  6. #pragma comment(lib, "gts.lib")


  7. //////////////////////////////////////////////////////////////////////////
  8. // CXGTMotionBase


  9. #ifndef Char2WChar
  10. #define Char2WChar(lpMultiByteStr,cbMultiByte,lpWideCharStr,cbWideChar) \
  11.         MultiByteToWideChar(CP_ACP/*代码页*/, 0, lpMultiByteStr/*ANSI字符串*/, cbMultiByte/*ANSI字符串大小*/, lpWideCharStr/*Unicode字符串缓冲区*/, cbWideChar/*Unicode字符串字符串缓冲区*/)
  12. #endif

  13. #ifndef WChar2Char
  14. #define WChar2Char(lpWideCharStr,cbWideChar,lpMultiByteStr,cbMultiByte) \
  15.         WideCharToMultiByte(CP_ACP/*代码页*/, 0, lpWideCharStr/*Unicode字符串*/, cbWideChar/*Unicode字符串大小*/, lpMultiByteStr/*ANSI字符串缓冲区*/, cbMultiByte/*ANSI字符串缓冲区大小*/, NULL, NULL)
  16. #endif


  17. #ifndef CLOSE_EGT
  18. #define CLOSE_EGT(rtn) if (0 != rtn) GT_Close()
  19. #endif


  20. #ifndef CHECK_RTN
  21. #define CHECK_RTN(nRtn, strFun, __LINE__) \
  22. do \
  23. { \
  24.         CString strTemp(_T("")); \
  25.         switch (nRtn) \
  26.         { \
  27.                 case 0: \
  28.                 break; \
  29.                 case 1: \
  30.                 strTemp.Format(_T("%s error return with %d\r\n指令执行错误:请检查当前指令的执行条件是否满足"), _T(strFun), nRtn); \
  31.                 MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
  32.                 return FALSE; \
  33.                 case 2: \
  34.                 strTemp.Format(_T("%s error return with %d\r\nLicense不支持:如果需要此功能,请与生产厂商联系"), _T(strFun), nRtn); \
  35.                 MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
  36.                 return FALSE; \
  37.                 case 7: \
  38.                 strTemp.Format(_T("%s error return with %d\r\n指令参数错误:请检查当前指令输入参数的取值"), _T(strFun), nRtn); \
  39.                 MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
  40.                 return FALSE; \
  41.                 case -1: \
  42.                 strTemp.Format(_T("%s error return with %d\r\n主机和运动控制器通迅失败:\r\n1. 是否正确安装运动控制器驱动程序\r\n2. 检查运动控制器是否接插牢靠\r\n3. 更换主机\r\n4. 更换控制器"), _T(strFun), nRtn); \
  43.                 MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
  44.                 return FALSE; \
  45.                 case -6: \
  46.                 strTemp.Format(_T("%s error return with %d\r\n打开控制器失败:\r\n1. 是否正确安装运动控制器驱动程序\r\n2. 是否调用了2次GT_Open指令\r\n3. 其他程序是否已经打开运动控制器"), _T(strFun), nRtn); \
  47.                 MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
  48.                 return FALSE; \
  49.                 case -7: \
  50.                 strTemp.Format(_T("%s error return with %d\r\n运动控制器没有响应:更换运动控制器"), _T(strFun), nRtn); \
  51.                 MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
  52.                 return FALSE; \
  53.                 default: \
  54.                 strTemp.Format(_T("%s error return with %d\r\n未知错误:未知错误"), _T(strFun), nRtn); \
  55.                 MessageBox(NULL, strTemp, _T("CXGTMotion"), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); \
  56.                 return FALSE; \
  57.         } \
  58. } while (FALSE)
  59. #endif


  60. #ifndef CHECK_BOOL
  61. #define CHECK_BOOL(x) \
  62. do \
  63. { \
  64.     if (!x) \
  65.     return FALSE; \
  66. } while (FALSE)
  67. #endif


  68. #define MAX_RIGHT 99999999
  69. #define MAX_LEFT -99999999
  70. #define MAX_AXIS  8


  71. //////////////////////////////////////////////////////////////////////////
  72. // CXGTMotionBase
  73. class CXGTMotionBase
  74. {
  75.     friend class CXGTMotion;
  76. public:
  77.     CXGTMotionBase(void);
  78.     ~CXGTMotionBase(void);

  79.     BOOL Stop(int nAxis);
  80.     BOOL MoveTo(int nAxis, long nPulsePos, double dbPulseVel, double dbPulseAcc, double dbPulseDec, double dbStartVel, short nSmoothTime);
  81.     BOOL MoveToNoWait(int nAxis, long nPulsePos, double dbPulseVel, double dbPulseAcc, double dbPulseDec, double dbStartVel, short nSmoothTime);
  82.     BOOL WaitAxisStop(int nAxis);
  83.     BOOL CapturePos(int nAxis, int nCaptureType, long &nCapturePulsePos, double dbPulsePos, double dbPulseVel, double dbPulseAcc, double dbPulseDec, double dbStartVel, short nSmoothTime);

  84. private:
  85.     BOOL     m_bOpenOk;              // 记录运动控制卡是否打开
  86.     CString  m_strModulePath; // 可执行文件目录
  87.     AxisPara m_axispara[8];   // 各轴参数
  88. };


  89. CXGTMotionBase::CXGTMotionBase(void)
  90. {
  91.     wchar_t pszFile[MAX_PATH];
  92.     GetModuleFileName(NULL, pszFile, MAX_PATH);
  93.     CString strFile = pszFile;
  94.     int     index   = strFile.ReverseFind('\\');
  95.     m_strModulePath = strFile.Left(index + 1);

  96.     m_bOpenOk = FALSE;
  97. }


  98. CXGTMotionBase::~CXGTMotionBase(void)
  99. {
  100. }


  101. BOOL CXGTMotionBase::Stop(int nAxis)
  102. {
  103.     short rtn = 0;
  104.     long  status = 0;
  105.     rtn = GT_Stop(1 << (nAxis - 1), 0);
  106.     CHECK_RTN(rtn, "GT_Stop", __LINE__);

  107.     do {
  108.         rtn = GT_GetSts(nAxis, &status);
复制代码


GTMotion.rar

6.85 KB, 下载次数: 146

售价: 5 视觉币  [记录]  [购买]

完整示例代码

夜行人 发表于 2018-1-20 10:13:30 | 显示全部楼层
好东西,分享下
cookie1843 发表于 2018-7-6 10:56:52 | 显示全部楼层
下载不鸟,谁有可以发一份到邮箱吗?谢谢了
99liuhong99@163.com
lhl2016 发表于 2018-8-27 10:17:41 | 显示全部楼层
不错,可以参考参考。。。。。。。。。
jun198923 发表于 2018-9-1 01:23:52 | 显示全部楼层
确实不错,可以作为参考
mei5201314 发表于 2021-6-16 14:35:36 | 显示全部楼层
要钱看不了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表