Moderator: RevPiModIO

 
User avatar
arpm92
Topic Author
Posts: 2
Joined: 04 Nov 2021, 17:31

Read/write variables Profibus: memory overlap

04 Nov 2021, 17:43

Hello,

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 1458 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 1458 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
        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...")

Software Engineer at NeurologIQ GmbH <https://www.neurologiq.de/>
 
User avatar
nicolaiB
KUNBUS
Posts: 514
Joined: 21 Jun 2018, 10:33
Answers: 1
Location: Berlin
Contact:

Re: Read/write variables Profibus: memory overlap

04 Nov 2021, 18:00

Hi arpm92,

Please have a look at the Python format characters for struct: https://docs.python.org/3/library/struc ... 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.

Nicolai
 
User avatar
arpm92
Topic Author
Posts: 2
Joined: 04 Nov 2021, 17:31

Re: Read/write variables Profibus: memory overlap

05 Nov 2021, 12:10

Hi NicolaiB,

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

Best regards,
Alejandro P
Software Engineer at NeurologIQ GmbH <https://www.neurologiq.de/>
 
User avatar
nicolaiB
KUNBUS
Posts: 514
Joined: 21 Jun 2018, 10:33
Answers: 1
Location: Berlin
Contact:

Re: Read/write variables Profibus: memory overlap

05 Nov 2021, 12:33

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 :-)

Nicolai

Who is online

Users browsing this forum: No registered users and 2 guests