Back

Topic

[KB1157]How to make a Ping command and use the result in PcVue?

Tags: Ethernet, Network, Scada Basic

2 years ago
By GRCH
Options
Print

Applies to:

PcVue


Summary:

This article describes a way, from PcVue, to make a ping and to retrieve the result.

When we talk about the ping function, we usually advise to use the SNMP protocol, but sometimes, the device does not support SNMP or the PcVue license does not have this protocol…

So, one solution is to use a Scada Basic program where we execute a ping command, we send the result in a file and we recover it in a buffer to analyze it.


Details:

The attached project, developped with PcVue 12, gives an example. The file where the ping result is sent, is located in TP folder of the project.

In this sample, we enter the IP address into a text variable and we display the result into another text variable.

 Make Ping sample project

 He are the two functions used:

 

Sub Make_Ping()
Dim CMD as str, ProjectName as Str;

@PINGS.ComOk=””;
ProjectName= addstring(GETPROJECTDIR(), “\TP\Test.txt”);

‘We send the result of the cmd prompt to the TP folder, in the file Test.txt
CMD = addstring(“ping “, @PINGS.IPAd,” > “”,ProjectName,”””);

SYSTEM(“SYSTEM”,CMD);
‘Alternatively, you can run an application in background:
‘Application(“LOAD”, “AppPing.cmd”, “”, 5, “”); ‘The cmd file must not be named Ping.cmd!

End sub
‘—————————–

Sub Analyze_Ping()
Dim Handle as Long, Result_Handle as Long;
Dim Result as str, Reply as str;
Dim Size as integer, StaticSize as integer;

‘StaticSize, Corresponds to the length of: “Reply from : bytes=32” (words and size will change according to the language)
StaticSize= 23; ‘-> Modify size according to the language used (words and size will change)

Handle = ALLOC_BUFFER(1024);
Result_Handle = ALLOC_BUFFER(1024);

Handle = FILETOBUF(“Test.txt”);

SEQ_BUFFER(“BEGIN”, Handle);
SEQ_BUFFER(“SEEKFIELD”, 2, Handle, “n”); ‘We seek for the second text line
SEQ_BUFFER(“NEXTFIELD”, Handle, “n”,Result_Handle);

Size=StaticSize + TEXTVAR(“TEXTLEN”, “@PINGS.IPAd”) ; ‘We add the length of the IP Address

‘Result, We retrieve the second line from the file
Result = Right((CGET_BUFFER(Result_Handle,0,Size)),9); ‘We are looking for octets=32, meanning the last 9 characters
print(“Result in file : “, Result);

‘Reply, We expect seometing like Reply from xxx.xxx.xxx.xxx: octets=32
Reply=”octets=32″; ‘-> Modify words according to the language used
print(“Result expected : “, Reply);

If(CMPSTRING(Result, Reply) == 0) Then
@PINGS.ComOk=”Communication ok”;
Else
@PINGS.ComOk=”Communication error”;
End if

Free_Buffer(Handle);
Free_Buffer(Result_Handle);

End sub

Sample project: MakePing.zip

 


Created on: 10 Aug 2022 Last update: 30 May 2024