Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

use of &h for long variables


kokihualpa Mar 31, 2020 09:52 AM

Is possible use &h in variables long format?.

for example:

Public longvar as long

beginprog

longvar=2694

longvar=&h+longvar (I think it would transmit &h2694, that is hexadecimal number)

In need the hexadecimal be transmit in long format and no string. Actually the longvar is not constant and it will take variable values.


JDavis Mar 31, 2020 10:39 AM

I hope this example clarifies how to go about it.

 

Public longvar As Long = &h26940000 'Long variables are 4 bytes long

Public InputHex As String * 9 = "0A0B0C0D"
Public longvar2 As Long

BeginProg
  Scan (1,Sec,0,0)

    SerialOutBlock (Com1,longvar,2) 'Outputs first two bytes of longvar

    longvar2 = HexToDec(InputHex)
    SerialOutBlock (Com1,longvar2,4) 'Output all 4 bytes of longvar2

  NextScan
EndProg

 


kokihualpa Mar 31, 2020 02:10 PM

Thank you

But they are constants. I will have variables continuously and I need they are in long format.

like in this case:

But if they are variables values:

Public longvar As Long = &h26940000 'Long variables are 4 bytes long

BeginProg
  Scan (1,Sec,0,0)

    SerialOutBlock (Com1,longvar,2) 'Outputs first two bytes of longvar

JDavis Mar 31, 2020 02:25 PM

The example I provided does work with variables. You can change the values of longvar and InputHex from the Public table.


Sam Apr 11, 2020 03:58 PM

It is also interesting to note the following. With the following concatenation, the datalogger will attempt to treat the righthand side as a 32 bit signed integer.

Public hexStr1 As String * 10 = "0A0B0C0D"
Public hexStr2 As String * 10 = "&h0A0B0C0D"

Public flt1 As Float
Public flt2 As Float

Public lng1 As Long
Public lng2 As Long

Public dbl1 As Double
Public dbl2 As Double

BeginProg
  Scan (1,Sec,0,0)

    'result is 1.684961e+08
    flt1 = "&h" & hexStr1
    flt2 = hexStr2

    'result is 168,496,141
    lng1 = "&h" & hexStr1
    lng2 = hexStr2

    'result is 168,496,141
    dbl1 = "&h" & hexStr1
    dbl2 = hexStr2

  NextScan
EndProg

 


kokihualpa Apr 29, 2020 08:05 PM

Thank you very much. I could use the concatenation successfully to my purpose.

Log in or register to post/reply in the forum.