cp-link3

Set the HID focus manually

A description of how the HID focus can be set manually follows (see also Client Configuration - HID-Focus).

Basic knowledge required
Setting the HID focus manually presupposes basic knowledge of how to use the TwinCAT system.

The following illustration shows schematically the host PC components involved in setting the HID Focus manually:

 hidfocus_01_overview

The driver for the “CP-Link 3 Remote Port Enumerator” has an interface through which the HID focus can be set to a specific client. The HID focus can also be reset through this interface. The driver's interface is indirectly accessible via ADS, i.e. through an ADS server that is implemented in the “CP-Link 3 Service”. The interface can therefore be used from the TwinCAT PLC as well. Use is simplified by a PLC library. The PLC library contains the FB_CPLink3_AcquireHidFocus function block, which is used to set the HID-Focus to a specific client. The corresponding example program illustrates how the FB_CPLink3_AcquireHidFocusfunction block can be used. Both the example program and the library are placed, when CP-Link 3 is installed, in the program directory in subfolder Plc (for TwinCAT 2: TcCPLink3.lib and CplHidFocusSelect.pro, for TwinCAT 3: Tc2_CPLink3.compiled-library and CplHidFocusSelect.tpzip).

Configuration of Clients
Setting the HID Focus manually is only possible for clients which are configured for HID Focus "Manual" (see also Client Configuration - HID-Focus).
CP-Link 3 Service
Settings the HID Focus manually is only possible if the CP-Link 3 Service is running (see also CP-Link 3 Service).
 
 

Example Program: Controlling the HID focus through special keys

Manually setting the HID focus can, for instance, be controlled by a clients 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 );
 
 

CP-Link 3 ADS Interface

The CP-Link 3 ADS server can be reached through AMS port 19300. One function is implemented at present:

 
AdsWrite

SetHidFocus
IndexGroup: 0x10000
IndexOffset: IP Address in network byte order or 0 to clear HID-Focus

Possible ADS return values:
ADSERR_DEVICE_INVALID_STATE - CP-Link 3 Remote Port Enumerator returned that command was not valid
ADSERR_DEVICE_NOT_FOUND - CP-Link 3 Remote Port Enumerator not installed
ADSERR_DEVICE_ERROR - CP-Link 3 Remote Port Enumerator returned an error
ADSERR_DEVICE_BUSY - HID-Focus was not set as another client has the focus
ADSERR_NOERR - HID-Focus was set to given client