-
Notifications
You must be signed in to change notification settings - Fork 113
Open
Description
I have some Tc2_System.T_MaxString variables I want to read and write. With plc.read_by_name() / plc.write_by_name() this works only if the plc_datatype is specified. Otherwise I get an exception. Similar issue when using plc.get_symbol(). There I have to manually set the plc_type of the symbol, in order to get it to work.
Because I have to read/write various different variable types dynamically, I would prefer not to specify the plc_datatype / symbol.plc_type manually. Is there a way to fix this?
Here some details:
import pyads
plc = pyads.Connection('199.4.42.250.1.1', pyads.PORT_TC3PLC1)
plc.open()
symbol_name_string = 'MyStringValue'
plc.read_by_name(symbol_name_string, plc_datatype=pyads.PLCTYPE_STRING) # works
plc.read_by_name(symbol_name_string) # TypeError: 'NoneType' object is not callableTraceback (most recent call last):
File "c:\Temp\pyads_string_test.py", line 9, in <module>
plc.read_by_name(symbol_name_string) # TypeError: 'NoneType' object is not callable
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\pyads\connection.py", line 546, in read_by_name
return adsSyncReadByNameEx(
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\pyads\pyads_ex.py", line 1216, in adsSyncReadByNameEx
value = adsSyncReadReqEx2(
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\pyads\pyads_ex.py", line 845, in adsSyncReadReqEx2
data = data_type()
TypeError: 'NoneType' object is not callable
symbol = plc.get_symbol(symbol_name_string, plc_datatype=pyads.PLCTYPE_STRING)
print(f'{symbol.symbol_type}') # Tc2_System.T_MaxString
print(f'{symbol.plc_type}') # None
print(f'symbol {symbol_name_string} = {symbol.read()}') # TypeError: 'NoneType' object is not callable
symbol = plc.get_symbol(symbol_name_string)
symbol.plc_type = pyads.PLCTYPE_STRING
print(f'symbol {symbol_name_string} = {symbol.read()}') # worksMetadata
Metadata
Assignees
Labels
No labels