Rx3i/quickpanel+ VB Script

Andor

Member
Join Date
Nov 2021
Location
Amsterdam
Posts
77
Dear guys, I am not a programmer but I can do simple things myself. I'm stuck with the following. if I want to extract a value from my rx3i emerson to a cvs file, this works. the only problem is that all values ​​only go up to a maximum of 32768. even though I changed it from int to dint and to real lreal. they all reach a maximum of 32768 when logged via my hmi screen (quickpanel+ emerson). In the PLC software when I am online and the HMI screen shows a value more than 32768, but not bad with the CVS file and when I access the screen via the web. I then get that it counts backwards or goes to the minus. anyone have an idea?

DB954F74-11AB-41A3-A0AF-F14A142EC69A.jpg BC8EF8F0-9265-4BC7-B0DE-742A265AA917.jpeg 9F0F4509-EC69-4CD0-8D15-531284205BB3.jpeg 9AA36D8F-A7FB-46C0-A944-CC060F202DD8.jpg
 
-------------------------------------
'
'Script Created: Jul 29, 2020
'-------------------------------------
' Script Created: Feb 20, 2018
' Description: Log Data To CSV File
' Application script period = 60000 ms = 1 minute
' VBScript
'-------------------------------------
'Get current year, make as start of file name
LOGFILENAME.Value = Cstr(CURRENTTIME.Element("YR").Value)
'Get current month, add to file name
LOGCURRENTMONTH.Value = CURRENTTIME.Element("MO").Value
If LOGCURRENTMONTH.Value < 10 Then
LOGFILENAME.Value = LOGFILENAME.Value + "0"
End If
LOGFILENAME.Value = LOGFILENAME.Value + Cstr(LOGCURRENTMONTH.Value)
'Get current day, add to file name
LOGCURRENTDAY.Value = CURRENTTIME.Element("DAY").Value
If LOGCURRENTDAY.Value < 10 Then
LOGFILENAME.Value = LOGFILENAME.Value + "0"
End If
LOGFILENAME.Value = LOGFILENAME.Value + Cstr(LOGCURRENTDAY.Value)
'Get current hour, add to file name
LOGCURRENTHOUR.Value = CURRENTTIME.Element("HR").Value
If LOGCURRENTHOUR.Value < 10 Then
LOGFILENAME.Value = LOGFILENAME.Value + "0"
End If
LOGFILENAME.Value = LOGFILENAME.Value + Cstr(LOGCURRENTHOUR.Value)
'Add path and .csv to get full file name - note SRAM storage
LOGFILENAME.Value = "\SRAM Storage" + LOGFILENAME.Value + ".CSV"
'Open log file or create new log file if there isn't one
LOGFILEHANDLE.Value = View.LogOpenFile (LOGFILENAME.Value)
If LOGFILEHANDLE.Value = -1 Then
LOGFILEHANDLE.Value = View.LogNewFile (LOGFILENAME.Value)
'Add Column titles to new file
View.LogPrintString LOGFILEHANDLE.Value, "DATE, TIME, prog1, prog2, prog3, prog4, prog5, prog6, O_Prog_1, O_Prog_2, O_Prog_3, O_Prog_4, O_Prog_5, O_Prog_6"
View.LogNewLine LOGFILEHANDLE.Value
End If
View.LogSetUseComma LOGFILEHANDLE.Value, 1 ' Add comma after LogPrintValue (default)
'Log the current data
View.LogDate LOGFILEHANDLE.Value
View.LogTime LOGFILEHANDLE.Value
View.LogPrintValue LOGFILEHANDLE.Value, prog1.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog2.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog3.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog4.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog5.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog6.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_1.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_2.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_3.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_4.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_5.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_6.Value / 100 , 2
View.LogNewLine LOGFILEHANDLE.Value
'Close file so it doesn't get corrupted
View.LogCloseFile LOGFILEHANDLE.Value
'Check hour rollover, move all csv files to CF card
'This copes with CF card beinhg removed, since files remain in local
'memory until CF card is available, then all copies moved
'So also no issues with deleting files locally either
If LOGPREVIOUSHOUR.Value <> LOGCURRENTHOUR.Value Then
' Delete old files here
' View.FileDelete "\PCFlash Storage\*.CSV"
View.FileMove "\SRAM Storage\*.CSV", "\SDMemory", 0 ' Overwrite
' Use httcopy here to move to external location
End If
LOGPREVIOUSHOUR.Value = LOGCURRENTHOUR.Value

