Francois Aujard Posted July 18 Report Share Posted July 18 Hello everyone, Is someone can explain me. How works this modbus VI? Two questions : I never used the "in place element structure" what's the point of using this type of structure? Is it better FGV? Is it important connect "Modbus master out" at the end of this structure VI or, if it plug to the input "Modbus master in" it will do the same? This VI use a memory control, how it work ? (three question sorry 😊) Kind regards. François A. Quote Link to comment
cordm Posted July 19 Report Share Posted July 19 The mutex ensures that no one else can perform a read or write while it is locked. Otherwise you could mismatch requests and replies. [W1,R1], [W2,R2] instead of potential W1, W2, R1, R2 You could have it in a non-reentrant VI, but then you would also restrict parallel operations for completely different ports. In this case, in could be wired direclty to out since there are no modifications to it. The mutex will be locked either way. 1 Quote Link to comment
Francois Aujard Posted July 22 Author Report Share Posted July 22 Thank @cordm for your reply. OK, It's the same as a semaphore ? And how you decided what type of value to put in the opening of the VI "New Data Value Reference"? Quote Link to comment
LogMAN Posted July 23 Report Share Posted July 23 On 7/18/2024 at 4:24 PM, Francois Aujard said: I never used the "in place element structure" what's the point of using this type of structure? The In-Place Element (IPE) Structure can be used for memory optimization purposes. It is most useful for large datasets. For example, to modify the value of a cluster in-place (hence the name). Here is a simple example: This is functionally equivalent to using `Unbundle By Name` followed by `Bundle By Name` but it allows the compiler to avoid a memory copy for the OK value and increment it in-place. Note that there are different kinds of border nodes that you can use on the IPE Structure: In Place Element Structure - NI In your example, the Data Value Reference Read / Write Element border nodes are used: Data Value Reference Read / Write Element - NI It allows you to access the value of a DVR in-place so that you can read, modify, and write a new value to the DVR. While the value is being used in one IPE Structure, no other IPE Structure can access it (all other IPE Structures that attempt to access the DVR at the same time are blocked). Since a new DVR is created for each instance of `Modbus master`, this ensures that multiple `Modbus master` can execute in parallel (non-blocking) but for each individual `Modbus master`, only one read or write operation can happen at once (blocking). On 7/18/2024 at 4:24 PM, Francois Aujard said: Is it better FGV? Yes and no. Yes because it is functionally equivalent to a FGV (prevent race conditions when reading/writing the value). No because it is not necessarily global (there may be multiple instances of `Modbus master`, each with its of copy of `mutex`). You can think of it like a FGV that is created for each instance of `Modbus master`. Note, however, that the value of the DVR is never used in your example. It only serves as a synchronization mechanism. 16 hours ago, Francois Aujard said: And how you decided what type of value to put in the opening of the VI "New Data Value Reference"? In this particular case, the data type of the DVR doesn't actually matter. If you have large datasets (for example an array that takes several MB or GB of memory), it is a very good candidate for a DVR so that memory copies can be avoided while you work on it. Especially in 32-bit, where memory is relatively limited. On 7/18/2024 at 4:24 PM, Francois Aujard said: Is it important connect "Modbus master out" at the end of this structure VI or, if it plug to the input "Modbus master in" it will do the same? Since its DVRs are `By Reference`, you don't need to connect `Modbus master out`. It will work even if you split the wire (only the DVR is copied, not the value inside the DVR). 16 hours ago, Francois Aujard said: OK, It's the same as a semaphore ? In this particular case, yes - if you had a different Semaphore for each instance of `Modbus master`. Quote Link to comment
Francois Aujard Posted July 23 Author Report Share Posted July 23 Thank you very much for your explanations @LogMAN 🙏. It's clearer for me. as I understand it I can do that : Synchronization is managed by the mutex, which is called up a IPE structure (accessible as a one-to-one like a FGV). This mutex serves only as a “semaphore”. 😊 31 minutes ago, LogMAN said: This is functionally equivalent to using `Unbundle By Name` followed by `Bundle By Name` but it allows the compiler to avoid a memory copy for the OK value and increment it in-place. What exactly happens during the memory copy if you don't use an IPE structure? Quote Link to comment
LogMAN Posted July 23 Report Share Posted July 23 4 hours ago, Francois Aujard said: as I understand it I can do that : Yes that works. 4 hours ago, Francois Aujard said: What exactly happens during the memory copy if you don't use an IPE structure? It creates a copy of the unbundled value (requires more memory). The IPE Structure avoids this copy by overwriting the original value. This is also explained in the docs: Unbundle / Bundle Elements - NI Please note that my example is simple enough that the compiler can probably optimize it on its own. Here is another example that the compiler cannot optimize on its own because of the Select: Quote Link to comment
Francois Aujard Posted July 24 Author Report Share Posted July 24 22 hours ago, LogMAN said: Yes that works. It creates a copy of the unbundled value (requires more memory). The IPE Structure avoids this copy by overwriting the original value. This is also explained in the docs: Unbundle / Bundle Elements - NI Please note that my example is simple enough that the compiler can probably optimize it on its own. Here is another example that the compiler cannot optimize on its own because of the Select: OK I have read your link. But what happen with the select? Labview create 2 copy : one for the case True and one for the case false and choose after the correct response? Quote Link to comment
ensegre Posted July 24 Report Share Posted July 24 Tools/Profile/Show buffer allocations... Quote Link to comment
LogMAN Posted July 24 Report Share Posted July 24 @ensegre is right. Use the profiler to visualize buffer allocations. It shows black dots where a copy occurs. Quote Link to comment
Francois Aujard Posted July 24 Author Report Share Posted July 24 Ok, thank you very much ! And sorry if my question is stupid..... I learn by myself 🙄 And there are some very good people here whom I trust to answer my questions. 💪 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.