Installing ActiveX Controls For Communicating With Mitsubishi Microcontrollers

Another recent re-revisit was necessary, this time to enable USB-based as well as COM-based communication between PC and Mitsubishi PLC microcontrollers. 

Registering the ActiveX Control

To register the ActiveX component so that is shows up on your toolbox, choose Tools and select Add/Remove Toolbox Items:

Click the Com Components tab and choose the DLL which includes the ActiveX control you want to use:

The Mitsubishi ActiveX control is now added to your toolbox:

toolbox

Set the include file

ToolsOptions

Start Visual Studio, choose the Tools menu and select Options. In the Projects folder select VC++ Directories, choose Show directories for include files and select the location for the include file:

Options

Using the ActiveX control in your project

Right-click on your form and choose “Insert ActiveX Control”:

InsertActiveX

Select the one you need, which will then paste itself onto your form.

ActiveXusb

ActiveXinserted

Generate the new ActiveX class

Navigate to the Project menu and select Add Class. Select MFC class for ActiveX control:

AddClass

In the Control Wizard that appears, select the appropriate ActiveX control that you need from the drop-down menu.  The Interfaces list control specifies the interface(s) in the ActiveX control currently selected. 

ControlWizard1

You also need to generate the class(es) from the interface(s) listed. Do this by using the > or >> buttons:

You are now ready to make full use of the all the features available:

Open() – establish a communication path, returns 0 if successful.
Close() – close the communication path
GetDevice(szDevice, lplData) – acquire device data
SetDevice2(szDevice, iData) – Sets 2-byte data to one device point

// CActQCPUQUSB3.h  : Declaration of ActiveX Control wrapper class(es) created by Microsoft Visual C++

#pragma once

/////////////////////////////////////////////////////////////////////////////
// CActQCPUQUSB3

class CActQCPUQUSB3 : public CWnd
{
protected:
    DECLARE_DYNCREATE(CActQCPUQUSB3)
public:
    CLSID const& GetClsid()
    {
        static CLSID const clsid
            = { 0xB5BDE862, 0xAEA9, 0x11D3, { 0x83, 0xAE, 0x0, 0xA0, 0x24, 0xBD, 0xBF, 0x2B } };
        return clsid;
    }
    virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
                        const RECT& rect, CWnd* pParentWnd, UINT nID,
                        CCreateContext* pContext = NULL)
    {
        return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
    }

    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
                UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
                BSTR bstrLicKey = NULL)
    {
        return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
        pPersist, bStorage, bstrLicKey);
    }

// Attributes
public:

