Library VBScript WinCC

I´m creating an extern Library build with C# to extend the options fo WinCC and used with VBScript. Another functions to do the code more easy for the user.

Currently all the functions are available for WinCC and WinCC RT Professional (Tia Portal).

If you are interested you can download the library from Siemens forum, where I will update the different versions.

https://support.industry.siemens.com/tf/ww/en/posts/library-vb-net-c-com-vbscript-wincc/187312/?page=0&pageSize=10

 

string :GetUserGroup (string DataSourceRT, string CurrentUser)

Dim CurrentUser , DatasourceNameRT , Obj , return
Set CurrentUser = HMIRuntime.Tags("@CurrentUser")
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetUserGroup(DatasourceNameRT.Read , CurrentUser.Read)
HMIRuntime.Trace "Grupo Usuario: " & return & vbNewline

 

string :GetUserGroupLogon(string DataSourceRT, string CurrentUser)

Dim CurrentUser , DatasourceNameRT , Obj , return
Set CurrentUser = HMIRuntime.Tags("@CurrentUser")
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetUserGroupLogon(DatasourceNameRT.Read , CurrentUser.Read)
HMIRuntime.Trace "Grupo Usuario: " & return & vbNewline

 

string :GetMaxLimitTag (string DataSourceRT, string TagName)

Dim Obj , return , DatasourceNameRT
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
return = Obj.GetMaxLimitTag(DatasourceNameRT.Read , "TagName")
HMIRuntime.Trace "Max Limit : " & return & vbNewline

 

string :GetMinLimitTag (string DataSourceRT, string TagName)

Dim Obj , return , DatasourceNameRT
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
return = Obj.GetMinLimitTag(DatasourceNameRT.Read , "TagName")
HMIRuntime.Trace "Min Limit : " & return & vbNewline

 

string :GetDateTime() 'With Miliseconds

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetDateTime()
HMIRuntime.Trace "System Date: " & return & vbNewline

 

string :GetDateTimeFormat(string format) '(HH:mm:ss.fff) ; (MMMM dd, yyyy) ; (yyyyMMddHHmmss)

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetDateTimeFormat("HH:mm:ss.fff")
HMIRuntime.Trace "System Date: " & return & vbNewline

 

int :Sleep(int Miliseconds) 'Return 1 when the time is finished

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "System Date: " & Obj.GetDateTime() & vbNewline
Obj.Sleep(500)
HMIRuntime.Trace "System Date: " & Obj.GetDateTime() & vbNewline

 

int :GetRandon()' By defaul 0-100

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetRandon()
HMIRuntime.Trace "Randon Number: " & return & vbNewline

 

int :GetRandonNumber(int MinNumber, int MaxNumber)

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetRandon(10,1000)
HMIRuntime.Trace "Randon Number: " & return & vbNewline

 

float :GetRandonFloat(int MinNumber, int MaxNumber)

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetRandon(10,1000)
HMIRuntime.Trace "Randon Number: " & return & vbNewline

 

int :StartProgram(string PathProgram, out string Message)

Dim Obj , msg
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.StartProgram("C:\\xxx\\MyExportFile.csv",msg)
If return = -1 Then
HMIRuntime.Trace msg & vbNewline
End If

 

int :CloseProgram(string Program, out string Message) 'Program = Name of the process

Dim Obj , msg
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.CloseProgram("firefox",msg)
If return = -1 Then
HMIRuntime.Trace msg & vbNewline
End If

 

void :Login()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.Login()

 

void :Logout()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.Logout()

 

void :SilentLogin(string login, string password)

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.SilentLogin("User" , "Passwords")

 

bool :LoggedInByCard()

Dim Obj , ret
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
ret = Obj.LoggedInByCard()

 

void :GetCursorPosition(out int x , out int y)

Dim Obj , x , y
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.GetCursorPosition x , y
HMIRuntime.Trace "X : " & x & vbNewline
HMIRuntime.Trace "Y : " & y & vbNewline

 

void : NormalWinCC()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.NormalWinCC()

 

void : MinimizeWinCC()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.MinimizeWinCC() 

 

void : MaximizeWinCC()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.MaximizeWinCC()

 

Thanks to WkHtmlToPdf I have created this functions, if you want try it, you need to install WkHtmlToPdf. You can donwload from https://wkhtmltopdf.org/downloads.htmlhttps://wkhtmltopdf.org/downloads.html

With this functions you will able to convert a website to pdf or convert a htm file to pdf.

int PrintHtmlToPdf(String Source, String Path , String msg)

