Environment
- Python 3.7.13 (32-bit)
- clr-loader 0.2.6
- pythonnet 3.0.3
- Windows 11 (64-bit)
I am trying to get values from a dll using Python. It is for Mitsubishi PLC’s MX Component 4. It offers simple formats in C# like below.
iRet = object.GetDevice(szDevice, out iData)
// Int iRet
// String szDevice
// Int iData
Above code is for getting a single value from a device. I could make it in Python.
import clr
import numpy as np
DLL_FILE_PATH = 'blablabla\ActUtlTypeLib.dll'
STATION_NUMBER = 1
szDevice = 'A0000'
clr.AddReference(DLL_FILE_PATH)
from ActUtlTypeLib import ActUtlType
act_util_type = ActUtlType()
act_util_type.ActLogicalStationNumber = STATION_NUMBER
ret, val = act_util_type.GetDevice(szDevice)
assert ret == 0, f'GetDevice error: {ret}'
print(val)
MX Component also offers getting multiple values from multiple devices.
iRet = object.ReadDeviceBlock(ref szLabel, iSize, ref iData)
// Int iRet
// String szLabel
// Int iSize
// Int[n] iData
But I am unable to do that in Python. I tried few types of iData but nothing worked.
# All the combinations of 'Type' and 'Trial' didn't work
length = 1000
# arr = [] # Type 1
# arr = [0 for _ in range(length)] # Type 2
arr = np.zeros(length, np.int32) # Type 3
# ret, val = act_util_type.ReadDeviceBlock(ADDRESS, length) # Trial 1
# ret = act_util_type.ReadDeviceBlock(ADDRESS, length, arr) # Trial 2
ret = act_util_type.ReadDeviceBlock(ADDRESS, length, arr[0]) # Trial 3
How can I get values using ReadDeviceBlock in Python?
MX Component 4 Manual