'
'Description:

'
'-------------------------------------
 
It is almost certain that what ever field that shows minus in those pictures is configured as a signed integer i.e. -32767 +32767
They need to be configured as unsigned integers so they can be displayed i.e. -65537 to +65537.
 
It is almost certain that what ever field that shows minus in those pictures is configured as a signed integer i.e. -32767 +32767
They need to be configured as unsigned integers so they can be displayed i.e. -65537 to +65537.

how can I do that? Ideally, they should be able to go even higher if possible?
 
sorry a little bit of a mistake on my part if it is an unsigned integer it is 0-65535
If it is a signed integer it will go -32767 to +32767.
The reason is a signed integer is only 15 bits for value & the 16th bit (bit15 as they go 0-15) is the sign, so 65537 is displayed as -32767. as it thinks if the sign bit is 1 it is negative.
See pic of monitoring a signed versus unsigned

Signed_Unsigned.png
 
The quick fix is to add 65536 to any .value that is negative.


Another fix would be to write it to a DINT and then use the bit-wise And operator mask out the high 15 bits e.g. this
CLng(whatever.value)
becomes this:
CLng(whatever.value) And CLng(65535)
<or>
CLng(whatever.value) And CLng(&0000FFFFH)
You could also make this a function:

FUNCTION fix_rawint(rawvalue)
fix_rawint = CLng(rawvalue) And CLng(&0000FFFFH)
END FUNCTION


then a statement like this:
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_1.Value / 100 , 2
becomes this (I think):
View.LogPrintValue LOGFILEHANDLE.Value, fix_rawvalue(O_Prog_1.Value) / 100 , 2
 
The quick fix is to add 65536 to any .value that is negative.
Like this?

View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_2.Value65536 / 100 , 2


fix would be to write it to a DINT and then use the bit-wise And operator mask out the high 15 bits e.g. this
CLng(whatever.value)
becomes this:
CLng(whatever.value) And CLng(65535)
<or>
CLng(whatever.value) And CLng(&0000FFFFH)
You could also make this a function:

FUNCTION fix_rawint(rawvalue)
fix_rawint = CLng(rawvalue) And CLng(&0000FFFFH)
END FUNCTION


then a statement like this:
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_1.Value / 100 , 2
becomes this (I think):
View.LogPrintValue LOGFILEHANDLE.Value, fix_rawvalue(O_Prog_1.Value) / 100 , 2

LOGFILEHANDLE.Value = View.LogOpenFile (LOGFILENAME.Value)
If LOGFILEHANDLE.Value = -1 Then
LOGFILEHANDLE.Value = View.LogNewFile (LOGFILENAME.Value)
'Add Column titles to new file

FUNCTION fix_rawint(rawvalue)
fix_rawint = Clng(rawvalue) And Clng(&0000fffh)END FUNCTION


View.LogPrintString LOGFILEHANDLE.Value, "DATE, TIME, prog1, prog2, prog3, prog4, prog5, prog6, O_Prog_1, O_Prog_2, O_Prog_3, O_Prog_4, O_Prog_5, O_Prog_6"
View.LogNewLine LOGFILEHANDLE.Value
End If
View.LogSetUseComma LOGFILEHANDLE.Value, 1 ' Add comma after LogPrintValue (default)
'Log the current data
View.LogDate LOGFILEHANDLE.Value
View.LogTime LOGFILEHANDLE.Value
View.LogPrintValue LOGFILEHANDLE.Value, fix_rawvalue(prog1.Value), 0
View.LogPrintValue LOGFILEHANDLE.Value, prog2.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog3.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog4.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog5.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, prog6.Value, 0
View.LogPrintValue LOGFILEHANDLE.Value, fix_rawvalue(prog1.Value) / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_2.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_3.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_4.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_5.Value / 100 , 2
View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_6.Value / 100 , 2
View.LogNewLine LOGFILEHANDLE.Value
'Close file so it doesn't get corrupted

