Truncating M308 report?
-
Is it possible to shorten the response of the M308 command? I am using the response within Openpnp to confirm and capture the reading. OpenPnp cant seem to parse the response even tho RegEx tests can. I believe the problem is the RRF3.3 response is too verbose;
"Sensor 0 (Pressure_1) type Linear analog using pin temp0, reading 4056.3, last error: success, unfiltered, range 0.0 to 4095.0
ok"
Ill I need is, reading 4056.3. I there a way to request only the reading or a different Command?
Thanks
Wayne -
@wayneosdias try this:
echo sensors[0].lastReading
or, if you would rather use a M-command and parse a JSON response:
M409 K"sensors.analog[0].lastReading"
-
@dc42 @dc42 said in Truncating M308 report?:
echo sensors[0].lastReading
@dc42 Thanks, I tried both commands;
echo sensors[0].lastReading
yeilds error from RRF3.3
2022-01-23 08:10:02.377 GcodeAsyncDriver DEBUG: serial://COM11 commandQueue.offer(echo sensors[0].lastReading, 5000)... 2022-01-23 08:10:02.377 GcodeAsyncDriver$WriterThread TRACE: [serial://COM11] >> echo sensors[0].lastReading 2022-01-23 08:10:02.377 GcodeDriver$ReaderThread TRACE: [serial://COM11] << Error: **meta command: object is not an array** 2022-01-23 08:10:02.377 GcodeDriver$ReaderThread TRACE: [serial://COM11] << ok
Next
M409 K"sensors.analog[0].lastReading"
Works, though still a bit long
2022-01-23 08:17:35.444 GcodeAsyncDriver DEBUG: serial://COM11 commandQueue.offer(M409 K"sensors.analog[0].lastReading", 5000)... 2022-01-23 08:17:35.444 GcodeAsyncDriver$WriterThread TRACE: [serial://COM11] >> M409 K"sensors.analog[0].lastReading" 2022-01-23 08:17:35.444 GcodeDriver$ReaderThread TRACE: [serial://COM11] << {"key":"sensors.analog[0].lastReading","flags":"","result":187.0} 2022-01-23 08:17:35.444 GcodeDriver$ReaderThread TRACE: [serial://COM11] << ok
In the end M308 and M409 in RRF3.3 both provide the necessary values, and I'm able to parse the desired string with a regex tool outside of Openpnp. So I'm leaning towards Openpnp not being set correctly. Im going to reach out to the Openpnp group.
For completeness here is what I have set in Openpnp, that do work in a regex tool outside of OpenPnp
M409
ACTUATOR_READ_COMMAND = M409 K"sensors.analog[0].lastReading" ACTUATOR_READ_REGEX = "result":(?<Value>-?\d+\.\d+)
M308
ACTUATOR_READ_COMMAND = M308 S0 ACTUATOR_READ_REGEX = reading (?<Value>-?\d+\.\d+)
Setup;
Board: Duet 3 MB6HC (MB6HC)
Firmware: RepRapFirmware for Duet 3 MB6HC 3.3 (2021-06-15)Thanks for Help
Wayne -
@dc42
Success! Thanks to Tony at OpenPnp group advised to conform regex to Java 8 needs to whole string and needs to be bookended with .*ACTUATOR_READ_COMMAND = M409 K"sensors.analog[0].lastReading ACTUATOR_READ_REGEX = .*"result":(?<Value>-?\d+\.\d+) .*
yeilds success
2022-01-23 13:52:53.898 GcodeAsyncDriver DEBUG: serial://COM11 commandQueue.offer(M409 K"sensors.analog[0].lastReading", 5000)... 2022-01-23 13:52:53.898 GcodeAsyncDriver$WriterThread TRACE: [serial://COM11] >> M409 K"sensors.analog[0].lastReading" 2022-01-23 13:52:53.898 GcodeDriver$ReaderThread TRACE: [serial://COM11] << {"key":"sensors.analog[0].lastReading","flags":"","result":252.5} 2022-01-23 13:52:53.898 GcodeDriver$ReaderThread TRACE: [serial://COM11] << ok 2022-01-23 13:52:53.898 GcodeDriver TRACE: actuatorRead response: {"key":"sensors.analog[0].lastReading","flags":"","result":252.5} 2022-01-23 13:52:53.898 ReferenceActuator DEBUG: VacSense1.read(): 252.5
-
@wayneosdias I'm sorry, my first suggestion should have been:
echo sensors.analog[0].lastReading