Esempio n. 1
0
 def __init__(self):
     self._ifname = HostIfname
     self._pd_thread_stop_event = threading.Event()
     self._ch_thread_stop_event = threading.Event()
     self.pd_thread = 0
     self.ch_thread = 0
     self._actual_wkc = 0
     self._master = pysoem.Master()
     self._master.in_op = False
     self._master.do_check_state = False
     SlaveSet = namedtuple('SlaveSet', 'name product_code config_func')
     self._expected_slave_layout = {
         0: SlaveSet('DM3E-522', self.DM3E_522_PRODUCT_CODE,
                     self.dm3e522_setup)
     }
     self.control_word = 0
     self.target_position = 0
     self.target_vel = 0
     self.target_acc = 0
     self.target_dec = 0
     self.mode_operation = 0
     self.last_error = 0
     self.status_word = 0
     self.mode_display = 0
     self.actual_position = 0
     self.touch_probe_status = 0
     self.touch_probe_value = 0
     self.digital_input = 0
Esempio n. 2
0
def read_sdo_info(ifname):
    master = pysoem.Master()

    master.open(ifname)

    if master.config_init() > 0:

        for slave in master.slaves:
            try:
                od = slave.od
            except pysoem.SdoInfoError:
                print('no SDO info for {}'.format(slave.name))
            else:
                print(slave.name)

                for obj in od:
                    print(
                        ' Idx: {}; Code: {}; Type: {}; BitSize: {}; Access: {}; Name: "{}"'
                        .format(hex(obj.index), obj.object_code, obj.data_type,
                                obj.bit_length, hex(obj.obj_access), obj.name))
                    for i, entry in enumerate(obj.entries):
                        if entry.data_type > 0 and entry.bit_length > 0:
                            print(
                                '  Subindex {}; Type: {}; BitSize: {}; Access: {} Name: "{}"'
                                .format(i, entry.data_type, entry.bit_length,
                                        hex(entry.obj_access), entry.name))

    else:
        print('no slave available')

    master.close()
Esempio n. 3
0
 def __init__(self, ifname):
     self._ifname = ifname
     self._master = pysoem.Master()
     SlaveSet = collections.namedtuple(
         'SlaveSet', 'slave_name product_code config_func')
     self._expected_slave_mapping = {0: SlaveSet('EK1100', self.EK1100_PRODUCT_CODE, None),
                                     1: SlaveSet('EL1018', self.EL1018_PRODUCT_CODE, None),
                                     2: SlaveSet('EL2008', self.EL2008_PRODUCT_CODE, None)}
Esempio n. 4
0
    def __init__(self):
        self._ifname = test_config.ifname
        self._master = pysoem.Master()
        self.SlaveSet = collections.namedtuple(
            'SlaveSet', 'name product_code config_func')

        self.el3002_config_func = None
        self.el1259_config_func = None
        self._expected_slave_layout = None
Esempio n. 5
0
    def __init__(self, adapter_name, BYTE_NUM):
        super().__init__()
        self.adapter = adapter_name

        self.master = pysoem.Master()
        self.master.in_op = False
        self.master.do_check_state = False
        self.master.open(adapter_name)

        self.BYTE_NUM = BYTE_NUM
        print("EtherCAT Master is opened using", adapter_name)
Esempio n. 6
0
 def __init__(self, ifname):
     self._ifname = ifname
     self._pd_thread_stop_event = threading.Event()
     self._ch_thread_stop_event = threading.Event()
     self._actual_wkc = 0
     self._master = pysoem.Master()
     self._master.in_op = False
     self._master.do_check_state = False
     SlaveSet = namedtuple('SlaveSet', 'name product_code config_func')
     self._expected_slave_layout = {0: SlaveSet('EK1100', self.EK1100_PRODUCT_CODE, None),
                                    1: SlaveSet('EL3002', self.EL3002_PRODUCT_CODE, None),
                                    2: SlaveSet('EL1259', self.EL1259_PRODUCT_CODE, self.el1259_setup)}
Esempio n. 7
0
    def __init__(self):
        self._ifname = test_config.ifname
        self._master = pysoem.Master()
        self._master.in_op = False
        self._master.do_check_state = False
        self._proc_thread_handle = None
        self._check_thread_handle = None
        self._pd_thread_stop_event = threading.Event()
        self._ch_thread_stop_event = threading.Event()
        self._actual_wkc = 0

        self.SlaveSet = collections.namedtuple('SlaveSet', 'name product_code config_func')

        self.el3002_config_func = None
        self.el1259_config_func = None
        self._expected_slave_layout = None
