error diagnostics and testing of the connection between a VB application and WinLC
How can I evaluate the error information that is generated in the case of connection faults to WinLC and how can I test the connection?
If a connection from your VB program to WinLC could not be set up, you have the option of evaluating the error information that is returned and displaying it on the user interface.
Proceed as follows:
- Create a Visual Basic dialog.
- Insert the "S7 Data" control element into this dialog. If this control element is not available in your toolbox, right-click the toolbox and select "Components" in the menu that opens. In the ensuing dialog go to the "Controls" tab and click the check mark in front of "Siemens SIMATIC Data Control" and then click "Accept". Now the icon for the S7 Data Control appears in your toolbox.
- Insert control elements in your dialog which you can use to output error information. These can be "static texts" or "text boxes" for example.
- Program the "S7Data1_ConnectionError" function. This function is called by Visual Basic as soon as a connection error occurs. With static texts you use the "Caption" property to assign a parameter transferred by the function, for example with the instruction: "lblOutVariable.Caption = VarName".
To test an existing connection you can output or display WinLC process variables on your VB user interface.
Proceed as follows:
- Insert the relevant control elements into your dialog, e.g. text box and slider.
- Link each of these objects to a process variable. You do this via the S7 Data Control. Open the Properties dialog of the "S7 Data Control" with a right-click. In the "Connections" tab you will see a list of all the controls available in the dialog. Click the property of the object to which you want to assign a process variable and enter the process variable in the "Assigned Variable" field. Normally for the Slider Control you select the "Value" property, and the "Text" property for the text box. The value of the selected variable is then displayed by the object concerned during runtime of the program.
Generally you must make sure that you correctly preset the name of the Control Engine. For this you go to the Properties dialog of the S7 Data Control, select the "Engine" tab and in the "Control Engine" field you enter the string "WinAC\default".
The following dialog is used in the sample program provided below:
If an connection error occurs, the error information is output in the "Error Diagnosis" field.
The download contains the program described above. The project has been created with Microsoft Visual Basic V6.0 SP 4.
Copy the "con_nection.exe" file into a separate directory and then start it with a double-click. The VB project unpacks automatically with all the associated files. You can then use Visual Basic to open and edit the unpacked project.
Connection diagnosis, Test routines