Dim Obj , msg , ret
item.Enabled = False
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "Start: " & Obj.GetDateTime() & vbNewline
ret = Obj.PrintHtmlToPdf ("https://wkhtmltopdf.org","C:\\PDF\\wkhtmltopdf.pdf",msg)
If ret = -1 Then
HMIRuntime.Trace "Error: " & msg & vbNewline
End If
HMIRuntime.Trace "Finished: " & Obj.GetDateTime() & vbNewline
item.Enabled = True

 

Dim Obj , msg , ret
item.Enabled = False
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "Start: " & Obj.GetDateTime() & vbNewline
ret = Obj.PrintHtmlToPdf ("file:///C:/PDF/wkhtmltopdf.htm","C:\\PDF\\wkhtmltopdf2.pdf",msg)
If ret = -1 Then
HMIRuntime.Trace "Error: " & msg & vbNewline
End If
HMIRuntime.Trace "Finished: " & Obj.GetDateTime() & vbNewline
item.Enabled = True

 

Thanks to HtmlRenderer.PdfSharp I have created this functions, with this you don´t need to install nothing.

With this functions you will able to create a pdf from html code, and you can include css style and image

int GeneratePdf(String Source, String Path , String msg)

Dim Obj, pdf , msg , ret
item.Enabled = False
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "Start: " & Obj.GetDateTime() & vbNewline

pdf = " <html> " _
& "<body>" _
& "<h1>My First Heading</h1>" _
& "<p>My first paragraph.</p>" _
& "<p><h1>Hello World</h1>This is html rendered text</p>" _
& " <tablewidth:100%"">" _
& "  <tr>" _
& "   <th>Firstname</th>" _
& "    <th>Lastname</th>" _
& "    <th>Age</th>" _
& "  </tr>" _
& "  <tr>" _
& "    <td>Jill</td>" _
& "    <td>Smith</td>" _
& "    <td>50</td>" _
& "  </tr>" _
& "  <tr>" _
& "    <td>Eve</td>" _
& "    <td>Jackson</td>" _
& "    <td>94</td>" _
& "  </tr>" _
& "</table> " _
& "</body>" _
& "</html> "

ret = Obj.GeneratePdf(pdf , "C:\\PDF\\CodeHTML2PDF.pdf",msg)
If ret = -1 Then
     HMIRuntime.Trace "Error: " & msg & vbNewline
End If
HMIRuntime.Trace "Finished: " & Obj.GetDateTime() & vbNewline
item.Enabled = True

 

 

Dim Obj, pdf , msg , ret
item.Enabled = False
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "Start: " & Obj.GetDateTime() & vbNewline

pdf = "<head><style>.test { background-color: linen;color: maroon;}</style></head>" _
& " <body Class=""test""><p><h1>Hello PLC HMI SCADAS</h1>This is html generated with HtmlRenderer.PdfSharp  and rendered text with css and image.</p>" _
& " <p><img src=""https://plc-hmi-scadas.com/images/header1280.gif"" height=""100%"" width=""100%""></p>" _
& " </body>"

ret = Obj.GeneratePdf(pdf , "C:\\PDF\\CodeHTML2PDF_2.pdf",msg)
If ret = -1 Then
HMIRuntime.Trace "Error: " & msg & vbNewline
End If
HMIRuntime.Trace "Finished: " & Obj.GetDateTime() & vbNewline
item.Enabled = True

 

Update , if you donwload the last version there is some changes with several functions 26-07-2018

string :GetUserGroup ()
string :GetUserGroupLogon()
string :GetMaxLimitTag (string TagName)
string :GetMinLimitTag (string TagName)


string : GetRuntimeProject()

Dim Obj , ret
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
ret = Obj.GetRuntimeProject()

 

void : ShowTaskbar()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.ShowTaskbar()

 

void : HideTaskbar()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.HideTaskbar()

 

string :GetUserGroup ()

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetUserGroup()
HMIRuntime.Trace "User Group : " & return & vbNewline

 

string :GetUserGroupLogon()

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetUserGroupLogon()
HMIRuntime.Trace "User Group: " & return & vbNewline

 

string :GetMaxLimitTag (string TagName)

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetMaxLimitTag( "TagName")
HMIRuntime.Trace "Max Limit : " & return & vbNewline

 

string :GetMinLimitTag (string TagName)

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetMinLimitTag("TagName")
HMIRuntime.Trace "Min Limit : " & return & vbNewline

 

int :PrintReport (string JobName)

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.PrintReport(JobName)

 

int :PreviewReport (string JobName)

Dim Obj , return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.PreviewReport(JobName)

 


 

 

08 de Marzo del 2017

"La gratitud en silencio no sirve a nadie". Gladys Bronwyn Stern