#include <QCoreApplication>
#include <QDebug>
#include<VSMD12XControl.h>
#include "qtextstream.h"
QTextStream cout1(stdout, QIODevice::WriteOnly);
void logout(QString str){
    std::cout<<str.toStdString()<<"<br>";
    std::fflush(stdout);
}
int main(int argc, char *argv[]) {
    int aaa=1000;
    QString str(argv[1]);
    QCoreApplication a(argc, argv);
    CVSMD12XControl Motercontrol;
    QString m_qstrDeviceConfigFilePath;
  //  cout1<<"adfasdfsadfsd"<<flush;
    cout1<<"Your position number is "<<str<<"<br>"<<flush;
#ifdef WIN32
     m_qstrDeviceConfigFilePath = ("D:\\03MyGit\\linux\\movingliner\\DeviceSettings.ini");
#else
    m_qstrDeviceConfigFilePath = ("/home/data/Setting/DeviceSettings.ini");
#endif

    QSettings *m_qsDeviceConfig;
    m_qsDeviceConfig = new QSettings(m_qstrDeviceConfigFilePath, QSettings::IniFormat);
    long positon =m_qsDeviceConfig->value("LINEAR SHUTTER/Position"+str).toLongLong();
    if (positon==0)
    {
        logout("<b style=\"color:red\">Can not Find the position<\/b>");
        return 0;
    }
    cout1<<"Find Configfile in "<<m_qstrDeviceConfigFilePath<<" <br> The Port of Motor is "<<m_qsDeviceConfig->value("LINEAR SHUTTER/Port").toString()<<"<br>"<<flush;
    cout1<<"Position Find  Value is "<<m_qsDeviceConfig->value("LINEAR SHUTTER/Position"+str).toLongLong()<<"<br>"<<flush;
    cout1<<"Configing The Motor <br>"<<flush;
    // m_qsDeviceConfig->value("LINEAR SHUTTER/Port").toString()
    Motercontrol.ILMES_InitializeComm(m_qsDeviceConfig->value("LINEAR SHUTTER/Port").toString());
    ControllerParams cpTest;
    Motercontrol.ILMES_InitializeParams(cpTest);




    logout("Moving  to Zero");
    Motercontrol.StartBackZero();
    //std::cout<<"beging to move position";
    logout("Moving to The Position");
    Motercontrol.MoveTo(positon);

    logout("<b style=\"color:green\">Finish the Task!!!<\/b> <br><b>Thanks For Using<\/b>");
    return 0;
   // return QCoreApplication::exec();
}
