Jump to content

Add bytes


Recommended Posts

Hi, I found a dll on this forum to create structs by calling a dll.

It was posted a long time ago, before structures were included in AutoIt.

It's called DllMem.dll. You don't need it for my problem though.

I have a piece of code (not in AutoIt, but that doesn't matter either)

$ReadInt = new DLL("DllMem.dll", "ReadInt", INT, INT+INT); // just loading the function nothing special
$ReadByte = new DLL("DllMem.dll", "ReadByte", INT, INT+INT); // same story

$ret = $ReadInt( $POINT, 4 ); // Returns 757 (byte 0-3)

$ReadByte( $POINT, 0 ); // Returns 67 (byte 0)
$ReadByte( $POINT, 1 ); // Returns 1 (byte 1)
$ReadByte( $POINT, 2 ); // Returns 0 (byte 2)
$ReadByte( $POINT, 3 ); // Returns 0 (byte 3)

Now, what if I don't know 757. What do I have to do with 67, 1, 0 and 0 to get to 757?

Thanks, Kip.

Edited by Kip
Link to comment
Share on other sites

...I have a piece of code (not in AutoIt, but that doesn't matter either)...

Netherlands - You know you really probably should write your code in the selfsame language from beginning to end - "Not AutoIt" is probably a language that does not use "$" to designate a variable - what language are you trying to use?

Das Häschen benutzt Radar

Link to comment
Share on other sites

Hi, I found a dll on this forum to create structs by calling a dll.

It was posted a long time ago, before structures were included in AutoIt.

It's called DllMem.dll. You don't need it for my problem though.

I have a piece of code (not in AutoIt, but that doesn't matter either)

$ReadInt = new DLL("DllMem.dll", "ReadInt", INT, INT+INT); // just loading the function nothing special
 $ReadByte = new DLL("DllMem.dll", "ReadByte", INT, INT+INT); // same story
 
 $ret = $ReadInt( $POINT, 4 ); // Returns 757 (byte 0-3)
 
 $ReadByte( $POINT, 0 ); // Returns 67 (byte 0)
 $ReadByte( $POINT, 1 ); // Returns 1 (byte 1)
 $ReadByte( $POINT, 2 ); // Returns 0 (byte 2)
 $ReadByte( $POINT, 3 ); // Returns 0 (byte 3)

Now, what if I don't know 757. What do I have to do with 67, 1, 0 and 0 to get to 757?

Thanks, Kip.

Have you got any more example values? I don't see the link between 67,1 and 757. Are you sure the dll function is returning data from the same struct for RedByte and ReadInt?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Oh damn, there was a bug in my script. I'm starting to see a connection now, wait just give me a minute.

Edit:

ok eerm:

If ReadInt is below 128 then the first ReadByte = the same value as ReadInt.

When ReadInt is above 128 but below 256, ReadInt = 128+(128+ReadByte), and ReadByte is a negative number

after that the second ReadByte begins counting, and so on.

Edit2: I just read it again and I can understand if you don't get it :D

There must be some kind of Bit function for this...

examples:

ReadInt = 70 ; it's under 128, so the first ReadByte is the same.

Byte1 = 70

Byte2 = 0

Byte3 = 0

Byte4 = 0

=

ReadInt = 175 ; It's above 128 and below 256, so the first ReadByte = 128+(128+-81)

Byte1 = -81 ; 128+(128+-81) = 175

Byte2 = 0

Byte3 = 0

Byte4 = 0

ReadInt = 260

Byte1 = 4

Byte2 = 1

Byte3 = 0

Byte4 = 0

ReadInt = 390

Byte1 = -122

Byte2 = 1

Byte3 = 0

Byte4 = 0

256 is the maximal number of different values one byte can hold. So... it makes sense (somewhere)

Edited by Kip
Link to comment
Share on other sites

I'm sorry, I don't understand what you're trying to say.

Edit: Ooh, wait... :D

$s1 = dllstructcreate("int")
$s2 = dllstructcreate("ubyte[4]",dllstructgetptr($s1))

Dllstructsetdata($s1,1,260)

ConsoleWrite(dllstructgetdata($s2,1,1) & @CRLF)
ConsoleWrite(dllstructgetdata($s2,1,2) & @CRLF)
ConsoleWrite(dllstructgetdata($s2,1,3) & @CRLF)
ConsoleWrite(dllstructgetdata($s2,1,4) & @CRLF)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

$s1 = dllstructcreate("int")
$s2 = dllstructcreate("ubyte[4]",dllstructgetptr($s1))

Dllstructsetdata($s1,1,260)

ConsoleWrite(dllstructgetdata($s2,1,1) & @CRLF)
ConsoleWrite(dllstructgetdata($s2,1,2) & @CRLF)
ConsoleWrite(dllstructgetdata($s2,1,3) & @CRLF)
ConsoleWrite(dllstructgetdata($s2,1,4) & @CRLF)
You're fast

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...