Esempio n. 8
0
def read_eeprom_of_first_slave(ifname):
    master = pysoem.Master()
    
    master.open(ifname)
    
    if master.config_init() > 0:
    
        first_slave = master.slaves[2]
        
        for i in range(0, 0x80, 2):
            print('{:04x}:'.format(i), end='')
            print('|'.join('{:02x}'.format(x) for x in first_slave.eeprom_read(i)))
    
    else:
        print('no slave available')
        
    master.close()
Esempio n. 9
0
 def __init__(self, ifname):
     self._ifname = ifname
     self._pd_thread_stop_event = threading.Event()
     self._ch_thread_stop_event = threading.Event()
     self._actual_wkc = 0
     self._master = pysoem.Master()
     self._master.in_op = False
     self._master.do_check_state = False
     SlaveSet = namedtuple('SlaveSet', 'name product_code config_func')
     self._expected_slave_layout = {
         0: SlaveSet('EK1100', self.EK1100_PRODUCT_CODE, None),
         1: SlaveSet('EL4008', self.EL4008_PRODUCT_CODE, None),
         2: SlaveSet('EL4114', self.EL4114_PRODUCT_CODE, None),
         3: SlaveSet('EL3144', self.EL3144_PRODUCT_CODE, None),
         4: SlaveSet('EL2624', self.EL2624_PRODUCT_CODE, None),
         5: SlaveSet('EL2872', self.EL2872_PRODUCT_CODE, self.el2872_setup),
         6: SlaveSet('EL1872', self.EL1872_PRODUCT_CODE, None)
     }
Esempio n. 10
0
def write_file_to_first_slave(ifname, file_path):
    master = pysoem.Master()

    master.open(ifname)

    try:
        if master.config_init() > 0:

            first_slave = master.slaves[0]

            with open(file_path, 'rb') as file:
                file_data = file.read()
                first_slave.foe_write('data.bin', 0, file_data)
        else:
            print('no slave available')
    except Exception as ex:
        raise ex
    finally:
        master.close()
Esempio n. 11
0
import pysoem
import netifaces


def get_nicid(ip):
    interfaces = netifaces.interfaces()
    for interface in interfaces:
        try:
            id = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]["addr"]
            if id == ip:
                return interface
        except:
            pass


nic_id = get_nicid("10.39.0.117")
full_id = str(f"\\Device\\NPF_{nic_id}")
# print(full_id)

master = pysoem.Master()
master.open(full_id)

if master.config_init() > 0:
    device_foo = master.slaves[0]
    device_bar = master.slaves[1]
else:
    print("No device found")
