mbuesch / pyprofibus

PROFIBUS-DP stack
https://bues.ch/a/profibus
GNU General Public License v2.0
134 stars 52 forks source link

After slave was reset/reloaded timeout occurs and slave-object changes its state to STATE_INIT, but its fcb remained in previous state ( fcv=1 fcb=0/1 ) #28

Closed Berendej closed 1 year ago

Berendej commented 1 year ago

Because of that master sends Set Prm to reloaded/reset slave with wrong fcv/fcb (fcv=1, fcb=x). Slave expects (fcv=0 fcb=1). Proposal : add

class DpSlaveState(object):
    def setState(self, state, stateTimeLimit=None):
                ...
        if state == self.STATE_INIT:
            **self.fcb.resetFCB()** 
            self.dxCycleRunning = False

In order this to work, attribute DpSlaveState.fcb should be initialized before initial call to setState() in init()

class DpSlaveState(object):
    def __init__(self, master, slaveDesc):
        self.fcb = FdlFCB()
        self.setState(self.STATE_INIT)
mbuesch commented 1 year ago

Hi. Thanks a lot for reporting this.

Yes indeed, this looks like a problem. Fcb handling is not 100% correct in all cases.

Do you want to create a pull request with the proposed change and test it on your device? I will then check if pyprofibus still works correctly on my devices.