I am currently facing a problem while configuring the RevPi and working with RevPiModIO in Python 3.7.
I have created a class which initialize itself and set some of the variables to float type (as seen here: viewtopic.php?t=1576).
My configuration in PiCtory is the following: However, when running my class it got the following error: Is there any step I missed as to solve the problem and avoid the memory overlap?
Note: I am not quite experienced working with the RevPi and I did not find further information in the forum.
Thanks in advance!
My code would be:
Code: Select all
import revpimodio2 as revpi2
class RevPi_Inputs:
def __init__(self) -> None:
self.I_capture = None
self.I_background = None
self.I_exit = None
self.I_calibrate = None
self.I_mask = None
self.I_send = None
self.I_PLC_OK = None
self.I_camera_reset = None
class RevPi:
# initialize rev py
def __init__(self) -> None:
self.inputs = RevPi_Inputs()
self.rpi = revpi2.RevPiModIO(autorefresh= True, monitoring=False, syncoutputs=True, debug=False, replace_io_file=None, shared_procimg=False)
# redefine outputs as float type
self.rpi.io.O_diameter_mm.replace_io("O_diameter_mm_f", "f")
self.rpi.io.O_perimeter_mm.replace_io("O_perimeter_mm_f", "f")
self.rpi.io.O_diameter_px.replace_io("O_diameter_px_f", "f")
self.rpi.io.O_perimeter_px.replace_io("O_perimeter_px_f", "f")
self.rpi.io.O_px_size.replace_io("O_px_size_f", "f")
def measuring_flag(self,prog_status):
print('measuring status')
self.rpi.io.O_measuring_flag = prog_status.measuring
def calibration_flag(self,prog_status):
print('calibration flag')
self.rpi.io.O_calibrate = prog_status.calibrate
def write_parameters(self, dimensions, prog_status):
print('Writing data in module...')
# Dimensions
self.rpi.io.O_diameter_mm_f.value = dimensions.diameter_mm
self.rpi.io.O_perimeter_mm_f.value = dimensions.perimeter_mm
self.rpi.io.O_diameter_px_f.value = dimensions.diameter_px
self.rpi.io.O_perimeter_px_f.value = dimensions.perimeter_px
self.rpi.io.O_px_size_f.value = dimensions.px_size # two decimals taken
# Program status
self.rpi.io.O_program_run.value = prog_status.program_run
self.rpi.io.O_camera_status.value = prog_status.camera_status
self.rpi.io.background = prog_status.background
print("Data written in module")
def read_inputs(self):
print('Reading module inputs...')
self.inputs.I_capture = self.rpi.io.I_capture.value
self.inputs.I_background = self.rpi.io.I_background.value
self.inputs.I_exit = self.rpi.io.I_exit.value
self.inputs.I_calibrate = self.rpi.io.I_calibrate.value
self.inputs.I_mask = self.rpi.io.I_mask.value
self.inputs.I_send = self.rpi.io.I_send.value
self.inputs.I_PLC_OK = self.rpi.io.I_PLC_OK.value
self.inputs.I_camera_reset = self.rpi.io.I_camera_reset.value
return self.inputs
#####
if __name__ == "__main__":
from ...data.object_dimensions import Dimensions
dimensions = Dimensions()
rvpi = RevPi()
dimensions.diameter_mm = 10
dimensions.perimeter_mm = 100
dimensions.diameter_px = 23
dimensions.perimeter_px = 230
dimensions.px_size = 5
rvpi.write_parameters(dimensions)
print("Writing data...")