mbuesch / pyprofibus

PROFIBUS-DP stack

Home Page:https://bues.ch/a/profibus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] how to read data without write ?

mczerski opened this issue · comments

Hi,

I'm a profibus noob but I'm using this library to communicate with profibus slave based on Anybus-S Profibus card. So this is more of a profibus general question.
The slave expects to receive 1 byte and outputs 16 bytes. What I need is to first read the output data before I do the first write (write data depends on what slave outputs). Is this even possible in profibus ? if Yes, how to do that with pyprofibus ?

Hi. Thanks for your question.
I think you can just set your master-output-data to None in your first iteration.
Hope that helps.

if toSlaveData is not None:

Doesn't the above "if" prevent any data exchange when master data out is None?

No, I don't think so. It should only suppress the sending of the data. The receiving is done here:

for telegram in slave.getRxQueue():

To my understanding the slave will not send anything without any request from master, but as i said i'm profibus noob :) so if master will not send any data how it receive data from slave. Could you clarify ?

I'm not sure what your question is anymore.
There are only two possibilities. Either you send data, or you don't. Both can be done with pyprofibus, as I described.

So, if your slave needs some data, then send some data.

Ok, so how do master read data from slave? To my understanding, master has to SEND data exchange request to do that. But that involves writing to slave as well.

Well, of course the slave may require some input data to send a reply.
I don't know your slave.

But there is no fundamental requirement on the bus level for the master to send data to a slave to be able to receive data from a slave.

I would suggest to simply try it out. It's trivial to not send the first frame.

unfortunately i'm not in possession of real device now and im only using dumny phy to simulate that. I'll try your suggestion when i'll have the device.
The thing i dont understand here is how profibus allow for slave devices to send data whenever they want without collisions ?

They can't send whenever they want. There is bus arbitration.

But pyprofibus does not implement any of that. It does only support single-slave operation. Therefore, there can never be a slave collision.

To be clear: I don't think it is normal behavior for a slave to send data without receiving a request from the master.
Just saying, that in theory, this would be supported by pyprofibus, unless it transmits at the same time as the cyclic master.
And under the premise, that your slave does such things, pyprofibus would support it.

I still think that your slave probably doesn't actually do this behavior.
However, there are many strangely behaving slaves. Therefore, I wouldn't be surprised either.

It does only support single-slave operation.

That is interesting. I did not see such info anywhere in the docs and when looking at code it seemed to me that multiple slaves are supported. There is even an example script example_dummy_twoslaves.py which has two slaves :) What is missing in pyprofibus to be able to handle multiple slaves ?

Regarding the topic issue, I do not believe that the slave I'm working with will send anything without any request - it is designed to work with multiple slaves on one bus.
When reading the profibus documentation I believe that there are two options to solve my issue:

  • DDLM_Data_Exchange request with 0 length input data (but there is explicit check in the code for that case slave.slaveDesc.inputSize == 0 in __runSlave_dataExchange method - what is missing to handle that case in pyprofibus ?)
  • DDLM_RD_Outp request but that is not implemented in pyprofibus

Hm, yes. The pyprofibus software architecture does include all elements needed for multi-slave support.
However, pyprofibus doesn't implement the required bus timing and arbitration mechanisms.

In the branch https://github.com/mbuesch/pyprofibus/tree/bustiming there is an initial attempt to define the relevant timings. But they are not used, yet.

I agree that this should be documented more clearly.

DDLM_Data_Exchange request with 0 length input data [..] what is missing to handle that case in pyprofibus ?)

Well, mostly that I was not aware such a thing exists.
Please feel free to implement support for this.
I would suggest to signal this situation to dp_master.py with a zero length bytes/bytearray as master-out-data. (While 'None' meaning "don't send a telegram at all")