// Operations
public:

    long Open()
    {
        long result;
        InvokeHelper(0x1, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);
        return result;
    }
    long Close()
    {
        long result;
        InvokeHelper(0x2, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);
        return result;
    }
    long ReadDeviceBlock(LPCTSTR szDevice, long dwSize, long * lpdwData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_PI4 ;
        InvokeHelper(0x3, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, dwSize, lpdwData);
        return result;
    }
    long WriteDeviceBlock(LPCTSTR szDevice, long dwSize, long * lpdwData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_PI4 ;
        InvokeHelper(0x4, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, dwSize, lpdwData);
        return result;
    }
    long ReadDeviceRandom(LPCTSTR szDeviceList, long dwSize, long * lpdwData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_PI4 ;
        InvokeHelper(0x5, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDeviceList, dwSize, lpdwData);
        return result;
    }
    long WriteDeviceRandom(LPCTSTR szDeviceList, long dwSize, long * lpdwData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_PI4 ;
        InvokeHelper(0x6, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDeviceList, dwSize, lpdwData);
        return result;
    }
    long ReadBuffer(long lStartIO, long lAddress, long lReadSize, short * lpwData)
    {
        long result;
        static BYTE parms[] = VTS_I4 VTS_I4 VTS_I4 VTS_PI2 ;
        InvokeHelper(0x7, DISPATCH_METHOD, VT_I4, (void*)&result, parms, lStartIO, lAddress, lReadSize, lpwData);
        return result;
    }
    long WriteBuffer(long lStartIO, long lAddress, long lWriteSize, short * lpwData)
    {
        long result;
        static BYTE parms[] = VTS_I4 VTS_I4 VTS_I4 VTS_PI2 ;
        InvokeHelper(0x8, DISPATCH_METHOD, VT_I4, (void*)&result, parms, lStartIO, lAddress, lWriteSize, lpwData);
        return result;
    }
    long GetClockData(short * lpwYear, short * lpwMonth, short * lpwDay, short * lpwDayOfWeek, short * lpwHour, short * lpwMinute, short * lpwSecond)
    {
        long result;
        static BYTE parms[] = VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2 ;
        InvokeHelper(0x9, DISPATCH_METHOD, VT_I4, (void*)&result, parms, lpwYear, lpwMonth, lpwDay, lpwDayOfWeek, lpwHour, lpwMinute, lpwSecond);
        return result;
    }
    long SetClockData(short wYear, short wMonth, short wDay, short wDayOfWeek, short wHour, short wMinute, short wSecond)
    {
        long result;
        static BYTE parms[] = VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2 ;
        InvokeHelper(0xa, DISPATCH_METHOD, VT_I4, (void*)&result, parms, wYear, wMonth, wDay, wDayOfWeek, wHour, wMinute, wSecond);
        return result;
    }
    long SetDevice(LPCTSTR szDevice, long dwData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 ;
        InvokeHelper(0xb, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, dwData);
        return result;
    }
    long SetCpuStatus(long lOperation)
    {
        long result;
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0xc, DISPATCH_METHOD, VT_I4, (void*)&result, parms, lOperation);
        return result;
    }
    long GetCpuType(BSTR * lpszCpuName, long * lplCpuType)
    {
        long result;
        static BYTE parms[] = VTS_PBSTR VTS_PI4 ;
        InvokeHelper(0xd, DISPATCH_METHOD, VT_I4, (void*)&result, parms, lpszCpuName, lplCpuType);
        return result;
    }
    long get_ActNetworkNumber()
    {
        long result;
        InvokeHelper(0xe, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActNetworkNumber(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0xe, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActStationNumber()
    {
        long result;
        InvokeHelper(0xf, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActStationNumber(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0xf, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActUnitNumber()
    {
        long result;
        InvokeHelper(0x10, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActUnitNumber(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x10, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActIONumber()
    {
        long result;
        InvokeHelper(0x11, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActIONumber(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x11, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActCpuType()
    {
        long result;
        InvokeHelper(0x12, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActCpuType(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x12, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActTimeOut()
    {
        long result;
        InvokeHelper(0x14, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActTimeOut(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x14, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActDestinationIONumber()
    {
        long result;
        InvokeHelper(0x15, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActDestinationIONumber(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x15, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActMultiDropChannelNumber()
    {
        long result;
        InvokeHelper(0x16, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActMultiDropChannelNumber(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x16, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActThroughNetworkType()
    {
        long result;
        InvokeHelper(0x17, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActThroughNetworkType(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x17, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActIntelligentPreferenceBit()
    {
        long result;
        InvokeHelper(0x18, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActIntelligentPreferenceBit(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x18, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActDidPropertyBit()
    {
        long result;
        InvokeHelper(0x19, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActDidPropertyBit(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x19, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long get_ActDsidPropertyBit()
    {
        long result;
        InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void put_ActDsidPropertyBit(long newValue)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x1a, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long GetDevice(LPCTSTR szDevice, long * lpdwData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_PI4 ;
        InvokeHelper(0x1b, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, lpdwData);
        return result;
    }
    long CheckDeviceString(LPCTSTR szDevice, long lCheckType, long lSize, long * lplDeviceType, BSTR * lpszDeviceName, long * lplDeviceNumber, long * lplDeviceRadix)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_I4 VTS_PI4 VTS_PBSTR VTS_PI4 VTS_PI4 ;
        InvokeHelper(0x1f, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, lCheckType, lSize, lplDeviceType, lpszDeviceName, lplDeviceNumber, lplDeviceRadix);
        return result;
    }
    long EntryDeviceStatus(LPCTSTR szDeviceList, long lSize, long lMonitorCycle, long * lplData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_I4 VTS_PI4 ;
        InvokeHelper(0x20, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDeviceList, lSize, lMonitorCycle, lplData);
        return result;
    }
    long FreeDeviceStatus()
    {
        long result;
        InvokeHelper(0x21, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);
        return result;
    }
    long ReadDeviceBlock2(LPCTSTR szDevice, long lSize, short * lpsData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_PI2 ;
        InvokeHelper(0x22, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, lSize, lpsData);
        return result;
    }
    long WriteDeviceBlock2(LPCTSTR szDevice, long lSize, short * lpsData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_PI2 ;
        InvokeHelper(0x23, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, lSize, lpsData);
        return result;
    }
    long ReadDeviceRandom2(LPCTSTR szDevice, long lSize, short * lpsData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_PI2 ;
        InvokeHelper(0x24, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, lSize, lpsData);
        return result;
    }
    long WriteDeviceRandom2(LPCTSTR szDeviceList, long lSize, short * lpsData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I4 VTS_PI2 ;
        InvokeHelper(0x25, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDeviceList, lSize, lpsData);
        return result;
    }
    long GetDevice2(LPCTSTR szDevice, short * lpsData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_PI2 ;
        InvokeHelper(0x26, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, lpsData);
        return result;
    }
    long SetDevice2(LPCTSTR szDevice, short sData)
    {
        long result;
        static BYTE parms[] = VTS_BSTR VTS_I2 ;
        InvokeHelper(0x27, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevice, sData);
        return result;
    }
};

Latest Comments

  1. Anonymous 13 September 2011

Leave a Reply to Anonymous Cancel reply