<< Click to Display Table of Contents > How to work with Flags |
Some commands give a possibility to set multiple flag values at once. These are for example: DeviceEnableFlagsValue, MarkFlags, and a lot of others. There are simple procedures which allow you to operate with the flag values very easily. We will consider an example of Mark Flags being set with MarkFlags function. Set Flag ValuesThe complete set of all available Mark Flags you can find in the corresponding command description. Here we just pick a few flags and use them for demonstration. Assume we want to set following flag values: WaitForTrigger → With this flag you activate the Trigger Mode. Selected → When this flag is activated, only selected entities will be marked. We do not know initially, which flags are already set and we do not want to overwrite them. That is why we call the current state of Mark Flags as first. To set the above flags, we need to combine them with the current flags state. We can do it by using the logical OR operator. In the last step, we "send" the modified flags value to SAMLight. In the table below you can see the example code for the described procedure. |
---|
Set Flag Values |
---|
// Save the current mark flags value to the markFlags variable int Mark_Flags = cci.New.ScGetMarkFlags(); // Modify the vlaue of markFlags by adding the new flags markFlags |= (int)ScComSAMLightClientCtrlMarkFlags.scComSAMLightClientCtrlMarkFlagWaitForTrigger; markFlags |= (int)ScComSAMLightClientCtrlMarkFlags.scComSAMLightClientCtrlMarkFlagSelected; // Define the new Flags Value to the SAMLight int CCI_Return = cci.ScSetMarkFlags(Mark_Flags); |
Table 411: Example Set Flag Values
Get Flag StatusIf we want to check, if the Wait For trigger Flag is already activated, we proceed as follows. As first get the current state of the mark flags. Than we save the value of the WaitForTrigger flag to the constant TriggerFlag. Using logical AND operator, we can now compare the current flag state with the Trigger flag.•If the condition markFlags & TriggerFlag == TriggerFlag is true, the WaitForTrigger flag is enabled. •If the above condition is false, the flag is disabled. In the table below the example code for this case. |
---|
Get Flag Status |
---|
// Save the current mark flags value to the markFlags variable int Mark_Flags = cci.ScGetMarkFlags();
// Define the value of the flag to be compared int Some_Flag = (int)ScComSAMLightClientCtrlMarkFlags.scComSAMLightClientCtrlMarkFlagWaitForTrigger; // Check, if the flag is already activated bool Flag_Status = (markFlags & someFlag) == someFlag ? true : false; |
Table 412: Example Get Flag Status
Deactivate a particular FlagIf you want to deactivate any particular flag, the work flow is very similar to the first example, where you activate some flags, but here we must use the logical AND NOT instead of logical OR. Below is the coding example of deactivating the WaitForTrigger flag. |
---|
Deactivate Flag |
---|
// Save the current mark flags value to the markFlags variable int Mark_Flags = cci.ScGetMarkFlags();
// Define the value of the flag to be deactivated int Deactivate_Flag = (int)ScComSAMLightClientCtrlMarkFlags.scComSAMLightClientCtrlMarkFlagWaitForTrigger; // Deactivate the flag using AND NOT operator Mark_Flags = Mark_Flags & (~Deactivate_Flag); // Define the updated flags value to SAMLight int CCI_Return = cci.ScSetMarkFlags(Mark_Flags); |
Table 413: Example Deactivate Flag