Modbus Spindle Control
-
@gloomyandy said in Modbus Spindle Control:
So I think there might still be a case for having modbus specific read/write operations but I'd be tempted to try and make them more generic ones that simply read/write a bunch of bytes and apply the timing and crc to them, but leave the formatting and decoding of those bytes up to the user in the form of a script?
Looking at the Modbus gcodes again this evening (
M260.1
andM261.1
) and it occurs to me that if the user has the ability to send arbitrary data then there's no distinction between these 2 commands.It seems like this lower-level "raw" behaviour could be achieved with a single gcode that takes raw bytes and expects a particular number of bytes in response, something like this:
; Purely hypothetical request that expects 3 data bytes returned from the 3 byte data request. ; var.modbusRaw would be a vector of bytes M261.3 B3 D{10,12,14} V"modbusRaw"
The underlying implementation would send the station address and deal with CRC, but everything to do with the data would be up to the user.
-
@NineMile the Modbus protocol specifies what response is expected to each command. RRF checks those responses. We could ads a generic command but as the response to such a command would be undefined, we would not be able to check it.
Appending the CRC would only be appropriate if the non-Modbus device used the same CRC rules as Modbus.
-
@dc42 I had a quick look at the linuxCNC HAL code for the VFD that the user over on discord was using. That looks like it uses the same crc16 and seed as modbus but has a different payload. I get the impression from a quick scan of the linuxCNC stuff that this is fairly common, devices which claim to be "modbus" use the modbus signal timing. framing and crc but do not use the modbus register/coil model and associated commands. But I'm certainly no expert on this.
-
@gloomyandy said in Modbus Spindle Control:
@dc42 I had a quick look at the linuxCNC HAL code for the VFD that the user over on discord was using. That looks like it uses the same crc16 and seed as modbus but has a different payload. I get the impression from a quick scan of the linuxCNC stuff that this is fairly common, devices which claim to be "modbus" use the modbus signal timing. framing and crc but do not use the modbus register/coil model and associated commands. But I'm certainly no expert on this.
This is my understanding as well. Theres at least a couple quite common Chinese VFD's which advertise Modbus support but don't follow the modbus-rtu data format - the Huanyang one encountered on Discord seems to be the most common though.
For my own understanding of the RRF codebase, I spent a bit of time looking at how custom spindle control might be implemented using
DoFileMacro
.It seems like adjusting spindle state and rpm would probably need to move to some type of reconciliation based system - where direct calls to
spindle->SetRpm()
andspindle->SetState()
would store values that would then be applied later while spinning aGCodeBuffer
.Applying the settings could be simply setting pin output states for a standard spindle config, like what happens now, or calling
DoFileMacro
to execute a user-provided control system.However - there's areas in the code where spindle control actions appear to be taken from outside any particular
GCodeBuffer
(Tool::Activate()
for example, called from direct LCD requests). These would not map cleanly onto just switching into a spindle control state in the currentGCodeBuffer
where the request was made.My initial thought was to use the Daemon buffer for all spindle control, but a long-running daemon macro could impact spindle control, and vice-versa.
Does it make sense to run the spindle control actions in their own
GCodeBuffer
instance and synchronise it with the other buffers?For example - when
File
buffer callsM3
to start the spindle, we change the pending spindle settings, notify that the spindle needs to be reconciled and then don't allow theFile
channel to continue until theSpindle
buffer reports the settings have been applied?Any thoughts on this appreciated, or if I'm missing any prior art that might indicate a smarter way to do this?
I'm going to be at SMRRF in a couple weekends so I'd be happy to chat about this in person if you're going to be there (David / Andy)?
-
@NineMile I'm also planning to be at SMRRF, probably on the Sunday.
-
@NineMile I've added new command M290.4 in 3.6-dev to support nonstandard transactions that conform only partially to the Modbus specification. See https://docs.duet3d.com/en/User_manual/Reference/Gcodes#m2604-raw-modbus-transaction. It's unlikely that I will have time to do any more work in this area before the 3.6.0 release.