Overview
本文介紹如何使用三菱提供的開發套件,與三菱機床M70進行通訊
開發套件下載地址:官方地址(需要註冊賬號)
如圖,目前官方更新到了A7版本(需要購買序列號):
com開發基礎
參考:https://www.cnblogs.com/dayw/category/512428.html
ProgID在登錄檔的 計算機\HKEY_CLASSES_ROOT
目錄下
CLSID在ProgID下記錄,如圖:
環境配置
開發套件安裝位置:C:\Program Files (x86)\EZSocket
庫檔案:
專案建立
使用Visual Studio 2022建立一個C++專案
將官方提供的標頭檔案複製到專案的目錄下,然後新增到標頭檔案中如圖
注意要使用32位來編譯,官方庫是32位的,使用64位編譯會找不到api
可以參考官方手冊的程式設計步驟和API說明程式設計:
示例程式碼
三菱m70的通訊埠為683
#include <iostream>
#include <climits>
#include "EZSocketCommonErr.h"
#include "EZSocketNc.h"
#include "EZSocketNcDef.h"
#include "EZSocketNcErr.h"
#include "EZSocketNcStr.h"
const LPCOLESTR CNC_IP = L"192.168.XXX.XXX";
const LONG CNC_port = 683;
int main()
{
LONG Iret;
IUnknown* m_pezUnknown = NULL;
IEZNcCommunication3* m_pezComm = NULL;
IEZNcPosition* m_pezPos = NULL;
IEZNcProgram2* m_pezProgram = NULL;
IEZNcFile6* m_pezFile = NULL;
IEZNcOperation* m_pezOperation = NULL;
IEZNcRunStatus* m_pezRunStatus = NULL;
IEZNcAxisMonitor* m_pezAxisMonitor = NULL;
IEZNcTime* m_pezTime = NULL;
IEZNcCommand2* m_pezCommand2 = NULL;
IEZNcDevice* m_pezDevice = NULL;
IEZNcParameter3* m_pezParameter3 = NULL;
enum { AXIS_X = 1, AXIS_Y, AXIS_Z, AXIS_C };
DOUBLE m70_MachinePos[4];
for (int i = 0; i < 4; i++) {
m70_MachinePos[i] = 100.0;
}
CLSID clsid;
if (Iret = CoInitialize(NULL) != S_OK) {
std::cout << "例項化com失敗!";
return -1;
}
Iret = CLSIDFromProgID(L"EZSocketNc.EZNcCommunication", &clsid);
if (Iret != S_OK) {
std::cout << "CLSIDFromProgID失敗!";
return -1;
}
Iret = CoCreateInstance(clsid,
NULL,
CLSCTX_INPROC_SERVER,
IID_IEZNcCommunication3,
(void**)&m_pezComm);
if (Iret != S_OK) {
std::cout << std::hex;
std::cout << Iret;
std::cout << "CoCreateInstance失敗!";
return -1;
}
Iret = m_pezComm->QueryInterface(IID_IEZNcPosition, (void**)&m_pezPos);
m_pezComm->SetTCPIPProtocol(CNC_IP, CNC_port, &Iret);
m_pezComm->Open2(EZNC_SYS_MELDAS700M, 1, 100, &Iret);
m_pezPos->GetMachinePosition(AXIS_X, &m70_MachinePos[0], 0, &Iret);
m_pezPos->GetMachinePosition(AXIS_Y, &m70_MachinePos[1], 0, &Iret);
m_pezPos->GetMachinePosition(AXIS_Z, &m70_MachinePos[2], 0, &Iret);
for (int i = 0; i < 3; i++) {
std::cout << m70_MachinePos[i] << std::endl;
}
//std::cout << "Hello World!\n";
m_pezComm->Close(&Iret);
}