一. 控件
编程语言使用了c++,所以用 ACT控件;
二.两种DLL -- 两种不同通讯设置方法
2.1 ActUtlType
在使用MX Component提供的一个通讯设置工具 - Communication Setup Utility,设置了PC与PLC之间的通讯相关参数的情况下,要使用ActUtlType。 这个设置好后,通过mx提供的接口就很好调用了,只需要 传入设置的 Logical Station Number 就可以直接调用Open函数打开了。
IActUtlType* mp_IUtlType; // ACT Control (Custom Interface)
long lRet;
HRESULT hr;
hr = mp_IUtlType->put_ActLogicalStationNumber(nStationNo);// Exec set-property method
if(SUCCEEDED(hr))
{ // Compornent Communication is succeeded?
hr = mp_IUtlType->Open(&lRet); // Exec Open Method
}
2.2 ActProgType
不使用Communication Setup Utility设置,则要使用ActProgType控件。这种情况下,需要知道的是cpu的型号,IP地址以及使用的通讯协议:
IActProgType* mp_IProgType; // ACT Control (Custom Interface)
hr = mp_IProgType->put_ActUnitType(UNIT_QNETHER); // Exec set-property method
if(SUCCEEDED(hr))
{ // Compornent Communication is succeeded?
hr = mp_IProgType->put_ActProtocolType(PROTOCOL_TCPIP);
hr &= mp_IProgType->put_ActHostAddress(IP);
if(SUCCEEDED(hr))
{ // Compornent Communication is succeeded?
hr = mp_IProgType->Open(&lRet); // Exec Open Method
}
}
在打开成功后,就可以进行后续的通讯接口调用了,详见mx控件提供的文档,在MX Component提供的安装文件中有具体的编程文档。