Files
vince/vincecontrol.h

325 lines
10 KiB
C++
Raw Permalink 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
};
struct ByteBack
{
float Speed;
int Location;
unsigned int Stata;
};
/********************************************************************
* 描述:马达控制程序
* 使用步骤
* 1 初始化 需要告诉通讯协议Vince规定的motor = new VinceControl(NETTCP, 6000);
* 2 通过 motor->IsMotorInit 来判断是否右马达接入
* 建议:
* 1) 可以用SettingZeroLocation结合传感器的是指来设置零为
* 2关于传感器的设置均在initmotor函数里
* 注意:
* 类中所有默认参数再不设置的情况下均指网络通讯的第一个设备id
* 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: MoveToLocation 移动到某位置据0点
// FullName: VinceControl::MoveToLocation
// Access: public
// Returns: void
// Qualifier:
// Parameter: long Location 距离零点的位置
//************************************
void MoveToLocation(long Location, QString motornetid = "non");
//************************************
// Method: Handshacke
// FullName: VinceControl::Handshacke
// Access: public
// Returns: void
// Qualifier:
//************************************
void Handshacke(QString motorid = "non");
//************************************
// Method: setSyncMode 设置时间为双马达同步模式
// FullName: VinceControl::setSyncMode
// Access: public
// Returns: void
// Qualifier:
//************************************
void setSyncMode();
//************************************
// Method: SettingZeroLocation 马达归零
// FullName: VinceControl::SettingZeroLocation
// Access: public
// Returns: void
// Qualifier:
// Parameter: QString motorid
//************************************
void SettingZeroLocation(QString motorid = "non");
//************************************
// 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(QString motornetid = "non");
//************************************
// Method: SettingUpandDownSpeed 设置加减速度
// FullName: VinceControl::SettingUpandDownSpeed
// Access: public
// Returns: void
// Qualifier:
// Parameter: int addspeed 加速度
// Parameter: int downspeed 减速度
//************************************
void SettingUpandDownSpeed(int addspeed, int downspeed, QString motornetid = "non");
//************************************
// Method: StopMotormove 停止马达
// FullName: VinceControl::StopMotormove
// Access: public
// Returns: void
// Qualifier:
// Parameter: QString motornetid
//************************************
void StopMotormove(QString motornetid = "non");
//************************************
// Method: GetState
// FullName: VinceControl::GetState
// Access: public
// Returns: ByteBack
// Qualifier:
// Parameter: QString motorid
//************************************
ByteBack GetState(QString motorid = "non");
//************************************
// Method: SetRS485ID
// FullName: VinceControl::SetRS485ID
// Access: public
// Returns: void
// Qualifier:
// Parameter: QString id RS485 id
//************************************
void SetRS485ID(QString id);
//************************************
// Method: serialconnect
// FullName: VinceControl::serialconnect
// Access: public
// Returns: bool
// Qualifier:
// Parameter: QString comname 串口名称
// Parameter: QString bandrate 串口波特率
//************************************
bool serialconnect(QString comname, QString bandrate);
//************************************
// Method: initMotor 设置左右极限 s1是为左极限 且到s1后会将s1位置设置为0 s2是右极限 归零传感器是指为s1
// FullName: VinceControl::initMotor
// Access: public
// Returns: void
// Qualifier:
// Parameter: QString motornetid
//************************************
void initMotor(QString motornetid = "non");
QStringList Motorlist;
bool IsMotorInit;
signals:
void SendLogToCallClass(QString str);
public slots :
void onNewTcpClinetConnet();
void onClinetDisConnet();
private:
QSerialPort *serial;
void onReciveFromClinet(QString motornetid = "non");
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 GetCommonRetrun(QByteArray &buf,QString id="non");
//
void SettingSpeedByThis(long Speed, QString motornetid = "non");
ByteBack TranslateBytedata(QByteArray buf, QString motornetid = "non");
void initme();
bool isSyncMotor;
};
#endif // VINCECONTROL_H