From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
02-16-2010 09:09 AM
Hi all,
I am writing a program that requires multiple MODBUS read and write at different instances in the program. I am using the MODBUS driver by NI. However, I put a wrapper around the driver, so that it would be more geared toward my application (just a subvi with read, write, and close comm functions). I have a question about different options in initialization and termination for the MODBUS communiction. Please give me some pros and cons for each. Thanks! See below.
1. Initialize MODBUS before each read/write and close MODBUS after each read/write (all in one subvi)
- pro: clean, since the user doesn't need to worry about initializing/closing comm (all in one subvi)
- con: more overhead (not sure how much though), since I am opening/closing comm for every read/write operation.
2. Initialize MODBUS only for the first time that read/write is called without closing the communication after the read/write operation. The user will have to remember to close out the comm at the end of the program.
- pro: only one initialization and termination for the comm in program. Decrease overhead (how much?).
- con: it is easy to accidentally insert a termination in a subvi and forget about it, which create an error, since comm not longer exist. It is easy to forget to close the comm.
Yik
02-17-2010 02:15 PM
02-17-2010 02:51 PM
I generally use what you list as option 2. Intialize at beginning of program. Read/Write as necessary during program. Close at end. Why? Because I am continually reading and writing to update information from the device, so I want less overhead. I make it as part of its own loop and will usually pass commands to it through a queue as part of a producer/consumer architecture.
You say you are worried about a user doing something wrong. But a user should never be touching your underlying code. How is a user going to "accidentally insert a termination ina subVI"? You only need to worry about a programmer doing things correctly. That is likely to be you, or maybe a colleague who works with you. A programmer should be thoroughly testing their code to be sure it works, so even if that person does something wrong, they'll discover and fix it. You shouldn't have to worry about a user doing something wrong because those details should never be visible to the user of your program.
02-17-2010 05:50 PM
I concur with Ravens Fan. Initialize at hte beginning. If you are worried about how other may use the VI(s) that you create, then add very specific usage information to the documentation.
I am a firm believer in fully documenting how something is supposed to be used.
Rob
02-18-2010 09:31 AM
02-19-2010 09:33 AM
Thank you! I agree with you all.