Center of Gravity to Serial
Martin from Spain  [3 posts]
10 year
I use the "Center of Gravity" module to output the results to the Serial Com-Port.
This works fine only the data wraps to 0 if the result is > 255.
So, is there a way  to send a number bigger than 255? With a screen resolution of 640*480 the most right pint on the X axis is  a number of aprox 600.
Thanks Martin
Carl from United States  [18 posts] 10 year

The problem is that a single byte can only
contain values up to 255.  In order to send
larger numbers you need to break the number
into a pair of bytes.  One means of doing
this is:

B1 = Cbyte(YourNumber And 255)
B2 = Cbyte(Int(YourNumber/256))

The program you're sending this data to will
need to reassemble the original number in a
similar fashion, such as:

YourNumber = B2 * 256 + B1

Martin from Spain  [3 posts] 10 year
Lets assume that the variable [COG_X] has the value of 11001000 (400 dec).

I do:

COG_X_lo = COG_X & 255 //  result 11001000
COG_X_hi= COG_X/ 256   //  result 00000001

Now, the big money thing is: how do I put a function like this into the serial module?
Cheers Martin

Carl from United States  [18 posts] 10 year

You simply place the function in a VBscript module
located before the serial module.  The VBscript
concatenates the bytes into a string, which is
placed into the global variable space with the
SetVariable function.  Within the serial module
send the contents of that variable.
For example:

In the VBscript module:
SerData = B1 & B2
SetVariable "SerData", SerData

In the Serial module utilize SerData as your
send sequence:

Hope this covers it  :)

Martin from Spain  [3 posts] 10 year

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index