FB_CPLink3_AcquireHIDFocus
This function block is used to acquire or release the HID focus.
VAR_IN_OUT
VAR_IN_OUT
hFocus : T_HCPLink3HidFocus;(* CPLink3 HID focus handle *)
END_VAR
hFocus: CP-Link3 HID focus handle.
VAR_INPUT
VAR_INPUT
bEnable : BOOL := FALSE;(* TRUE = Acquire, FALSE = Release focus *)
setIP : T_IPv4Addr := '';
END_VAR
bEnable: TRUE = acquire focus, FALSE = release focus.
setIP: The IP address of the client.
VAR_OUTPUT
VAR_OUTPUT
bAcquired : BOOL := FALSE;(* Focus status information *)
bLED : BOOL := FALSE;(* LED control output *)
bBusy : BOOL;(* TRUE => function in progress *)
bError : BOOL;(* Error flag *)
nErrID : UDINT;(* Error code *)
END_VAR
bAcquired: This output is set when the client gets the focus and is reset when the client looses the focus.
bLED: This meaning of this output depends on the output mode:
Mode | Meaning |
---|---|
Constant TRUE | The client has the focus. |
Constant FALSE | The client does not have the focus. |
Toggles | The client is waiting for the focus. |
bBusy: When the function block is activated this output is set. It remains set until an acknowledgement is received.
bError: If an ADS error occurs during the execution of the command, then this output is set, after the bBusy output has been reset.
nErrID: When the bError output is set, this variable supplies the ADS error code.
Example: Example Program: Controlling the HID focus through special keys
Manually setting the HID focus can, for instance, be controlled by a client’s special key. The special key is linked to the corresponding input variable in the PLC program through the TwinCAT System Manager. An instance of FB_CPLink3_AcquireHidFocus is generated for each client and configured with the client's IP address. After the special key at a client is pressed, where the rising edge will be detected by the R_TRIG function block, the PLC program will attempt to set the HID focus through the corresponding instance of FB_CPLink3_AcquireHidFocus. The function block can, in addition, control an output (e.g. a LED) that indicates whether the HID focus has successfully been set, or whether it is still attempting to obtain the focus. Pressing the special key again resets the HID focus.
The three instances of the FB_CPLink3_AcquireHidFocus function block use the hFocus variable to exchange information between each other. This is used, for instance, to ensure that only the instance that has successfully set the HID focus is able to reset it.
The PLC program for three clients looks like this:
PROGRAM MAIN
VAR
button1 AT%IX0.0 : BOOL;
button2 AT%IX0.1 : BOOL;
button3 AT%IX0.2 : BOOL;
led1 AT%QX0.0 : BOOL;
led2 AT%QX0.1 : BOOL;
led3 AT%QX0.2 : BOOL;
hFocus : T_HCPLink3HidFocus;
fbPanel1 : FB_CPLink3_AcquireHidFocus := ( setIP := '192.168.1.1' );
fbPanel2 : FB_CPLink3_AcquireHidFocus := ( setIP := '192.168.1.2' );
fbPanel3 : FB_CPLink3_AcquireHidFocus := ( setIP := '192.168.1.3' );
trigger1 : R_TRIG;
trigger2 : R_TRIG;
trigger3 : R_TRIG;
END_VAR
(* Panel 1 *)
trigger1( CLK := button1 );
IF trigger1.Q THEN
fbPanel1.bEnable := NOT fbPanel1.bEnable;
END_IF
fbPanel1( hFocus:= hFocus, bLED=>LED1);
(* Panel 2 *)
trigger2( CLK := button2 );
IF trigger2.Q THEN
fbPanel2.bEnable := NOT fbPanel2.bEnable;
END_IF
fbPanel2( hFocus:= hFocus, bLED=>LED2 );
(* Panel 3 *)
trigger3( CLK := button3 );
IF trigger3.Q THEN
fbPanel3.bEnable := NOT fbPanel3.bEnable;
END_IF
fbPanel3( hFocus:= hFocus, bLED=>LED3 );
Requirements
Development environment | Target system type | PLC libraries to include |
---|---|---|
TwinCAT v2.10.0 and higher | PC | TcCPLink3.Lib |