bnjmnp / pysoem

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

Can't decode slave information #81

Open MarcelloDavis opened 1 year ago

MarcelloDavis commented 1 year ago

Hello,

i was just trying to simply read out the slave device's name via sdo_read. The lines of code I used are:

import sys
import pysoem
import struct

master = pysoem.Master()
master.open("eth1")

EL1809 = master.slaves[1]
device_name = EL1809.sdo_read(0x1008, 0).decode('utf-8')

However, when I ran these lines of code, the output says: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte Do you have any guesses as to what might be the problem?

bnjmnp commented 1 year ago

Hi @MarcelloDavis,

Did you try to call master.config_init() prior to accessing the device? This is required to establish any communication.

mithathacioglu commented 1 year ago

Just try sleep() func. after "EL1809 = master.slaves[1]" after this. Cause if u open ethercat com,just register is going out.

for this solution.sleep() function.3 sec is enough i tried.

SukritMachineTools commented 1 year ago

try this:

`import pysoem
import ctypes
master = pysoem.Master()

master.open('eth1')

if master.config_init() > 0:
    for device in master.slaves:
        print(f'Found Device {device.name}')
        pav=device.sdo_read(0x1008, 0).decode('unicode_escape')
        pav2 = ctypes.c_uint32.from_buffer_copy(device.sdo_read(index=0x6064, subindex=0x00)).value
        print(pav)
        print(pav2)`

replace index with register address you want to read.