Files
vince/vincecontrol.h

256 lines
8.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************************************
* 文件名 : vincecontrol.h
* 类名 :
* 作用 :马达控制程序
* 作者 : xin
* 邮箱 : renlixin@iris-rs.cn
* 日期 : 2020-8-5
********************************************************
* *
* _ooOoo_ *
* o8888888o *
* 88" . "88 *
* (| -_- |) *
* O\ = /O *
* ____/`---'\____ *
* .' \\| |// `. *
* / \\||| : |||// \ *
* / _||||| -:- |||||- \ *
* | | \\\ - /// | | *
* | \_| ''\---/'' | | *
* \ .-\__ `-` ___/-. / *
* ___`. .' /--.--\ `. . __ *
* ."" '< `.___\_<|>_/___.' >'"". *
* | | : `- \`.;`\ _ /`;.`/ - ` : | | *
* \ \ `-. \_ __\ /__ _/ .-` / / *
* ======`-.____`-.___\_____/___.-`____.-'====== *
* `=---=' *
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
* 佛祖保佑 长发永存 *
* *
********************************************************/
#ifndef VINCECONTROL_H
#define VINCECONTROL_H
#ifdef VINCECONTROL_LIB
# define VINCECONTROL_EXPORT Q_DECL_EXPORT
#else
# define VINCECONTROL_EXPORT Q_DECL_IMPORT
#endif
#define LOGOUT
#include "vincecontrol_global.h"
#include "QString"
#include "QStringList"
#include "QList"
#include <QObject>
#include <QSerialPort>
#include <QTcpServer> //监听套接字
#include <QTcpSocket> //通信套接字
#include "QByteArray"
enum ProTools
{
RS232 = 0,
RS485 = 1,
NETTCP=2
};
/********************************************************************
* 描述:马达控制程序
* 使用步骤
* 1初始话 需要告诉通讯协议Vince规定的
* 2如果是485 请设置id 默认为0
* 3) serialconnect 建立链接
* 4使用
* 2020-8-5立新
*******************************************************************/
class VINCECONTROL_EXPORT VinceControl:public QObject
{
Q_OBJECT
public:
//************************************
// Method: VinceControl
// FullName: VinceControl::VinceControl
// Access: public
// Returns:
// Qualifier:
// Parameter: ProTools 通讯协议 RS485 或者 RS232
//************************************
VinceControl(ProTools proto);
//************************************
// Method: VinceControl //走网络协议 需要两个参数 第一个为NETTCP 第二个为端口 6000或者6001
// FullName: VinceControl::VinceControl
// Access: public
// Returns:
// Qualifier:
// Parameter: ProTools proto
// Parameter: int port
//************************************
VinceControl(ProTools proto,int port);
~VinceControl();
//************************************
// Method: serialconnect
// FullName: VinceControl::serialconnect
// Access: public
// Returns: bool
// Qualifier:
// Parameter: QString comname 串口名称
// Parameter: QString bandrate 串口波特率
//************************************
bool serialconnect(QString comname,QString bandrate);
//************************************
// Method: Handshacke
// FullName: VinceControl::Handshacke
// Access: public
// Returns: void
// Qualifier:
//************************************
void Handshacke(QString motorid = "non");
//************************************
// Method: SetRS485ID
// FullName: VinceControl::SetRS485ID
// Access: public
// Returns: void
// Qualifier:
// Parameter: QString id RS485 id
//************************************
void SetRS485ID(QString id);
//************************************
// Method: 电机使能
// FullName: VinceControl::EnableMotro
// Access: public
// Returns: void
// Qualifier:
//************************************
void EnableMotro(QString motornetid="non");
//************************************
// Method: 取消使能
// FullName: VinceControl::DisableMotro
// Access: public
// Returns: void
// Qualifier:
//************************************
void DisableMotro(QString motornetid = "non");
//************************************
// Method: SendCommandtoSerial
// FullName: VinceControl::SendCommandtoSerial
// Access: public
// Returns: void
// Qualifier:
// Parameter: QString str 命令 不包含id 如果是nettcp 默认想第一个发送
//************************************
void SendCommandtoMotor(QString str);
//************************************
// Method: SendCommandtoMotor //两个参数 仅网络协议 第一个为命令 第二个为马达
// FullName: VinceControl::SendCommandtoMotor
// Access: public
// Returns: void
// Qualifier:
// Parameter: QString str
// Parameter: int motorid
//************************************
void SendCommandtoMotor(QString str,QString modor);
//************************************
// Method: MoveSetDistance 电机左移/右移 一定数量(不是距离)
// FullName: VinceControl::MoveSetDistance
// Access: public
// Returns: void
// Qualifier:
// Parameter: long distance
//************************************
void MoveSetDistance(long distance, QString motornetid = "non");
//************************************
// Method: MoveModar 电机左移/右移 direction是方向
// FullName: VinceControl::MoveModar
// Access: public
// Returns: void
// Qualifier:
// Parameter: bool direction 方向
//************************************
void MoveMotar(bool direction, QString motornetid = "non");
//************************************
// Method: SettingSpeed 设置速度
// FullName: VinceControl::SettingSpeed
// Access: public
// Returns: void
// Qualifier:
// Parameter: unsigned long Speed 速度 正值 无方向
//************************************
void SettingSpeed(unsigned long Speed, QString motornetid = "non");
//************************************
// Method: MovetoZero 归零
// FullName: VinceControl::MovetoZero
// Access: public
// Returns: void
// Qualifier:
//************************************
void MovetoZero(QString motornetid = "non");
//************************************
// Method: GetLocationNow 获取当前至0点位置
// FullName: VinceControl::GetLocationNow
// Access: public
// Returns: long 位置
// Qualifier:
//************************************
long GetLocationNow();
//************************************
// Method: MoveToLocation 移动到某位置据0点
// FullName: VinceControl::MoveToLocation
// Access: public
// Returns: void
// Qualifier:
// Parameter: long Location 距离零点的位置
//************************************
void MoveToLocation(long Location);
//************************************
// Method: SettingUpandDownSpeed 设置加减速度
// FullName: VinceControl::SettingUpandDownSpeed
// Access: public
// Returns: void
// Qualifier:
// Parameter: int addspeed 加速度
// Parameter: int downspeed 减速度
//************************************
void SettingUpandDownSpeed(int addspeed, int downspeed);
void StopMotormove(QString motornetid = "non");
QStringList Motorlist;
signals:
void SendLogToCallClass(QString str);
public slots :
void onNewTcpClinetConnet();
void onReciveFromClinet();
void onClinetDisConnet();
private:
QSerialPort *serial;
bool IsMotorInit;
ProTools protools;
QString RS485ID;
unsigned long speed;
QTcpServer *tcpServer; //定义监听套接字tcpServer
QList<QTcpSocket *>tcpSocket; //定义通信套接字tcpSocke
void SendLog(QString str);
QList<bool> isSettingSpeedlist;
QList<int> Speedlist;
bool SpeedisSet;
int Speednow;
//
void SettingSpeedByThis(long Speed, QString motornetid = "non");
};
#endif // VINCECONTROL_H