python 3.10 table variable value to easymodbus register address Windows 10 64bits

Viewed 11

Dear community I am trying to pass the data from a table to a variable address, I am getting the data from the table through a select, it is being stored in result and I am assigning that result to the register address I want to read, this is my code:

#!/usr/bin/env python
'''
Created on 12.09.2016

@author: Stefan Rossmann
'''

# @UnresolvedImport
from easymodbus.modbusClient import *
# @UnresolvedImport

import psycopg2

conn = psycopg2.connect(
    user = "myuser",
    password = "mypasswd",
    host = "localhost",
    port = "5432",
    database = "mydb"
)

cur = conn.cursor()

cur.execute("SELECT a_data FROM my_table WHERE a_data = %s", [3])
result = cur.fetchone()[0]

modbusClient = ModbusClient('127.0.0.1', 502)
modbusClient.connect()

discreteInputs = modbusClient.read_discreteinputs(result, 1)
print (discreteInputs)

modbusClient.close()

print(result)

cur.close()

however when executing I get the following error message.

Traceback (most recent call last):
  File "C:\Users\Pruebas\Downloads\EasyModbus\EasyModbusPy\easymodbus\asignar.py", line 26, in <module>
    result = cur.fetchone()[0]
TypeError: 'NoneType' object is not subscriptable

Thanks for your time

0 Answers
Related