-
Notifications
You must be signed in to change notification settings - Fork 14
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
Move modbus code to separate folder? #2
Comments
The code can be moved to a separate submodule, but the code has to be changed a bit in order to support more than one client as there are two callbacks that is bound when the Huanyang plugin is initialized. I guess these has to be per transaction instead, to be added to the queue_entry_t struct? |
I wonder, could they be chained, and then each client could just ignore if not for it's own modbus slave address? (the rx_exception callback would also need the msg passed back to it for context). |
They could, but IMO adding the callbacks to each message is cleaner - and I can get rid of the public modbus_stream_t struct. That would allow access to the modbus code from custom my_plugin.c implementations. Here is my suggestion (I have not tested the code): What do you think? |
Thanks, will try and test that tomorrow.. |
Hi, afraid is not working just yet.. Is faulting - I think because packet is set to NULL by the ModBus_AwaitReply case in modbus_poll(), before the ModBus_Timeout and ModBus_Exception cases are reached in modbus_send(). Checking that packet is non null removes the faults, but then the timeouts and exceptions never actually do anything useful. I then tried commenting out the packet = NULL in ModBus_AwaitReply instead, as it seems this is done after the callbacks are processed in modbus_send() anyway - but I must be missing something else in the logic, as the regular messages from spindleGetState() just stop.. Cheers, Jon. |
Actually, this seems to work (I had been overlooking the different code paths for sync and async packets)..
|
Do you think this is an ok way to implement support for multiple clients then? |
I only got as far as testing with the Huanyang plugin yesterday. I'll port my proof of concept control panel plugin across today, and try them both together.. |
Hmm, have them both working independently, but no luck if enabled together.. Thinking perhaps the modbus & serial initialisations should just be called once from driver.c?
|
Sure - I'll split the modbus_init() to a separate call. Your panel_init() should be without any parameters. |
Thanks, can confirm it is working well with two clients now. Have noticed that the Huanyang VFD appears to intermittently stop responding with a silence of less than ~6ms, leading to timeouts/spindle alarms. My test environment is running at 19200 baud with cheap auto switching RS485 modules, however my modbus slave device (STM32 BlackPill board with FreeMODBUS stack) is reliable at the default 2ms silence, so will blame the Huanyang implementation for now. :) Also uncovered a small bug while troubleshooting the above - the configured silence timeout was not always respected, due to a 16/32 bit comparison with the ms ticks counter - will confess I scratched my head for some time over this!
Cheers, Jon. |
Great, I appreciate the testing you are doing. Perhaps getting closer remove the "experimental" label from the plugin?
Version 1 of the Huanyang protocol is not Modbus compliant in how the messages are made up so I am not surprised. Should the silence delay be made configurable or should we just increase it? Here is a new version of the code that I believe is closer to how the final version should be: I have incorporated your bug fixes in this. In driver.c initialization will be like this:
I have added a call for checking if the Modbus plugin managed to install itself: Note that the Modbus plugin is not fully configured before settings has been read and acted upon, for that the call Finally the
|
Thanks, I think I've given it a good testing, but I do have a smaller Huanyang VFD on it's way from China (currently testing with an old 4kW that I had here already). When the new one arrives, I'll compare the silence timeouts and see whether they're consistent. Could then maybe increase the default modbus timeouts to something more suitable if SPINDLE_HUANYANG is defined? Have noticed that the very first command on startup always ends up in a timeout, will dig into that also... |
That initial error was when trying to read the configured speed at 50Hz, was just requesting the wrong register number and getting a NAK. (The default value for rpm_max50 matched the common Chinese spindles, so displayed RPMs were still as expected)..
That makes me wonder though. This only gets called via huanyang_settings_changed() at startup, so if the spindle isn't responding immediately, then there's no way to get this value without power cycling the board (which is probably tricky once in a cabinet). Perhaps should be called after a reset also? |
Yes, I guess that would be ok.
Good idea, I guess you have seen how I do that in the modbus code so you can add it? The original reset handler should be called first so that the modbus code is ready to accept new commands. |
Yep sure, will do.. |
This seems to work fine. One strange thing though - if the VFD is not responding (i.e. powered off for testing), then no spindle alarm gets raised from the modbus timeout when called from the reset path. rx_exception() gets called, but not raise_alarm()?
|
This is due to the rt command queue beeing emptied on a warm reset in protocol.c:
During a cold start alarms should only be raised after everything is up and running, that is why I queued it. Since |
Hi Terje, how would you feel about moving the modbus files out of here to their own folder? I think this would be cleaner for any future plugins that also use modbus..
Don't think I can make a pull request for this, as it would need a new submodule - but changes would be (1) creating a new 'modbus' source folder in STM32CubeIDE, (2) moving the two modbus.* files, and (3) changing the include path in huangyang.h as follows;
I have a Huangyang VFD here on the bench that I'm testing with, using the STM32F4xx driver. (My interest here is that I'm picking up on my modbus control panel & plugin work again).
Regards, Jon.
The text was updated successfully, but these errors were encountered: