AttributeError: can not find io 'HEATER_V'

Moderator: RevPiModIO

Post Reply
in06khattab
Posts: 44
Joined: 24 Jan 2024, 19:07

AttributeError: can not find io 'HEATER_V'

Post by in06khattab »

I tried revpimodio2, but it didn't work. I will eventually want to use a variable name from the vars list.

See the errors and warnings.

Code: Select all

import revpimodio2
import time

rpi = revpimodio2.RevPiModIO()

vars = {
    b"HEATER_V"     : "MBFLOAT",
    b"HEATER_I"     : "MBFLOAT",
    b"HEATER_P"     : "MBFLOAT",
    b"FAN_V"        : "MBFLOAT",
    b"FAN_I"        : "MBFLOAT",
    b"FAN_P"        : "MBFLOAT",
    b"TEMP_SET_PT"  : "MBINT",
    b"TEMP_PV"      : "MBINT",
    b"OVER_HEAT"    : "MBINT",
    b"MF1_TEMP"     : "AI/1000",  
    b"MF1_FLOW"     : "AI/1000",
    b"MF2_TEMP"     : "AI/1000", 
    b"MF2_FLOW"     : "AI/1000",
    b"FAN_CP"     : "AI",
    b"FAN_SP"     : "AI/100",
    b"TEMP_MON"     : "AI/100",
    b"RPI_TEMP"     : "SYSINT",
    }
print(rpi.io.HEATER_V_HB.value)
print(rpi.io.HEATER_V_LB.value)
#for varname,type in vars.items():
        
        #print("var name: ", varname, ", type: ", type) 

I just get Zeros with a lot of warnings:

Code: Select all

pi@RevPi17663:~ $ python3 test.py
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'HEATER_V_STATUS_RESET', as an io already exists at the address '358 Bit 0'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'HEATER_I_STATUS_RESET', as an io already exists at the address '358 Bit 1'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'HEATER_P_STATUS_RESET', as an io already exists at the address '358 Bit 2'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'TEMP_PV_STATUS_RESET', as an io already exists at the address '358 Bit 3'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'TEMP_SET_PT_STATUS_RESET', as an io already exists at the address '358 Bit 4'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'FAN_V_STATUS_RESET', as an io already exists at the address '358 Bit 5'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'FAN_I_STATUS_RESET', as an io already exists at the address '358 Bit 6'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'FAN_P_STATUS_RESET', as an io already exists at the address '358 Bit 7'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'OVER_HEAT_STATUS_RESET', as an io already exists at the address '359 Bit 0'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'Action_Status_Reset_10', as an io already exists at the address '359 Bit 1'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'Action_Status_Reset_11', as an io already exists at the address '359 Bit 2'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'Action_Status_Reset_12', as an io already exists at the address '359 Bit 3'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'Action_Status_Reset_13', as an io already exists at the address '359 Bit 4'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'Action_Status_Reset_14', as an io already exists at the address '359 Bit 5'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'Action_Status_Reset_15', as an io already exists at the address '359 Bit 6'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/io.py:303: Warning: ignore io 'Action_Status_Reset_16', as an io already exists at the address '359 Bit 7'. this can be caused by an incorrect pictory configuration.
  Warning,
/usr/lib/python3/dist-packages/revpimodio2/modio.py:426: Warning: equal device name 'RevPi AIO' in pictory configuration. you can access this devices by position number .device[30|31] only!
  Warning,
0
0


This is the output of piTest:

pi@RevPi17663:~ $ piTest -r HEATER_V_HB
2 Byte-Value of HEATER_V_HB: 17262 dez (=436e hex)
2 Byte-Value of HEATER_V_HB: 17262 dez (=436e hex)
2 Byte-Value of HEATER_V_HB: 17262 dez (=436e hex)
User avatar
nicolaiB
KUNBUS
Posts: 916
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: AttributeError: can not find io 'HEATER_V'

Post by nicolaiB »

Hi

The warnings are a hint for duplicate variable / devices names.

In order to get values from the process image you have to use revpimodio with autorefresh=True or call the read_procimg() method. More details can be found in the API documentation or one the the linked examples:

https://revpimodio.org/en/doc2/

Nicolai
in06khattab
Posts: 44
Joined: 24 Jan 2024, 19:07

Re: AttributeError: can not find io 'HEATER_V'

Post by in06khattab »

Thanks for replying. I could not find any documentation about read_procimg.
I tried with autorefresh and sometimes when I re-run the script, I get zero instead of the correct number. However piTest -r HEATER_V_HB always gives the correct number.

Is there anything I should do to remove the warnings?

Do you know if it is possible to combine two modbus bytes?
2024-01-25_18-27.png
This is the old code implementation for handling two bytes:

Code: Select all

 high_byte = read_bytes((var_name + b"_HB"))
        low_byte = read_bytes((var_name + b"_LB"))

        try:
            value = (struct.unpack('f', low_byte + high_byte ))[0]
        except:
            print("unpack error")
            value = 0
        
        value = round(value,1)
