Click or drag to resize

CommandListAppendSwitch(String) Method

Introduces a switch-block, and specifies the variable against which the case(s) will be tested.


Namespace: RAYLASE.SPICE3.ClientLib
Assembly: RAYLASE.SPICE3.ClientLib (in RAYLASE.SPICE3.ClientLib.dll) Version: 3.6.0
Syntax
C#
public void AppendSwitch(
	string integerVariableName
)

Parameters

integerVariableName  String
The name of the integer variable whose value will be tested by the CASE commands within the switch block.
Remarks

Appends a SWITCH_VALUE command to the list.

Caution note  Caution

Conditional BRANCH commands do NOT automatically de-activate the laser.

See also: 12.9 Notes on Flow-Control Commands.

Example

Please note that this is a contrived example, illustrating very naive usage of the switch-block.

Switch by Variable Value Example
string varname = "var";                                 // the name of an integer-variable (on the card) whose value will be tested.

uint lowSpeedMarkingTestValue = 3;                      // a case-value used to test the variable-value.
uint mediumSpeedMarkingTestValue = 6;                   // 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( varname );                           // at list offset 1.
list.AppendCaseRel( 3, lowSpeedMarkingTestValue );      // at list offset 2. The case-target is +3 positions ahead.
list.AppendCaseRel( 4, mediumSpeedMarkingTestValue );   // at list offset 3. The case-target is +4 positions ahead.
list.AppendDefaultRel( 5 );                             // at list offset 4. The default-target is +5 positions ahead.
                                                        // End of switch-case block.

list.AppendMarkSpeed( 1.0 );                            // at list offset 5.
                                                        // This is the case-target when lowSpeedMarkingTestValue matches the variable'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 mediumSpeedMarkingTestValue matches the variable'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 TestValues matches the variable's value.
                                                        // No BRANCH command is necessary here, since the MARK command follows immediately.

list.AppendMarkAbs( 500, 500 );                         // at list offset 10.
                                                        // This is the branch-target for the branches out of 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: { SWIV, I32[ 0 ], U32[ 2317739966 ] }
//  2: { CASGR, I32[ 3 ], I32[ 3 ] }
//  3: { CASGR, I32[ 4 ], I32[ 6 ] }
//  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 ] }
See Also