0

I need use QAxObject to read some PLCdata.I Can connect PLC successful but the problem is that I can't read data from it.The reason in below.

class Test(QAxWidget):
    def __init__(self):
        super().__init__()
        self.setControl("ActUtlType.ActUtlType.1")
        self.dynamicCall("SetActLogicalStationNumber(int)", 1)

        ret = self.dynamicCall("Open()")
        value = 12
        ret = self.dynamicCall("ReadDeviceRandom2(QString, int, int&)", "D300", 1, value)
        print(ret, value)

enter image description here
info: ReadDeviceRandom2 method, szDeviceList is PLC address, ISize is read data size, IpsData is to store read data

The problem is that method ReadDeviceRandom2 need to pass a int address to it, but python has no int address.So the sample code not working. In this situation how can i pass a pointer to it and read it.

The output:
enter image description here


Then I use other method

import win32com.client

plc = win32com.client.Dispatch("ActUtlType.ActUtlType.1")
plc.ActLogicalStationNumber = 1
plc.open()

value = 0
ret = plc.ReadDeviceRandom2("D300", 1, value)

print(ret, value)

The output, it work fine. enter image description here

jett chen
  • 1,067
  • 16
  • 33
  • what is the output of `print(self.dynamicCall("ReadDeviceRandom2(QString, int, int&)", "D300", 1, 0))`? – eyllanesc Jul 31 '21 at 03:19
  • It always output `0 12`,I try to use win32com.client.Dispatch("ActUtlType.ActUtlType.1") to read, it read fine.But qt method not working. – jett chen Jul 31 '21 at 03:22
  • You may take a look at https://stackoverflow.com/questions/121396/accessing-object-memory-address – Kfcaio Jul 31 '21 at 03:45
  • @Kfcaio The method you specified not working in pyqt system. – jett chen Jul 31 '21 at 03:54
  • Can't you pass the object itself to method? I don't think it's possible to get memory address and deference it at Python level – Kfcaio Jul 31 '21 at 03:58
  • 1
    @Kfcaio The "id" is not the pointer of the python object but is an identifier that python sets to each object. – eyllanesc Jul 31 '21 at 04:21

0 Answers0