Reconstructing double float values with RSView


Thread Starter

Yosef Feigenbaum

I am communicating between an SLC-500 and an external device over Modbus. The external device returns much of it's data in double (64 bit) floating point format. RSView does not support the data type double for tags while double is supported within VBA.

I have been unable to find a way to change the address of a variable (as is possible in c) so
I am currently reading in 4 integer values, writing them as ints (16 bit) to a file in VBA and reading the data back into a double variable.
Needless to say this method is very slow.

I would appreciate and input on a more reasonable method of reconstructing the 4 ints into a double in RSView. A long integer result is also acceptable.
try to use win api method:

it works in VB and in vba also. Assuming that you are using a microsoft OS.

now what!

try CopyMemory wich syntaxe is:

Declare Sub CopyMemory Lib "kernel32"
Alias "RtlMoveMemory" (pDst As Any, pSrc As
Any, ByVal ByteLen As Long)

· Destination
Points to the starting address of the copied block’s destination.

· Source
Points to the starting address of the block of memory to copy.

· Length
Specifies the size, in bytes, of the block of memory to copy.

and also if you don't know how to get Adress Pointers in VB try
VarPtr() that return a long type pointer to one memory adress

dim MyValue as double
Dim AdressOfVal as long

AdressOfVal= VarPtr(MyValue)
I found an easy way to do this using the LSET command.

Create 2 user defined data types (for some reason an LSET requirement):
1) a structure with 4 ints (eg. FourInts)
2) a structure with 1 double (eg. OneDouble)

Declare a variable for each (eg. MyInts, MyDouble).

Load the tag data into each of the 4 sub elements of the "4 int" structure (MyInts) with the tag data from the PLC.

Use LSET to make MyDouble point to MyInts' memory location.