Esempio n. 12
0
def read_values(ifname):

    # Create EtherCAT master instance
    master = pysoem.Master()

    # Open EtherCAT master instance
    master.open(ifname)
    print("EtherCAT master created and started...")

    print("Enumarating slaves")
    print(
        '==========================================================================================='
    )
    # Enumerate and init all slaves
    if master.config_init() > 0:

        # Read state of all slaves at start-up
        master.read_state()

        # Iterate over all slves found
        for slave in master.slaves:
            # Print info on slave
            print('{}:'.format(slave.name))

            # Read state of slave
            print('\tState: {}'.format(hex(slave.state)))

            if (SDO_Info_Check):
                # Check if SDO info is available
                try:
                    od = slave.od
                except pysoem.SdoInfoError:
                    print('\tno SDO info')
                else:
                    for obj in od:
                        print(
                            ' Idx: {}; Code: {}; Type: {}; BitSize: {}; Access: {}; Name: "{}"'
                            .format(hex(obj.index), obj.object_code,
                                    obj.data_type, obj.bit_length,
                                    hex(obj.obj_access), obj.name))
                        for i, entry in enumerate(obj.entries):
                            if entry.data_type > 0 and entry.bit_length > 0:
                                print(
                                    '  Subindex {}; Type: {}; BitSize: {}; Access: {} Name: "{}"'
                                    .format(i, entry.data_type,
                                            entry.bit_length,
                                            hex(entry.obj_access), entry.name))

        print(
            '==========================================================================================='
        )
        # Transition MASTER to SAFEOP_STATE
        # PREOP_STATE to SAFEOP_STATE request - each slave's config_func is called
        print('Transition sytem to SAFEOP_STATE')
        print(
            '==========================================================================================='
        )
        io_map_size = master.config_map()
        print('IOMap-Size: {}'.format(io_map_size))
        print(
            '==========================================================================================='
        )
        # Config DC
        print('Config DC')
        # print(master.config_dc())
        print(
            '==========================================================================================='
        )
        # DC Sync
        print('DC Sync')
        # master.slaves[3].dc_sync(1,1000000000)
        print(
            '==========================================================================================='
        )

        # wait 50 ms for all slaves to reach SAFE_OP state
        if master.state_check(pysoem.SAFEOP_STATE,
                              50000) != pysoem.SAFEOP_STATE:
            master.read_state()
            for slave in master.slaves:
                if not slave.state == pysoem.SAFEOP_STATE:
                    print('{} did not reach SAFEOP 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 SAFEOP state')

        # Iterate over all slves found
        for slave in master.slaves:
            # Print info on slave
            print('{}:'.format(slave.name))

            # Read state of slave
            print('\tState: {}'.format(hex(slave.state)))
        print(
            '==========================================================================================='
        )

        # Send and receive process data to have valid data at all outputs before transistioning to OP_STATE
        print(
            'Send and receive process data to have valid data at all outputs before transistioning to OP_STATE'
        )
        master.send_processdata()
        actual_wkc = master.receive_processdata(2000)
        if not actual_wkc == master.expected_wkc:
            print('incorrect wkc')

        print(
            '==========================================================================================='
        )

        # Transition MASTER to OP_STATE (Slave should follow)
        print('Transistioning system to OP_STATE')
        master.state = pysoem.OP_STATE
        master.write_state()
        print(
            '==========================================================================================='
        )

        master.state_check(pysoem.OP_STATE, 50000)
        if master.state != pysoem.OP_STATE:
            master.read_state()
            for slave in 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')

        # Read state of all slaves at start-up
        master.read_state()

        # Iterate over all slves found
        for slave in master.slaves:
            # Print info on slave
            print('{}:'.format(slave.name))

            # Read state of slave
            print('\tState: {}'.format(hex(slave.state)))
        print(
            '==========================================================================================='
        )

        # ================= SYSTEM OPERATIONAL ==============================

        # Create individual objects
        M_00 = master.slaves[0]
        # M_01 = master.slaves[1]
        # M_02 = master.slaves[2]
        # M_03 = master.slaves[3]
        print('Waiting 3 secs...')
        time.sleep(3)

        for ii in range(50000):
            print(
                '==========================================================================================='
            )
            print(ii)

            master.slaves[3].output = struct.pack('H', 0xAAAA)
            master.send_processdata()
            actual_wkc = master.receive_processdata(2000)
            if not actual_wkc == master.expected_wkc:
                print('incorrect wkc')
            print(master.slaves[3].output.hex())
            print(master.slaves[4].input.hex())

            master.read_state()
            # Iterate over all slves found
            for slave in master.slaves:
                # Print info on slave
                print('{}:'.format(slave.name))

                # Read state of slave
                print('\tState: {}'.format(hex(slave.state)))

            time.sleep(1)

            master.slaves[3].output = struct.pack('H', 0x5555)
            master.send_processdata()
            master.receive_processdata(2000)
            if not actual_wkc == master.expected_wkc:
                print('incorrect wkc')
            print(master.slaves[3].output.hex())
            print(master.slaves[4].input.hex())

            time.sleep(1)

        #for _ in range(5):
        #    # Write to 1010 1010 1010 1010
        #    master.slaves[5].output = struct.pack('H', 0xAAAA)
        #    time.sleep(0.5)
        #    print(master.slaves[6].input)
        #    time.sleep(3)

        #    # Write to 0101 0101 0101 0101‬
        #    master.slaves[5].output = struct.pack('H', 0x5555)
        #    time.sleep(0.5)
        #    print(master.slaves[6].input)
        #    time.sleep(3)

        # Write Analog Output Ch.1 of EL4008 (position 1) to 5V
        # M_01.sdo_write(0x7000, 1, struct.pack('H', 2048))

        time.sleep(1)

        print(
            '==========================================================================================='
        )
        # ================= SHUTDOWN =======================================
        # Transition MASTER to INIT (Slave should follow)
        print('Transistioning system to INIT_STATE')
        master.state = pysoem.INIT_STATE
        master.write_state()

        # Read state of all slaves
        time.sleep(3)

        master.read_state()
        # Iterate over all slves found
        for slave in master.slaves:
            # Print info on slave
            print('{}:'.format(slave.name))

            # Read state of slave
            print('\tState: {}'.format(hex(slave.state)))
        print(
            '==========================================================================================='
        )

    # IF NO SLAVES AVAILABLE !!
    else:
        print('no slave available')

    master.close()