like this?
 
The trouble is not knowing the platform & how the posted fields are set up then it is difficult to understand what is going on. as shown in my posted picture those fields look like they are configured as signed words so anything above that is showing negative, the pic I posted those 2 values are the same variable but declared as a signed word & unsigned word it would be the same on an HMI
So unless we know how the pictures posted & the variables are configured it is impossible to know what is going on.
Attached is just an Example of an HMI tag, it will depend on how it is configured for example if it is a signed integer then anything above 32767 will show negative, however, if the tag is set as an unsigned integer then it will display from 0-65535, if set as a double then again will depend on if it is a signed double or an unsigned one.

Type.png
 
Like this?

View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_2.Value65536 / 100 , 2
No. More like this


If O_Prog_2.Value < 0 Then

View.LogPrintValue LOGFILEHANDLE.Value, (O_Prog_2.Value+65536) / 100 , 2

Else

View.LogPrintValue LOGFILEHANDLE.Value, O_Prog_2.Value / 100 , 2

End If




...

FUNCTION fix_rawint(rawvalue)
fix_rawint = Clng(rawvalue) And Clng(&0000fffh)
END FUNCTION


...

View.LogPrintValue LOGFILEHANDLE.Value, fix_rawint(prog1.Value), 0
...



like this?


Sort of.


I think the function definition (between FUNCTION and END FUNCTION) needs to be somewhere else, and cannot be in the middle of the other code that uses it. I am not a VBScript expert, but VBScript does have a syntax for defining procedures and functions.
 
If I'm interpreting your initial post correctly, the variable is correctly defined in the PLC target as well as in the HMI target, since it displays the value you expect to see in both the programming software and on the HMI screen. If that's the case, there's something in the VBScript that is not correctly interpreting the pattern of bits and you should concentrate your debugging efforts there.
 
Would you not assign you vb variables to Uinteger ?


Ooh, nice. Much better, CUShort(O_Prog_2.Value) might be a built-in replacement for what that fix_rawint(O_Prog_2.Value) would do, and then you don't have to create the fix_rawint function.
 
I think you mean this. But i can’t found it in the HMI only in the plc


I can only put the uint in the plc. It is not listed in the HMI.

5994F322-1BFF-4B8E-B911-344531430736.jpg 13FD5951-E827-472C-8000-0C838722B31C.jpg A2F38F19-46ED-4A50-A191-B67CF4BFAC8D.jpg C5166685-D9B4-4632-8256-A26265EE30F3.jpeg 195D6B1A-CB10-4D10-AD26-B5322E9F8133.jpeg
 
If I'm interpreting your initial post correctly, the variable is correctly defined in the PLC target as well as in the HMI target, since it displays the value you expect to see in both the programming software and on the HMI screen. If that's the case, there's something in the VBScript that is not correctly interpreting the pattern of bits and you should concentrate your debugging efforts there.

I will first test what Parky wrote to see whether the variable in the PLC converts from int/dint to uint to see if that is the problem. the hmi does show the correct numbers. only the quickpanel+ script and web page show the maximum of 32678
 

Similar Topics

Hi all, I'm trying to setup communications between an RX3i PLC and a GE QuickPanel View touchscreen. I have a CPU315 (IC695CPU315) with an...
Replies
7
Views
4,763
I have a system using Rx3I CRU320 redundant CPU with Proficy Machine Edition Software. In the hardware configuration of each CPU module, under...
Replies
14
Views
389
Hi, we are using Rx3i CRU320 redundant PLC system and we noticed a discrepancy between Primary and Secondary controller. Couple of variables (DI)...
Replies
8
Views
284
Hi there, I'm doing some extensive testing and commissioning with a slew of new Emerson PACSystems RX3i PLCs. It would be convenient to...
Replies
5
Views
106
Hi there, Trying to get some ascii serial communications working via RS485 (COMMREQ functions). I have attached our wiring for the COM2...
Replies
1
Views
977
Back
Top Bottom