2

I'm recently using the package pyads to connect to Beckhoff TwinCAT3. The reading and writing methods work smoothly. (BTW: TwinCAT3 works fine)

But some error occurs when I try to write a value into an enumeration in TwinCAT3.

I'm using the easiest code to test:

eCtrlMode = plc.write_by_name("GVL_Tset.stTest.eCtrlMode", 1)

eCtrlMode is the instance of an enumeration "E_CtrlMode". The enumeration "E_CtrlMode in" TwinCAT3 as following:

TYPE E_CtrlMode:
(
    Off := 0,
    Auto := 1,
    Reset := 10,
    Manual := 20
);
END_TYPE

Error returns:

TypeError: 'NoneType' object is not callable

Any help, direct or recommended reading would be appreciated :)

Schwarz XU
  • 51
  • 4
  • Sorry, first time being here, the title was false and I can not change it. the question is how to write not how to read. Thanks :) – Schwarz XU Feb 16 '22 at 12:30
  • 2
    It's been solved :) a PLCTYPE property should be added – Schwarz XU Feb 16 '22 at 14:23
  • 2
    Can you add your solution as answer covering what you did to solve and give a quick an example if possible? Just so that if anyone else comes looking they can follow through. – Steve Feb 16 '22 at 17:34

2 Answers2

3

Solution right now: An enumeration in this case is no other than a group of INT values. By using the write_by_name function, the pyads.PLCTYPE_INT property should always be added, otherwise it won't work:

eCtrlMode = plc.write_by_name("GVL_Tset.stTest.eCtrlMode", 1, pyads.PLCTYPE_INT)
Schwarz XU
  • 51
  • 4
1

I came to this question from the question title: "How to read Enumeration values via. pyads"

If anyone get here for the reading of an enum this should work

eCtrlMode = plc.read_by_name("GVL_Tset.stTest.eCtrlMode", pyads.PLCTYPE_INT)
Ola Karlsson
  • 141
  • 1
  • 2
  • 10