#include "testdll.h"
#include "QThread"

testdll::testdll(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	motor = new VinceControl(NETTCP, 6000);
	connect(ui.startmotor, &QPushButton::clicked, this, &testdll::onbeginstart);
	connect(ui.pushButton, &QPushButton::clicked, this, &testdll::onfanzhuan);
	connect(ui.pushButton_2, &QPushButton::clicked, this, &testdll::onstop);
	connect(ui.pushButton_3, &QPushButton::clicked, this, &testdll::oninfomotor);
	connect(motor, &VinceControl::SendLogToCallClass, this, &testdll::onlogcom);
	timer = new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(oninfomotor()));
	timer->start(2000);


}

testdll::~testdll()
{
	motor->StopMotormove();
	delete motor;

}

void testdll::onbeginstart()
{
	//motor->Handshacke();
	motor->EnableMotro();

		//motor->StopMotormove();
		long aa = ui.lineEdit->text().toLong();
		motor->StopMotormove();
		motor->SettingSpeed(aa);
		motor->MoveMotar(true);
		//fangxiang = !fangxiang;
		//QThread::sleep(5);
	



}

void testdll::onfanzhuan()
{

//	motor->StopMotormove();
	long aa = ui.lineEdit->text().toLong();
	motor->StopMotormove();
	motor->SettingSpeed(aa);
	motor->MoveMotar(false);
	motor->SendCommandtoMotor("cfg\n");
	//fangxiang = !fangxiang;
	//QThread::sleep(5);
}

void testdll::onstop()
{
	//motor->StopMotormove();
	//motor->SendCommandtoMotor("cfg\n");
	motor->SettingZeroLocation();
}

void testdll::onlogcom(QString str)
{
	ui.textEdit->append(str);
	//motor->SendCommandtoMotor("cfg\n");
}

void testdll::oninfomotor()
{
	if (motor->IsMotorInit)
	{
		motor->GetState();
	}
	
}
