Connecting to the Velmex motor using C++

73 views
Skip to first unread message

Xicheng Zheng

unread,
Jul 17, 2015, 2:55:40 PM7/17/15
to velmex-...@googlegroups.com
Hello, I have some code here intended to communicate with the motor without Cosmos. It uses a class called CSerial: "http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c2503/CSerial--A-C-Class-for-Serial-Communications.htm"

However, it fails to open the port. It communicates fine with com1, the communications port. Can anyone tell me what's going on?

///////////////////////////////////////////////////////////////////////////////////////////////
//                        VXM Controller.cpp
///////////////////////////////////////////////////////////////////////////////////////////////

#include <assert.h>
#include <iostream>
#include <string>
#include "Serial.h"

using namespace std;

int* MOTOR_NUM;

int main()
{
    cout << "Enter the com port number: " << endl;
    int portInt;
    cin >> portInt;

    MOTOR_NUM = &portInt;

    CSerial serialPort;
    CSerial* P_serialPort = &serialPort;

    if (P_serialPort->Open(*MOTOR_NUM, 9600))
    {
        cout << "Port opened successfully" << endl;
        string* command;
        string userInput = "";

        do
        {
            //Get the command in the form of a string
            cout << "What would you like to do?" << endl
                << "Enable on-line mode (E or F)" << endl
                << "Verify status (V)" << endl
                << "Move x units (I1Mx)" << endl
                << "Quit C++ dialog (q)" << endl;
            cin >> userInput;

            command = &userInput;

            //Change the command (string) into a const char*
            const char* message = (*command).c_str();

            //Send the command that is in the form of a const char*
            cout << "Sending message: " << message << endl;           
            int bytesRead = P_serialPort -> SendData(message, (*command).length());
            cout << "There were " << bytesRead << " bytes read to the serial port." << endl;

            //Check that all of it sent
            assert(bytesRead == strlen(message));

            char* lpBuffer = new char[500];
            int nBytesRead = P_serialPort->ReadData(lpBuffer, 500);
            delete[]lpBuffer;
            cout << "Data returned: " << *lpBuffer << endl;
        } while (*command != "q");
    }
    else
    {
        cout << "Failed to open port!" << endl;
        return 0;
    }

    cout << "Ending program. " << endl;
    P_serialPort->Close();

    return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////

Cliff

unread,
Jul 17, 2015, 8:10:11 PM7/17/15
to velmex-...@googlegroups.com
although code from some other site is totally unsupported.
If you use the tools from www.velmexcontrols.com on the software page and run both of the following
1.) Serial Port Diagnostic
2.) COSMOS under "Tools--->Troubleshooting---> System Diagnostic
And email the results of both those tests to sup...@velmex.com along with the information printed on the slide or rotary table you are using and the serial number from the VXM controller on the back then we can probably fix the problem fairly quickly

Zeng, Sicheng

unread,
Jul 20, 2015, 8:45:50 AM7/20/15
to velmex-...@googlegroups.com
The connection to the website, velmexcontrols.com, times out and I can't load those programs.

--
You received this message because you are subscribed to a topic in the Google Groups "Velmex Controls" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/velmex-controls/HBW8IdkA7bw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to velmex-contro...@googlegroups.com.
To post to this group, send email to velmex-...@googlegroups.com.
Visit this group at http://groups.google.com/group/velmex-controls.
For more options, visit https://groups.google.com/d/optout.

Support

unread,
Jul 20, 2015, 10:19:43 AM7/20/15
to velmex-...@googlegroups.com, zen...@ncssm.edu
I am unaware why it may be timing out for you cause it is working here.

I also have copies at www.velmex.com  under the Downloads tab if you drop down the "Software / Drivers / Patches" dropdown section,.
You received this message because you are subscribed to the Google Groups "Velmex Controls" group.
To unsubscribe from this group and stop receiving emails from it, send an email to velmex-contro...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages