Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] how to read data without write ? #32

Open
mczerski opened this issue Sep 1, 2023 · 12 comments
Open

[Question] how to read data without write ? #32

mczerski opened this issue Sep 1, 2023 · 12 comments
Labels

Comments

@mczerski
Copy link

mczerski commented Sep 1, 2023

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 ?

@mbuesch
Copy link
Owner

mbuesch commented Sep 1, 2023

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

@mczerski
Copy link
Author

mczerski commented Sep 1, 2023

if toSlaveData is not None:

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

@mbuesch
Copy link
Owner

mbuesch commented Sep 1, 2023

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():

@mczerski
Copy link
Author

mczerski commented Sep 1, 2023

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 ?

@mbuesch
Copy link
Owner

mbuesch commented Sep 1, 2023

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.

@mczerski
Copy link
Author

mczerski commented Sep 1, 2023

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.

@mbuesch
Copy link
Owner

mbuesch commented Sep 1, 2023

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.

@mczerski
Copy link
Author

mczerski commented Sep 1, 2023

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 ?

@mbuesch
Copy link
Owner

mbuesch commented Sep 1, 2023

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.

@mbuesch
Copy link
Owner

mbuesch commented Sep 1, 2023

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.

@mczerski
Copy link
Author

mczerski commented Sep 4, 2023

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

@mbuesch
Copy link
Owner

mbuesch commented Sep 4, 2023

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants