VB.NET - Get Position

hi, i am an absolutely newbie

I want to read the position of a servo

my try:

buffer3(0) = 144
buffer3(1) = ComboBox1.Text      
SerialPort1.Write(buffer3, 0, 2)
SerialPort1.Read(buffer3, 0, 2)
TextBox3.Text = buffer3(1)

please post me the right code

Hello,

Please tell us what servo controller you are trying to use. Also, have you succeeded in setting the position yet? What did your “try” do?

-Paul

I use the “Mini Maestro 24-Channel USB Servo Controller”

i need the NB.net code to read a position of a servo
(https://www.pololu.com/docs/0J40/5.e → Get Position)

my try gives a value in the range 15 - 30 back.
But the position i set, is in range 0 – 254

is this the right code and i have to equalize (15 = pos.0 and 30 = pos.254)??? but the positions are very inexactly yet

sorry for my english, i hope you understand :mrgreen: :mrgreen: :mrgreen:

So your program is almost working. This is important information that you should have included in your first post to save everyone’s time.

Your problem is that you are only looking at ONE of the two bytes of the response; you are looking at the high byte. Try something like this (I’m not sure if this is valid VB code or not):

TextBox3.Text = buffer3(0) + (buffer3(1) << 8);

–David

google says me that “<<” a left shift of C++ is for binary numbers

my program send and receive decimal numbers! not binary or hexa code

what do the “<< 8” in your code

if i only add the 2 bytes the numbers are also shit like before
we in germany say “gequirlte scheisse” :mrgreen: :mrgreen: :mrgreen:

Did you actually try the code that I posted? Did it work? When someone tells you an easy way to fix your program, you should try their solution before asking for more help, and you should say what the results were!

Your program talks to the Maestro. The Maestro sends its Get Position response as a two-byte, little endian integer. There is nothing “decimal” about it.

It shifts the number to the left by 8 bits… equivalent to multiplying by 256. If “<< 8” is not valid in Visual Basic, try replacing it with “* 256”.

–David