Command |
Introduces a switch-block, and specifies the port against which the case(s) will be tested.
public void AppendSwitch( IOPort port, bool compareCondAsMask, uint mask = 4294967295 )
The condition evaluates to true if (cv & pv) != 0.
Appends a SWITCH command to the list.
Caution |
---|
Conditional BRANCH commands do NOT automatically de-activate the laser. |
See also: 12.9 Notes on Flow-Control Commands.
Please note that this is a contrived example, illustrating very naive usage of the switch-block.
uint lowSpeedMarkingBitmask = 0x5AA5; // a case-value used to test the port-value. uint mediumSpeedMarkingBitmask = 0xA55A; // another case-value used to test the port-value. CommandList list = new CommandList(); list.AppendJumpAbs( 0, 0 ); // at list offset 0. // Start of switch-case block list.AppendSwitch( IOPort.PortB, true ); // at list offset 1. list.AppendCaseRel( 3, lowSpeedMarkingBitmask ); // at list offset 2. The case-target command is +3 positions ahead. list.AppendCaseRel( 4, mediumSpeedMarkingBitmask ); // at list offset 3. The case-target command is +4 positions ahead. list.AppendDefaultRel( 5 ); // at list offset 4. The default-target command is +5 positions ahead. // End of switch-case block list.AppendMarkSpeed( 1.0 ); // at list offset 5. // This is the case-target when lowSpeedMarkingBitmask matches the port's value. list.AppendBranchRel( 4 ); // at list offset 6. // Goto the MARK command +4 positions ahead. list.AppendMarkSpeed( 2.0 ); // at list offset 7. // This is the case-target when mediumSpeedMarkingBitmask matches the port's value. list.AppendBranchRel( 2 ); // at list offset 8. // Goto the MARK command +2 positions ahead. list.AppendMarkSpeed( 3.0 ); // at list offset 9. // This is the default-target when none of the Bitmasks matches the port's value. // No BRANCH command is necessary in this case, since the MARK command follows immediately. list.AppendMarkAbs( 500, 500 ); // at list offset 10. // This is the branch-target for the case blocks. // The MARK will be made at the selected speed. Console.WriteLine( $"List commands:" ); int count = 0; foreach ( var cmd in list ) Console.WriteLine( $" {count++}: {cmd.ToString()}" ); // output should be: // List commands: // 0: { JA, P2D[ X=0 Y=0 ] } // 1: { SWI, I32[ 1 ], Bool[ True ], U32[ 4294967295 ] } // 2: { CASGR, I32[ 3 ], I32[ 23205 ] } // 3: { CASGR, I32[ 4 ], I32[ 42330 ] } // 4: { DEFGR, I32[ 5 ] } // 5: { MS, F64[ 1 ] } // 6: { BR, I32[ 4 ] } // 7: { MS, F64[ 2 ] } // 8: { BR, I32[ 2 ] } // 9: { MS, F64[ 3 ] } // 10: { MA, P2D[ X=500 Y=500 ] }