Page 1 of 1

Read/write variables Profibus: memory overlap

Posted: 04 Nov 2021, 17:43
by arpm92

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:
Bildschirmfoto 2021-11-04 um 17.37.58.png
Bildschirmfoto 2021-11-04 um 17.37.58.png (373.59 KiB) Viewed 4463 times
However, when running my class it got the following error:
Bildschirmfoto 2021-11-04 um 17.39.24.png
Bildschirmfoto 2021-11-04 um 17.39.24.png (70.07 KiB) Viewed 4463 times
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:

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"O_diameter_mm_f", "f")"O_perimeter_mm_f", "f")"O_diameter_px_f", "f")"O_perimeter_px_f", "f")"O_px_size_f", "f")

    def measuring_flag(self,prog_status):
        print('measuring status') = prog_status.measuring

    def calibration_flag(self,prog_status):
        print('calibration flag') = prog_status.calibrate

    def write_parameters(self, dimensions, prog_status):
        print('Writing data in module...')
        # Dimensions =  dimensions.diameter_mm =  dimensions.perimeter_mm =  dimensions.diameter_px =  dimensions.perimeter_px =  dimensions.px_size # two decimals taken
        # Program status = prog_status.program_run = prog_status.camera_status = prog_status.background
        print("Data written in module")

    def read_inputs(self):
        print('Reading module inputs...')
        self.inputs.I_capture =
        self.inputs.I_background =
        self.inputs.I_exit =
        self.inputs.I_calibrate =
        self.inputs.I_mask =
        self.inputs.I_send =
        self.inputs.I_PLC_OK =
        self.inputs.I_camera_reset =

        return self.inputs


if __name__ == "__main__":
    from 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


    print("Writing data...")

Re: Read/write variables Profibus: memory overlap

Posted: 04 Nov 2021, 18:00
by nicolaiB
Hi arpm92,

Please have a look at the Python format characters for struct: ... characters. You use float (f) as datatype as the format character which claims 4 bytes in the process image, but from your pictory config is looks like you only reserve a WORD (2 BYTE) for this. Therefore revpimodio2 is not able to this. If you have a float which fits into 2 BYTES, you can try to use e as format character.


Re: Read/write variables Profibus: memory overlap

Posted: 05 Nov 2021, 12:10
by arpm92
Hi NicolaiB,

Thanks a lot. Such a silly mistake from my side. It works fine now.

Best regards,
Alejandro P

Re: Read/write variables Profibus: memory overlap

Posted: 05 Nov 2021, 12:33
by nicolaiB
Hi Alejandro,

Glad to hear that I was able to point you into the right direction. I can't find anything silly about this. It's all about learning :-)