This is the value that is returned.
low_byte 6554
high_byte 17263

By combining the two, the old code used to get 230
User avatar
nicolaiB
KUNBUS
Posts: 916
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: AttributeError: can not find io 'HEATER_V'

Post by nicolaiB »

readprocimg is also mentioned in the link above.

revpimodio2 provides the handy function replace_io, which can create an virtual IO based on the provided data type. In your example the definition would look something like this:

Code: Select all

import revpimodio2
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.io.HEATER_V_HB.replace_io('heater_v', 'H', byteorder='little')

print(f"value={rpi.io.heater.value}")
Change byteorder and format string according to your data.

For more details see https://revpimodio.org/en/doc2/io/#replace_io and https://docs.python.org/3/library/struc ... characters
in06khattab
Posts: 44
Joined: 24 Jan 2024, 19:07

Re: AttributeError: can not find io 'HEATER_V'

Post by in06khattab »

Hi,

Unfortunately I am getting a syntax error. Also will this combine the high and low bytes?

Code: Select all

pi@RevPi17663:~ $ python3 test.py
  File "test.py", line 15
    print(f"value={rpi.io.heater.value}")
                                       ^
SyntaxError: invalid syntax

Code: Select all

import revpimodio2
import time
import struct

rpi = revpimodio2.RevPiModIO(autorefresh=True)


vars = {
    "HEATER_V_HB"     : "MBFLOAT",
    "HEATER_V_LB"     : "MBFLOAT",
    }
#low_byte=rpi.io.HEATER_V_LB.value
#print("low_byte", low_byte)
rpi.io.HEATER_V_HB.replace_io('heater_v', 'H', byteorder='little')
print(f"value={rpi.io.heater.value}")

User avatar
nicolaiB
KUNBUS
Posts: 916
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: AttributeError: can not find io 'HEATER_V'

Post by nicolaiB »

Looks like you're using an older image with python3, which does not support f strings. Try:

Code: Select all

import revpimodio2
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.io.HEATER_V_HB.replace_io('heater_v', 'H', byteorder='little')
print("value=" + str(rpi.io.heater_v.value))
in06khattab
Posts: 44
Joined: 24 Jan 2024, 19:07

Re: AttributeError: can not find io 'HEATER_V'

Post by in06khattab »

Hi,
Thanks for your help, but I am not able to read the expected data. I have tried all of the formats e.g. float, double etc.
I am not able to unpack the bytes as a float.
Page 9 describes this: https://cdn.shopify.com/s/files/1/0558/ ... 1659968620

The replace_io function does all of this in the background but it is not clear what it is doing.

This is the output from pictory :
I also tried swapping the high and low bytes in Pictory, but it did not work.
2024-01-26_15-39.png

Code: Select all

rpi.io.HEATER_V_LB.replace_io('heater_v', 'H', byteorder='little')
value=19661


Code: Select all

rpi.io.HEATER_V_LB.replace_io('heater_v', 'H', byteorder='big')
value=39449


Code: Select all

rpi.io.HEATER_V_LB.replace_io('heater_v', 'f', byteorder='little')
value=5.510185821418046e-41


Code: Select all

rpi.io.HEATER_V_LB.replace_io('heater_v', 'f', byteorder='big')
value=-3.163965843015331e-23


I would expect 230.
The old code read the data as bytes, then unpacked them. How do I transition to this new code?

Code: Select all

high_byte = read_bytes((var_name + b"_HB"))
low_byte = read_bytes((var_name + b"_LB"))
 value = (struct.unpack('f', low_byte + high_byte ))[0]
Last edited by in06khattab on 26 Jan 2024, 17:08, edited 1 time in total.
in06khattab
Posts: 44
Joined: 24 Jan 2024, 19:07

Re: AttributeError: can not find io 'HEATER_V'

Post by in06khattab »

Actually I managed to make it work. Is there a more elegant method using the RevPiModIO library?

Code: Select all

vars = {
    "HEATER_V"     : "MBFLOAT",
    }


for varname,type in vars.items():
    high_byte = rpi.io[varname+"_HB"].value
    low_byte = rpi.io[varname+"_LB"].value
    value = (struct.unpack('f', low_byte.to_bytes(2,byteorder='little') + high_byte.to_bytes(2, byteorder='little') ))[0]
    print(value)


Value: 238.39999389648438
User avatar
nicolaiB
KUNBUS
Posts: 916
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: AttributeError: can not find io 'HEATER_V'

Post by nicolaiB »

Try to set the wordorder

Code: Select all

import revpimodio2
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.io.HEATER_V_HB.replace_io('heater_v', 'H', byteorder='little', wordorder='little')
print("value=" + str(rpi.io.heater_v.value))
or

Code: Select all

import revpimodio2
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.io.HEATER_V_HB.replace_io('heater_v', 'H', byteorder='little', wordorder='big')
print("value=" + str(rpi.io.heater_v.value))
Post Reply