bnjmnp / pysoem

Cython wrapper for the Simple Open EtherCAT Master Library
MIT License
96 stars 37 forks source link

Learning with Beckhoff #94

Closed kxondus closed 1 year ago

kxondus commented 1 year ago

Hi. I'm trying to read and write I/O using Beckhoff EK1100 + EL1004 + EL2622.

After reading almost all the issues (and learning a lot of things...) I can read inputs from EL1004, but no way to write outputs to EL2622. I don't know where can get more info and even, if this module needs to be configured similar as EL3002 of _minimalexample.py . Your help will be apreciated.

bnjmnp commented 1 year ago

Hi. Lets focus on a script that only runs EK1100 + EL2622. I'm not sure if this will work right away because the EL2622's output length is 2 bit, and not 1 byte (8 bit):

    ...
    EL2622_PRODUCT_CODE = 0x0a3e3052
        ...
        self._expected_slave_mapping = {0: SlaveSet('EK1100', self.EK1100_PRODUCT_CODE, None),
                                        1: SlaveSet('EL2622', self.EL2622_PRODUCT_CODE, None)}
            ...
            self._master.state_check(pysoem.OP_STATE, 50000)
            if self._master.state != pysoem.OP_STATE:
                self._master.read_state()
                for slave in self._master.slaves:
                    if not slave.state == pysoem.OP_STATE:
                        print('{} did not reach OP state'.format(slave.name))
                        print('al status code {} ({})'.format(hex(slave.al_status),
                                                              pysoem.al_status_code_to_string(slave.al_status)))
                raise Exception('not all slaves reached OP state')

            el2622 = self._master.slaves[1]
            print(len(el2622.output))

            toggle = True
            try:
                while 1:
                    # free run cycle
                    self._master.send_processdata()
                    self._master.receive_processdata(10000)

                    # lets toggle both outputs every second here
                    if toggle:
                        el2622.output = bytes([0x03])
                    else:
                        el2622.output = bytes([0x00])

                    toggle ^= True
                    time.sleep(1)

            except KeyboardInterrupt:
                # ctrl-C abort handling
                print('stopped')
            ...

Everything else should be taken from the _minimalexample.py. Could you also check whats printed at print(len(el2622.output)), please!

kxondus commented 1 year ago

Hi. First of all, thanks for your reply. The lenght is 1, I had tested it before, and trying your code, I found my error 'cause I was trying to write the output of the EL1004 (newbie error... ). I have several modules of Beckhoff and I want to try with all of them. I think you're doing a great work with this repository. Congrats!. I'll be here reading and learning. Thanks!