Pololu in Linux with VMware(virtual machine)6 channel Maestro ‘device not open’ in ubuntu&Qt

Host system: ios(Mac)
guest system: linux

I install linux on mac system by using VMware. When I connect pololu with the computer by using USB it has ttyACM0 and ttyACM1 under dev. Now I want to use pololu to control a gimbal but it always shows “device not open”. What’s the problem? Is it because I use a virtual machine?

6 channel Maestro ‘device not open’ in ubuntu&Qt

The code.
servocontroller.h

class ServoController
{
public:
    virtual ~ServoController();
    void createSerialPort();
    void setTarget(unsigned char channelNumber, unsigned short target );

private:
    static const unsigned short mMinChannelValue = 4000;
    static const unsigned short mMaxChannelValue = 8000;
    unsigned short target;
    unsigned char channelNumber;
    QSerialPort* myCom;
    QByteArray command;
};

servocontroller.cpp

void ServoController::createSerialPort()//
{
    myCom= new QSerialPort();
    myCom->setPortName("/dev/ttyACM0");
    myCom->open(QIODevice::WriteOnly);
    myCom->setBaudRate(9600);
    myCom->setDataBits(QSerialPort::Data8);
    myCom->setParity(QSerialPort::NoParity);
    myCom->setStopBits(QSerialPort::OneStop);
    myCom->setFlowControl(QSerialPort::NoFlowControl);
}

ServoController::~ServoController()
{
    myCom->close();
}

void ServoController::setTarget(unsigned char channelNumber,unsigned short target )
{
    if (target<mMinChannelValue ){
        target=mMinChannelValue;
    }
    if(target>mMaxChannelValue){
        target=mMaxChannelValue;
    }

    command.resize(4);
    command[0]=0x84;  
    command[1]=channelNumber; 
    command[2]=(char)(target & 0x7F);  
    command[3]=(char)((target >> 7) & 0x7F);    
    myCom-> QSerialPort::write(command);

    //QString string = QString(command.toHex());
    //qDebug()<<string;

}

main.cpp

// main.cpp
#include <servocontroller.h>
int main()
{
    QString portName = "/dev/ttyACM0";
    unsigned int baudRate=9600;
    ServoController com;
    com.createSerialPort(portName, baudRate);
while(true){
    com.setTarget(0x02,6000);
}
}

ERROR:QIODevice::write: device not open

Hello.

I have moved your post to the “Servo controllers and servos” category.

I am sorry you are having trouble controlling your Micro Maestro 6-Channel USB Servo Controller from an Ubuntu VMWare guest system. Are you really running iOS on your Mac, or is it Mac OS X?

In general, I have had bad experiences using USB devices on a virtual machine. I would not be surprised if the problem was due to VMWare’s USB emulation. I would recommend compiling and running that program directly on your Mac if possible.

It is also possible that the problem is in your code, so you might want to try compiling our cross-platform C example code, which can be found in the Serial Example Code section of the Maestro user’s guide. If our C example works inside VMWare, then it would mean that the problem is in your code.

Does your code actually compile? I see you are calling createSerialPort with two arguments, but you defined createSerialPort to not take any arguments.

The documentation for QSerialPort’s open method says that it returns false if it fails; I recommend that you check the return value to see whether it succeeded in opening the port. If it returns false, you can use the error method to see what the exact error was, which should help in troubleshooting.

–David

It is Mac OS X. And the program can’t run directly on my Mac, so I choose to install the virtual machine.

The problem is that I don’t know weather the serial is connected. If not how to connect it?

I am not sure what you mean by “whether the serial is connected”; could you try rephrasing the question? I still recommend that you try running our cross-platform C example code, and I also recommend checking the return value of QSerialPort’s open method so you can get a better error message from Qt.

–David

The code seems to be right. The problem is that I have installed MaestroControlCenter but can’t find ttyACM0 and ttyACM1.

Even if your code is right, trying both of the things I suggested above would probably help you get a better error message, which would probably help you troubleshoot the problem.

The Maestro Control Center software does not create or use the Maestro’s serial ports. Without installing any software or drivers, you should be able to plug a Maestro into a Linux or Mac OS X machine and see two entries for its virtual serial ports in the /dev/ directory.

I am not sure what you mean by “can’t find ttyACM0 or ttyACM1” because in your first post, you said “it has ttyACM0 and ttyACM1 under dev”. Can you try running the following command in a terminal inside your Ubuntu machine and then post the entire output here?

ls /dev/tty*

–David

When I run ls /dev/ttyACM*
it shows:
c@ubuntu:~$ ls /dev/ttyACM* /dev/ttyACM0 /dev/ttyACM1

It looks like your Ubuntu machine is recognizing the Maestro’s virtual serial ports. If you want to get your Qt program working, I suggest doing the troubleshooting steps I mentioned above and then posting your results here. Please let me know if you have any questions.

–David