What is the correct syntax for string operations?



  • This is the line I want to display on the screen.
    M291 P"auto bed levelling using 3 Z motors completed deviation " ^ move.calibrationDeviation.deviation ^ "mm"
    this is the error
    Error: Bad command: M291 P"auto bed levelling using 3 Z motors completed deviation " ^ move.calibrationDeviation.deviation ^ "mm"
    and then I thought that it needed a ","
    M291 P"auto bed levelling using 3 Z motors completed deviation ", ^ move.calibrationDeviation.deviation ^ "mm"
    this is the error
    Error: Bad command: M291 P"auto bed levelling using 3 Z motors completed deviation ", ^ move.calibrationDeviation.deviation ^ "mm"
    Not knowing much about code, I am stuck.


  • administrators

    When using an expression in place of a parameter, the expression must be enclosed in { }. Example:

    M291 P{"2+2 is " ^ 2+2}



  • @dc42, thank you for your response. I still cant get this to work, your example works but my line fails with
    "Error: Bad command: M291 P{"Repeating calibration, Deviation is " ^ move.calibrationDeviation.deviation ^ "mm"}

    M291 P{"2+2 is " ^ 2+2}
    M291 P{"Repeating calibration, Deviation is " ^ move.calibrationDeviation.deviation ^ "mm"}

    Do I need to add something when using an object?



  • Sorry, just to let you know I am using Firmware 3.01-beta2


  • administrators

    @appjaws said in What is the correct syntax for string operations?:

    M291 P{"Repeating calibration, Deviation is " ^ move.calibrationDeviation.deviation ^ "mm"}

    When I run that, the command works (the message box pops up) BUT it also reports bad command. Whereas:

    M291 P{"2+2 is " ^ 2+2}

    doesn't report an error. I will look into it.



  • Interesting.
    I get both the expected popup and an error.
    screenshote.jpg

    Firmware version
    version.jpg



  • I am using a Duet2 with expansion board Duex5 connected by ethernet
    M115
    FIRMWARE_NAME: RepRapFirmware for Duet 2 WiFi/Ethernet FIRMWARE_VERSION: 3.01-beta2 ELECTRONICS: Duet Ethernet 1.02 or later + DueX5 FIRMWARE_DATE: 2020-01-23b1

    This is the console output

    27/01/2020, 07:48:50
    M98 P"0:/macros/Conditional/Auto_Bed_Levelling.g"
    Leadscrew adjustments made: -0.029 0.021 0.005, points used 3, (mean, deviation) before (-0.019, 0.015) after (-0.000, 0.000)
    iteration = 0
    Repeating calibration because initial deviation (0.015mm) must be < 0.01
    and (0.000mm) must be within 0.005 of initialDeviation
    Error: Bad command: M291 P{"Repeating calibration, Deviation is " ^ move.calibrationDeviation.deviation ^ "mm"}

    This is my macro

    ; Conditional auto bed levelling using 3 Z motors

    M561 ; clear any existing bed transforms

    ;if heat.heaters[0].current <60
    M291 P"Preheating to bed to 65 and nozzle to 195 for accurate probing"
    M140 S60 ; Set bed temperature to 60
    M116 ; waiting for bed to reach temperature
    if heat.heaters[0].current <65 || heat.heaters[1].current <190
    M140 S65 ; Set bed temperature to 65
    G10 S195 ; Set current tool temperature to 195C
    M116 ; waiting for bed and nozzle to reach temperature

    ; If the printer hasn't been homed, home it
    if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
    G28

    G1 Z5

    ;Run an initial 3-point Probe

    M291 P"auto bed levelling using 3 Z motors started"

    M98 P"0:/macros/Conditional/bedlevel.g"

    while true
    if iterations = 5
    abort "Too many auto calibration attempts"
    echo "iteration = ", iterations
    if move.initialDeviation.deviation < 0.01
    if move.calibrationDeviation.deviation < move.initialDeviation.deviation + 0.005
    if move.calibrationDeviation.deviation > move.initialDeviation.deviation - 0.005
    break
    echo "Repeating calibration because initial deviation (" ^ move.initialDeviation.deviation ^ "mm) must be < 0.01"
    echo "and (" ^ move.calibrationDeviation.deviation ^ "mm) must be within 0.005 of initialDeviation"
    M291 P{"Repeating calibration, Deviation is " ^ move.calibrationDeviation.deviation ^ "mm"}
    M291 P{"2+2 is " ^ 2+2}
    M98 P"0:/macros/Conditional/bedlevel.g"

    echo "Auto calibration successful, deviation", move.calibrationDeviation.deviation ^ "mm"
    echo "Auto calibration successful, initialDeviation", move.initialDeviation.deviation ^ "mm"
    M291 P{"2+2 is " ^ 2+2}
    ;M291 P{"auto bed levelling using 3 Z motors completed, Initial Deviation is " ^ move.initialDeviation.deviation ^ "mm"}
    ;M291 P{"auto bed levelling using 3 Z motors completed, Deviation is " ^ move.calibrationDeviation.deviation}

    M140 S0 ; Set bed temperature to 0C
    G10 S0 ; Set current tool temperature to 0C
    G1 X150 Y100; Move to bed centre
    G30; reset Z0

    G1 X50 Y230 F24000 ; move the head to park
    M291 P"auto bed levelling using 3 Z motors completed"


  • administrators

    I found the problem and it will be fixed in the next internal build. Meanwhile, here is the workaround. Where an object model string starts with the letter g, m or t, make sure that the character immediately before it isn't a space or tab. The following both work:

    M291 P{"Repeating calibration, Deviation is " ^move.calibrationDeviation.deviation ^ "mm"}
    M291 P{"Repeating calibration, Deviation is " ^ (move.calibrationDeviation.deviation) ^ "mm"}



  • @dc42 said in What is the correct syntax for string operations?:

    M291 P{"Repeating calibration, Deviation is " ^move.calibrationDeviation.deviation ^ "mm"}

    @dc42 Worked like a charm, thank you so much.


Log in to reply