Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Looking for VB6 sample code for ‘get_ position’


#1

Mini Maestro 12
It works in Maestro Control Center.
Maestro Control Center says, connected to #00100775
Does that mean my device number is 100775?

Trying to send this,
Pololu protocol: 0xAA, device number, 0x10, channel number
Can’t get a response other than blank.
I have channel 6 configured as an Input.
I just want to know if a button has been pushed or not.
I know I am antique, but VB6 is the only language I am proficient with.
If anyone has any sample code that works I would greatly appreciate it.

Thanks


#2

Hello.

The values listed in the “Connected to:” drop-down menu are the serial numbers of each Maestro unit connected to your computer. The device number can be found under the “Serial Settings” tab in the Maestro Control Center.

As for sample code, there is another member who shared his code for communicating with a Maestro servo controller from Visual Basic 6.0 that you might find useful.

If you continue to have issues, you can post your code and pictures of your setup, and I would be happy to take a look.

- Amanda


#3

Thanks Amanda for your help.

I am able to control the servos just fine.
I want one of the channels to be an input so I can tell if a button is pushed.

’ the manual says to send the flowing and it will return a value. My device is number 12 and the channel is 6.

'Pololu protocol: 0xAA, device number, 0x10, channel number    
    
    MSComm1.Output = Chr(170) & "12" & Chr(16) & "6"    ''''  I think this is the problem line.

Here is a bigger section of code.

Here is the code I have been experimenting with

  MSComm1.CommPort = 7

    MSComm1.Settings = "9600,N,8,1"

    MSComm1.PortOpen = True 'Open the port

    
   ' MSComm1.RThreshold = 1
    MSComm1.InputLen = 1

    StartTime = Now
   
       
'Pololu protocol: 0xAA, device number, 0x10, channel number    
    
    MSComm1.Output = Chr(170) & "12" & Chr(16) & "6"
     
     
     
     
    ReturnFlag = ""
    Do
        If MSComm1.InBufferCount >= 10 Then Exit Do: ' got enough bytes
        i = DateDiff("s", StartTime, Now)
        If i > 5 Then ReturnFlag = "Timeout": Exit Do: ' timeout in 5 seconds
    Loop
        If ReturnFlag <> "Timeout" Then
            For i = 1 To 10: ' read in 10 bytes
                SerialInputString = SerialInputString + MSComm1.Input
            Next
        Else
            SerialInputString = "No data"
        End If
       '' MSComm1.PortOpen = False
        
    
          DoEvents
        MsgBox (SerialInputString)

#4

I added code tags ([ code ] [ /code ] without spaces) to your post to make it easier to read; please use this method to post code in the future.

You are correct. Your output line is not formatted properly. It looks like you were sending some ASCII-encoded strings instead of just sending the binary bytes that are needed. You might try making the output like this:

MSComm1.Output = Chr(170) & Chr(12) & Chr(16) & Chr(6)   ' Chr(12) = '0x0C'!="12"

Also, I noticed that you are trying to read in 10 bytes from the receive buffer. The get position command should only returns 2 bytes (position low 8 bits, position high 8 bits), so you probably would want to change the number of bytes to read from the buffer to 2.

- Amanda


#5

Amanda, Thank You Thank You!
This works now!

[code]
MSComm1.CommPort = 7

MSComm1.Settings = "9600,N,8,1"

MSComm1.PortOpen = True 'Open the port

MSComm1.InputLen = 2

’ device is 12 channel is 6
’Pololu protocol: 0xAA, device number, 0x10, channel number
’Response: position low 8 bits, position high 8 bits

 MSComm1.Output = Chr(170) & Chr(12) & Chr(16) & Chr(6)  ' it won't work without this line here too.
 DoEvents
 
 While True
    MSComm1.Output = Chr(170) & Chr(12) & Chr(16) & Chr(6)
    DoEvents
    txtInput.Text = (Asc(MSComm1.Input))
    Me.Refresh
    Form1.Show
 Wend
   
   
   [/code]