News:

  • August 29, 2026, 05:11:01 PM

Login with username, password and session length

Author Topic: IP Address as DWord Variable?  (Read 11846 times)

FuzzyLogic

  • Newbie
  • *
  • Posts: 3
IP Address as DWord Variable?
« on: December 19, 2013, 03:34:11 PM »
I'm trying to write code that would allow a user to input an ip address on a C-More panel and have that address stored as a DWord variable in the Do-more. My idea is to convert each segment of the ip address to hex and then write this hex number to a DWord variable.  As an example, I'll use the ip address: 192.168.2.1.  Converting this address to Hex, I get 0xC0A80201.  Converting this Hex number to decimal I get 3,232,236,033 which is too big a number to fit in a DWord location.  When I look at the address in decimal data view, it is displayed as -1,062,731,263.  Using a decimal to hex calculator, I see that this number is also equal to 0xC0A80201 but I have not idea how to convert from hex to a negative decimal number.  Any help would be greatly appreciated! 

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: IP Address as DWord Variable?
« Reply #1 on: December 19, 2013, 04:05:31 PM »
Just use 4 separate numerical entries on the CMore, then load those 4 values into the 4 parts of the address variable.
Example:
MOVE
V0
D0:B3

MOVE
V1
D0:B2

MOVE
V1
D0:B2

MOVE
V0
D0:B3
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
https://premiersi.com

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: IP Address as DWord Variable?
« Reply #2 on: December 19, 2013, 07:45:28 PM »
Entering them in separately would be the simplest to do. However, if someone had the time and willing to take on such a challenge, it would be a worthy cause to write a task to take the IP address as a string and then using the plethora of string functions in the Do-More to parse out the individual octets and combine them into a DWORD.

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: IP Address as DWord Variable?
« Reply #3 on: December 19, 2013, 09:31:10 PM »
ATU, I believe that would actually be quite simple to do. If I can remember I will try to post a sample task to do this...
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
https://premiersi.com

FuzzyLogic

  • Newbie
  • *
  • Posts: 3
Re: IP Address as DWord Variable?
« Reply #4 on: December 20, 2013, 12:47:33 AM »
Plcnut - Thanks!  I keep forgetting about the power of the MOVE instruction...  Your idea would certainly be the simplest and would probably have fewer chances of input errors than having the user put the whole ip address in as a string.  I'll give your idea a try.   

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: IP Address as DWord Variable?
« Reply #5 on: December 20, 2013, 07:10:17 AM »
In the posted sample, make sure that you change all of the V addresses to V???:B0 or the MOVEs won't work.
I posted a sample called IPSetup in the DoMore Example programs section of the forum that seems to work very well though. Check it out.
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
https://premiersi.com