How to read IEEE format INTEL Litter Endian in PcVue?

Прочие SCADA: iFix, InTouch, Citect, ...
Post Reply
leofarhan
Posts: 122
Joined: Fri May 01, 2009 8:50 am

How to read IEEE format INTEL Litter Endian in PcVue?

Post by leofarhan » Thu Jun 30, 2011 5:49 pm

Hello,

I am using PcVue 8.1 for reading some exteranl devices on ModBus TCP/IP, I have to read the floating registers available in the device the floating format is "IEEE format INTEL Litter Endian"

When I read the incorrect value appears in the PcVue. Have tried to use Real with Mlsb & Lmsb (i.e. LSB/MSB First) But it did not work.

Can anyone guide me how can I read the data? Is there any instruction in SCADA Basic Program of the PcVue to convert IEEE 754 Float to IEEE format INTEL Litter Endian.

Looking forward for your reply.

BR
Leo-Ali

leofarhan
Posts: 122
Joined: Fri May 01, 2009 8:50 am

Re: How to read IEEE format INTEL Litter Endian in PcVue?

Post by leofarhan » Tue Aug 30, 2011 6:35 am

Hello!

The following VB code can be used to convert IEEE-754 Intel Endian format into IEEE-754 Intel Big Endian in the PcVue.
For this two registers need to be configured, one for reading the value from device (Used as hex number) other the float as output of the program.
Spoiler
Show

Code: Select all

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Const cVARIABLES_NUM = 1

'Number of variables to subscribe
Dim WithEvents Obj_NewValue As CLS_Subscription 'Object used when a value change
Private arstrVarNames(1 To cVARIABLES_NUM) As String        'Array containing the variables to subscribe

'Dim WithEvents vMyVar As Variable


Private Sub fvProject_StartupComplete()

'    Set vMyVar = Variables("TEST")
'    vMyVar.EnableEvents = True
    
    'Here we create an array containing the list of variables to subscribe
        arstrVarNames(1) = "Variable_Name"
        
            
        'Call the subscripion function
        Set Obj_NewValue = ConnectSubscription
    
End Sub

'-----------------------------------------------
'To Initialize the variable name and value arrays
'- using arStrVarNames : Array of variables to connected
'- (out) ConnectSubscription : Subscription object created to connect the variables
'----------------------------------------------------------------
Private Function ConnectSubscription() As CLS_Subscription

 On Error GoTo TRAP_Error
 
 'Initialize the Subscription object to be returned to the caller
 Set ConnectSubscription = Nothing
 
 'No Subscription currently executed, so a new one can be created
     'Create the Subscription object
     Set ConnectSubscription = New CLS_Subscription
     'If connection succeeds, initialize the Subscription object to returned to the caller
     If ConnectSubscription.ConnectVariables(arstrVarNames) = False Then 'If connection failed
         ConnectSubscription.Clear
         Set ConnectSubscription = Nothing
     End If

On Error GoTo 0
Exit Function

TRAP_Error:
 MOD_General.ErrorManagement "ConnectSubscription", "ThisProject"

End Function

'-----------------------------------------------
'Sub : Obj_NewValue_OnRefreshed
'Scope : When a value change the procedure is called
'Parameters :   arstrVarNames --> Array containing the variable name
'               arStrVarValues --> Array containing the variable value
'Caller : EVENT
'-----------------------------------------------
Private Sub Obj_NewValue_OnRefreshed(arstrVarNames() As String, arStrVarValues() As String)

Dim strHexNumber As String
Dim strTmp As String
Dim sglYourNumber As Single

On Error GoTo TRAP_Error
    
    strTmp = Hex(arStrVarValues(0))   'AA BB CC DD
    
    'Check if the strTmp having 0's in start, the number of HEX characters will be reduced (i.e. less than 8)
    'If number of characters of strTmp are less then 8, add zeros in start to complete 8 characters
    
    '---New code

    If (Len(strTmp)) < 8 Then
        For x = 1 To (8 - Len(strTmp))
            strTmp = "0" & strTmp
        Next
    End If

    '---End new code

    'swap the bytes for Little Endian: DD CC BB AA
    strHexNumber = Right$(strTmp, 2) & Mid$(strTmp, 5, 2) & Mid$(strTmp, 3, 2) & Left$(strTmp, 2)
    
    sglYourNumber = StringToSingle(strHexNumber)

    Variables(arstrVarNames(0) & "_REAL").Value = sglYourNumber
    
On Error GoTo 0
Exit Sub
 
TRAP_Error:
 MOD_General.ErrorManagement "Obj_NewValue_OnRefreshed", "ThisProject"

End Sub


'Private Sub vMyVar_ValueChange()

'Dim strHexNumber As String
'Dim sglYourNumber As Single

'    strHexNumber = Hex(vMyVar.Value)
'    sglYourNumber = StringToSingle(strHexNumber)

'    Variables("TEST_REAL").Value = sglYourNumber

'End Sub

Public Function StringToSingle(ByVal strNumber As String) As Single

Dim a(4) As Byte
Dim z As Integer

For z = 0 To 3
    a(z) = CInt("&H" & Mid$(strNumber, (4 - z) * 2 - 1, 2))
Next z
CopyMemory StringToSingle, a(0), 4

End Function
BR

Leo-Ali

shaikh_rehan
Posts: 2
Joined: Sun Nov 25, 2012 1:00 pm

Re: How to read IEEE format INTEL Litter Endian in PcVue?

Post by shaikh_rehan » Sun Nov 25, 2012 1:06 pm

Hi,

Please tell me is it possible to read the IEEE754 format in PC Vue...?Can PC vue understands the double prescion IEEE754 format..?

Post Reply