VBScript in Indusoft

Jon R

Member
Join Date
Jan 2007
Location
Tadley
Posts
206
Hi,

I am trying to implement a small bit of code in the VBScript within Indusoft Web Studio. Basically I have a selector switch that sets a variable within a Beckhoff PLC, to enable functions within a function block.

Initially I just used an IF..Then statement in the script, which works fine if the PLC is running when the switch is changed, however if the PLC is started after the switch is selected, the variable won't get written.

I have tried a Do..Loop but it seems to hog processing time, as I need to repeat the code continuosly to make sure that the variables get written regardless.

Below is the code I have used as a test. I am still trying to pick up bits of VB and VBScript whilst trying to arrange training.


Sub Multiple_Switch()

Dim A

Do While $iCounter < 9

For A = 0 To 9 Step 1

$iCounter = $iCounter + 1

Next

Loop

If $iCounter => 10 And $IGatesOn > 0 Then

$bTest1 = True
$bTest2 = True

End If

If $iCounter => 10 Then

$iCounter = 0

End If

End Sub


I would be grateful for any pointers. Would I be better doing a compare based ontime that executes an IF..Then statement every second or so? Is this possible?

Jon.
 
Please explain $icounter and what it's possible initial values are. There are places where you can equivalently simplify your code. For example:
Do While $iCounter < 9

For A = 0 To 9 Step 1

$iCounter = $iCounter + 1

Next

Loop

If $iCounter => 10 And $IGatesOn > 0 Then

Could be:
If $iCounter < 9
For A = 0 To 9
$iCounter = $iCounter + 1
Next
End If

If $IGatesOn > 0 Then...
What's the purpose of the For loop? Why not just increment $iCounter by 10? Perhaps there is a more subtle concurrency problem that I'm missing...?

To address your problem of writes not working when the PLC is unavailable:
Do you have any shared memory that the PLC can read directly upon startup to avoid having to poll frequently?

If not, you might need to find a way to disable writes on the HMI side when the PLC is not responding.
 
Nathan,

The variable $iCounter is an application variable that I was just using to control and try to monitor the counting. The $ sign is just to let VBScript know that this is an internal variable within Indusoft.

The reason for the for loop was to try and put in a small delay between polling, but obviously 10 gets counted almost immediately. This was just to try and prevent continuous polling, which is why I thought a time based comparison approach might be better.

I could possibly get the unit to read from the TwinCAT Soft PLC instance that I have running on the same PC. To be honest, I hadn't thougt of that but I would prefer to have direct comes from HMI to hardware.

I know the HMI reports errors, as I can monior reading and writing to the devices through the logging window so this may be a better way to go, although it will no doubt mean a bit of sripting. I will contact Indusoft to see if that is possible, unless of course any one on here knows.

Thanks for the advice,

Jon.
 
As a matter of practice, it's not a good idea to constantly run code when you don't need to. I would cut the "Do While" and "For" loops. There must be commands to introduce a delay (Pause or a timer) for those rare cases where you ABSOLUTELY need it. You can also just run that Sub less frequently.

Here are some approaches to prevent writes when the PLC is unavailable:
1. Check if the PLC is available in your code before running
2. Perform error handling/readback afterward
3. Have the PLC provide some kind of output feedback that the user can see on their screen. This will at least indicate cases when nothing happened.

Best yet - the HMI might support not writing to, or providing feedback from, tags that aren't available. That seems pretty fundamental...
 
Last edited:

Similar Topics

I am using Indusoft Version 8.1, and trying to use the VBScript button command to find a string in a column in a MySql database, and return all...
Replies
36
Views
8,743
Hello, I have a quick question. I have been using scripts to change the color of buttons. The reason, I am usually using multiple hmiruntime.tags...
Replies
1
Views
101
hello, i m trying to write a VB script on wincc RT Advanced to activate an internal tag. but it won't work. any help here...
Replies
9
Views
2,962
Hi, Siemens TP900 Comfort: VBscript logging vs datalog I have a request from a customer. He needs to log around 10 real value's. The interval...
Replies
0
Views
2,229
Hi, I tried this: HMIRuntime.Screens("Mainscreen.bottomwindow:bottomwindow").ScreenItems("btn_body").back.color = RGB(255,255,255)...
Replies
1
Views
3,623
Back
Top Bottom