Click or drag to resize

CommandListAppendSwitch(IOPort, Boolean, UInt32) Method

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


Namespace: RAYLASE.SPICE3.ClientLib
Assembly: RAYLASE.SPICE3.ClientLib (in RAYLASE.SPICE3.ClientLib.dll) Version: 3.4.1
Syntax
C#
public void AppendSwitch(
	IOPort port,
	bool compareCondAsMask,
	uint mask = 4294967295
)

Parameters

port  IOPort
The I/O port whose value will be tested by the CASE commands within the switch block.
compareCondAsMask  Boolean
false
cond value (cv) must exactly match the I/O port value (pv) read back from port at the time of execution.
Only the bits set in mask are compared.
The condition evaluates to true if (cv & mask) == (pv & mask).
true
cond value (cv) itself is applied as a bit mask to the I/O port value (pv) read back from port at the time of execution.

The condition evaluates to true if (cv & pv) != 0.

mask  UInt32  (Optional)
This is only used when compareCondAsMask is set to false. Only the bits set to 1 in mask are compared. All bits set to 0 are ignored.
Remarks

Appends a SWITCH 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 Port Value Command Example
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 ] }
See Also