I am not sure it is a good idea to send only on change. One advantage of Modbus is that it is self correcting, meaning that in case the VFD for some reason would lose the set data, it is corrected in the next packet because it is periodically resent. Also, the script does not have any error handling, it assumes that the VFD will receive the message without error. If there is noise or any other disturbance on the line the message will be discarded and the VFD will not act as expected, and if there is just one single message which is sent the VFD will not work as expected. There is no control of the VFD response, so UCCNC has no idea if the message was received or not. This script fills a gap in absence of a real plugin, but it is just a quick and easy solution, not very well designed technically. It works, and that's fine, but there are some issues connected to handling communication this way, so I would not rely on this in any critical or professional situation.
Issues with this solutions are:
- Missing error handling. This is very serious, especially if messages are only sent once.
- Lack of locking COM resource at the start of UCCNC. Continuously opening/closing COM is not a good solution at all.
- Timing. It relies on UCCNC macro loop timing, which is far too fast for this purpose.
- Lack of localization. Will be fixed in next UCCNC release, but for now anyone living outside of USA and/or using other than US English Windows should add these two lines at the beginning of the code:
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US", false);
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false);
If those lines are not added the macro should only work when called as an M-code, not if it is in a macro loop. You and Vmax have not seen this since you are using the "right" Windows. I spent the whole weekend fighting with a short macro which worked well if called manually but failed in macro loop and I could not understand why, so I gave up and sent a mail to Balázs during the evening. He replied pretty fast with those two lines and after adding those lines the macro worked even in macro loop. This will be corrected in the next UCCNC release, but for now it may be necessary to inform users about it.
Those are just some of the things why I can not see this as anything other than a gap filler in waiting for a better plugin. Don't misunderstand me, I am really glad Vmax came up with this solution, but it is not very well written and is not going to be better if the periodic sending is removed, quite the opposite, more complicated and risky to use.
In my opinion, it isn't a good idea at all to use this script to control any VFD which uses Modbus. The built in functions in UCCNC are miles better than this solution, even if this solution works for HY VFD which is not following any Modbus standards. For any device using Modbus as it supposed to be used, this function can be solved in a few lines of code, so even if this may be adjustable for other devices, it is better to use the built in functions for handling datacom and Modbus.