mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-10-19 03:49:42 +08:00
添加了位置定标程序 及位置移动相关程序源码
This commit is contained in:
16
othersoft/shuttercali/source/LinearShutter/AbstractPort.h
Normal file
16
othersoft/shuttercali/source/LinearShutter/AbstractPort.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "VSMD12XMiscDefines.h"
|
||||
#include <string>
|
||||
class CAbstractPort
|
||||
{
|
||||
public:
|
||||
virtual void InitPort(PortInfo portinfo) = 0;
|
||||
virtual bool SetPort() = 0;
|
||||
virtual bool Open() = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual std::string ReadAll(int waite=5000) = 0;
|
||||
virtual int Write(const std::string strSend) = 0;
|
||||
|
||||
};
|
||||
|
1415
othersoft/shuttercali/source/LinearShutter/VSMD12XControl.cpp
Normal file
1415
othersoft/shuttercali/source/LinearShutter/VSMD12XControl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
146
othersoft/shuttercali/source/LinearShutter/VSMD12XControl.h
Normal file
146
othersoft/shuttercali/source/LinearShutter/VSMD12XControl.h
Normal file
@ -0,0 +1,146 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
#include "AbstractPort.h"
|
||||
using namespace std;
|
||||
// #ifdef IRIS_API_EXPORTS
|
||||
//
|
||||
// #ifdef __cplusplus
|
||||
// #define IRIS_API_FUNC extern "C" __declspec(dllexport)
|
||||
// #else
|
||||
// #define IRIS_API_FUNC __declspec(dllexport)
|
||||
// #endif
|
||||
//
|
||||
// #else
|
||||
//
|
||||
// #ifdef __cplusplus
|
||||
// #define IRIS_API_FUNC extern "C" __declspec(dllimport)
|
||||
// #else
|
||||
// #define IRIS_API_FUNC __declspec(dllimport)
|
||||
// #endif
|
||||
//
|
||||
// #endif
|
||||
//
|
||||
//
|
||||
// #ifdef IRIS_API_EXPORTS
|
||||
// #define IRIS_API_CLASS __declspec(dllexport)
|
||||
// #else
|
||||
// #define IRIS_API_CLASS __declspec(dllimport)
|
||||
// #endif
|
||||
#define MAXDISTANCE 1265000
|
||||
class /*IRIS_API_CLASS*/ CVSMD12XControl
|
||||
{
|
||||
public:
|
||||
CVSMD12XControl();
|
||||
~CVSMD12XControl();
|
||||
private:
|
||||
int *m_piPositionInPulses;
|
||||
|
||||
CAbstractPort *m_pAbsPort;
|
||||
unValue m_unValue;
|
||||
MSInfo m_stuMSInfo;
|
||||
ControllerParams m_stuControllerParams;
|
||||
int m_iProtocolType;
|
||||
int m_iCID;
|
||||
std::string m_strCID;
|
||||
public:
|
||||
bool m_bIsSyncMove;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//for IRIS Linear Motor - Electric Shutter
|
||||
//Initialize communication setup iPortType(0:RS232 1:RS485) iCID(For RS485 device) bSyncMove(move mode)
|
||||
bool ILMES_InitializeComm(QString portName,int bandrate=9600, int iPortType = 1, int iCID = 1, bool bSyncMove = true);
|
||||
//Initialize communication setup iPortType(0:RS232 1:RS485) iCID(For RS485 device) bSyncMove(move mode)
|
||||
bool ILMES_InitializeComm(PortInfo portinfo,int iPortType = 1,int iCID = 1, bool bSyncMove = true);
|
||||
|
||||
//Initialize Controller params
|
||||
bool ILMES_InitializeParams(ControllerParams cpParams);
|
||||
|
||||
//Set the light hole position(pulses)
|
||||
void ILMES_SetPosition(int *piPositionInPulse,size_t szSize);
|
||||
|
||||
bool ILMES_MoveToPos(int iPositionIndex);
|
||||
|
||||
public:
|
||||
int waitetime;
|
||||
////init port
|
||||
void SetProtocolType(int iProtocolType = 0);//0:RS232 1:RS485 call before send any command
|
||||
void SetCID(int iID);//set device id when using RS485 protocol call before send any command
|
||||
void SetSyncMode(bool bSyncMove = false);
|
||||
bool InitAndOpenPort(PortInfo portinfo);//Init comport by PortInfo Struct
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////for debug or unsupported function
|
||||
std::string ReadReceive();
|
||||
int SendCommand(const std::string strSend); // return indicates how many char has been sent
|
||||
//////////////////////////////////////////////////////////////////////////motor control
|
||||
////init&misc
|
||||
bool InitController(); //Init Motor controller hand shake
|
||||
|
||||
bool Enable(); //enbale
|
||||
bool Disable(); //disable
|
||||
|
||||
bool GetStatus(MSInfo &stuMotorParam); //load motor status see MSInfo Struct
|
||||
////motion control
|
||||
bool Move(int iRelPulse); // relative move mode,pulse (-2147483647<34><37>2147483647)
|
||||
bool MoveTo(int iAbsPulse);//absolute mode,pulse (-2147483647<34><37>2147483647)
|
||||
bool Move_NoSyn(int iRelPulse); // relative move mode,pulse (-2147483647<34><37>2147483647)
|
||||
bool MoveTo_NoSyn(int iAbsPulse);//absolute mode,pulse (-2147483647<34><37>2147483647)
|
||||
bool SetLogicZero(); //set logic zero
|
||||
|
||||
bool StartBackZero();//back zero
|
||||
bool StopBackZero();// stop back zero & reset register
|
||||
////Set&Get
|
||||
bool SetBaudRate(int iBaudRate);//set controller baud rates,default B9600 (2400 <20><> 921600)
|
||||
int GetBaudRate(); // -1:should retry;
|
||||
|
||||
bool SetMicroSteps(int iMicroSteps);//set micro steps (0<><30>5)->(1/2/4/8/16/32)
|
||||
int GetMicroSteps();
|
||||
|
||||
bool SetAccSpeed(float fAccSpd);//set acceleration speed in pulse (0 <20><> 192000000)
|
||||
float GetAccSpeed();
|
||||
|
||||
bool SetRunSpeed(float fRunSpeed);//set normal running speed in pulse (0 <20><> 192000000)
|
||||
float GetRunSpeed();
|
||||
|
||||
bool SetDecSpeed(float fDecSpeed);//set deceleration speed in pulse (0 <20><> 192000000)
|
||||
float GetDecSpeed();
|
||||
|
||||
bool SetSpeed(float fRunSpeed, float fAccSpd, float fDecSpeed);//see above three functions
|
||||
|
||||
bool SetHoldCurrent(float fHoldCurrent);//set hold current ( 0 <20><> 8.0 )Amp? pay attention to your motor specification.
|
||||
float GetHoldCurrent();
|
||||
|
||||
bool SetAccCurrent(float fAccCurrent);//set acceleration current ( 0 <20><> 8.0 )Amp? pay attention to your motor specification.
|
||||
float GetAccCurrent();
|
||||
|
||||
bool SetRunCurrent(float fRunCurrent);//set normal running current ( 0 <20><> 8.0 )Amp? pay attention to your motor specification.
|
||||
float GetRunCurrent();
|
||||
|
||||
bool SetCurrent(float fAccCurrent, float fRunCurrent, float fHoldCurrent);//see above three functions
|
||||
|
||||
bool SetS1FETE(ZZ_U8 bS1FETE);//S1 register falling edge trigger event,see enum
|
||||
ZZ_U8 GetS1FETE();
|
||||
|
||||
bool SetS1RETE(ZZ_U8 bS1RETE);//S1 register rising edge trigger event
|
||||
ZZ_U8 GetS1RETE();
|
||||
|
||||
bool SetS2FETE(ZZ_U8 bS2FETE);//S2 register falling edge trigger event
|
||||
ZZ_U8 GetS2FETE();
|
||||
|
||||
bool SetS2RETE(ZZ_U8 bS2RETE);//S2 register rising edge trigger event
|
||||
ZZ_U8 GetS2RETE();
|
||||
|
||||
//(ZeroMode 0:off 1:once 2:once + safe position 3:twice 4:twice + safe position) (OpenVoltageLevel 0:Low Level 1:High Level)
|
||||
//(ZeroSensor 0:S1 1:S2 2:S3 3:S4 4:S5 5:S6)( ZeroVelocity <20><>-192000) <20><><EFBFBD><EFBFBD>192000<30><30>pulse)(SafePosition <20><>-2147483647) <20><><EFBFBD><EFBFBD>2147483647<34><37>)
|
||||
bool SetZeroParams(ZZ_U8 bZeroMode, ZZ_U8 bSwitchOpenVL, ZZ_U8 bZeroSensor, float fZeroVelocity, int iSafePosition);
|
||||
ZZ_U8 GetZeroMode();
|
||||
ZZ_U8 GetSwitchOpenVoltageLevel();
|
||||
ZZ_U8 GetZeroSensor();
|
||||
int GetSafePosition();
|
||||
float GetZeroVelocity();
|
||||
|
||||
private:
|
||||
bool ParseReturnedString(std::string &strRecv,int iType);
|
||||
bool ParseReturnedParam(std::string &strRecv);
|
||||
void VSMD_BitShift(ZZ_U8* src, unValue* dst);
|
||||
char* VSMD_Split(char* cStr, char cSplit);
|
||||
};
|
||||
|
108
othersoft/shuttercali/source/LinearShutter/VSMD12XMiscDefines.h
Normal file
108
othersoft/shuttercali/source/LinearShutter/VSMD12XMiscDefines.h
Normal file
@ -0,0 +1,108 @@
|
||||
#pragma once
|
||||
#include "ZZ_Types.h"
|
||||
#define MAXBUFFER 10240
|
||||
#include<qstring.h>
|
||||
using namespace ZZ_MISCDEF;
|
||||
|
||||
typedef struct tagTransportLayerInfomation
|
||||
{
|
||||
//Serial
|
||||
int iPortType;
|
||||
int iPortNumber;
|
||||
int indexBaudRate;
|
||||
int iBaudRate;
|
||||
int indexParity, indexBytesize, indexStopBits; //Mode
|
||||
bool Hw;
|
||||
bool Sw;
|
||||
bool Dtr, Rts;
|
||||
QString FullPortName;
|
||||
tagTransportLayerInfomation() {
|
||||
iPortType = 0;
|
||||
indexParity = 0;
|
||||
iPortNumber = 8;
|
||||
iBaudRate = 9600;
|
||||
indexBytesize = 3;
|
||||
indexStopBits = 0;
|
||||
FullPortName = "";
|
||||
}
|
||||
|
||||
//Bit
|
||||
//Stop
|
||||
//MODEM CONTROL setting
|
||||
//MODEM LINE STATUS
|
||||
|
||||
//TCP UDP
|
||||
|
||||
}PortInfo;
|
||||
|
||||
typedef struct tagMotorStatusInfo
|
||||
{
|
||||
float fVelocity;
|
||||
int iPosition;
|
||||
ZZ_U32 uiFlags;
|
||||
}MSInfo;
|
||||
|
||||
typedef struct tagControllerParams
|
||||
{
|
||||
int bdr; //baud
|
||||
int mcs; //microsteps 0:full 1:half 2:4 3:8 4:16 5:32 6:64 7:128 8:256
|
||||
float spd; //velocity
|
||||
float acc; //acceleration
|
||||
float dec; //deceleration
|
||||
float cra; //acc state current
|
||||
float crn; //normal state current
|
||||
float crh; //hold state current
|
||||
ZZ_U8 s1f;
|
||||
ZZ_U8 s1r;
|
||||
ZZ_U8 s2f;
|
||||
ZZ_U8 s2r;
|
||||
ZZ_U8 zmd; //zero mode
|
||||
ZZ_U8 osv; //open state sensor value
|
||||
ZZ_U8 snr; //zero sensor
|
||||
ZZ_U8 zsp; //zero safe position
|
||||
float zsd; //zero velocity
|
||||
tagControllerParams() {
|
||||
bdr = 9600;
|
||||
|
||||
cra = 0.8;
|
||||
crh = 0.4;
|
||||
crn = 0.6;
|
||||
|
||||
acc = 100000;
|
||||
dec = 100000;
|
||||
spd = 64000;
|
||||
|
||||
osv = 0;
|
||||
snr = 0;
|
||||
zmd = 3;
|
||||
zsp = 20;
|
||||
zsd = 50000;
|
||||
|
||||
mcs = 6;
|
||||
}
|
||||
}ControllerParams;
|
||||
|
||||
typedef union
|
||||
{
|
||||
ZZ_U8 byteValue[4];
|
||||
short i16Value[2];
|
||||
ZZ_U16 u16Value[2];
|
||||
int i32Value;
|
||||
float fValue;
|
||||
ZZ_U32 u32Value;
|
||||
}unValue;
|
||||
|
||||
enum emVSMDTriggerEvent
|
||||
{
|
||||
NoAction =0, //<2F><EFBFBD><DEB6><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>״̬λ S1 <20>仯֪ͨ<CDA8><D6AA>
|
||||
ResetZeroPosition, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>λ<EFBFBD><CEBB>
|
||||
DecSpdStop, //<2F><><EFBFBD><EFBFBD>ֹͣ
|
||||
DecSpdStopRZP, //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>λ<EFBFBD><CEBB>
|
||||
Stop, //<2F><><EFBFBD><EFBFBD>ֹͣ
|
||||
StopRZP, //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>λ<EFBFBD><CEBB>
|
||||
RunningPosDirect, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ٶȣ<D9B6>
|
||||
RunningNegDirect, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ٶȣ<D9B6>
|
||||
OfflineModeOn, //<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
OfflineModeOff //<2F><><EFBFBD><EFBFBD>ģʽֹͣ
|
||||
};
|
||||
|
147
othersoft/shuttercali/source/LinearShutter/ZZ_SeiralPort.cpp
Normal file
147
othersoft/shuttercali/source/LinearShutter/ZZ_SeiralPort.cpp
Normal file
@ -0,0 +1,147 @@
|
||||
#include "pch.h"
|
||||
#include "ZZ_SeiralPort.h"
|
||||
|
||||
CZZ_SeiralPort_QT::CZZ_SeiralPort_QT()
|
||||
{
|
||||
m_pSerialPort = new QSerialPort();
|
||||
}
|
||||
|
||||
CZZ_SeiralPort_QT::~CZZ_SeiralPort_QT()
|
||||
{
|
||||
if (m_pSerialPort != NULL)
|
||||
{
|
||||
delete m_pSerialPort;
|
||||
}
|
||||
}
|
||||
|
||||
void CZZ_SeiralPort_QT::InitPort(PortInfo portinfo)
|
||||
{
|
||||
|
||||
m_piSettings = portinfo;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool CZZ_SeiralPort_QT::SetPort()
|
||||
{
|
||||
bool bRes = true;
|
||||
// int iRes = sio_ioctl(m_piSettings.iPortNumber, m_piSettings.indexBaudRate,
|
||||
// m_piSettings.indexParity | m_piSettings.indexBytesize | m_piSettings.indexStopBits);
|
||||
// if (iRes != SIO_OK)
|
||||
// {
|
||||
// bRes = false;
|
||||
// }
|
||||
QString qstrPortName;
|
||||
if (m_piSettings.FullPortName!="")
|
||||
{
|
||||
qstrPortName = m_piSettings.FullPortName;
|
||||
qDebug() << m_piSettings.FullPortName;
|
||||
}
|
||||
else {
|
||||
qstrPortName = QString("COM%1").arg(m_piSettings.iPortNumber);
|
||||
}
|
||||
// qstrPortName = "COM4";
|
||||
// QString qstrPortName = m_piSettings.FullPortName;//QString("COM%1").arg(m_piSettings.iPortNumber);
|
||||
m_pSerialPort->setPortName(qstrPortName);
|
||||
m_pSerialPort->setReadBufferSize(512);
|
||||
bRes = m_pSerialPort->setBaudRate(m_piSettings.iBaudRate);
|
||||
return bRes;
|
||||
}
|
||||
|
||||
bool CZZ_SeiralPort_QT::Open()
|
||||
{
|
||||
bool bRes = true;
|
||||
// int iRes = sio_open(m_piSettings.iPortNumber);
|
||||
// if (iRes!=SIO_OK)
|
||||
// {
|
||||
// bRes = false;
|
||||
// }
|
||||
bRes = m_pSerialPort->open(QIODevice::ReadWrite);
|
||||
if (!bRes)
|
||||
{
|
||||
qDebug() << "Err:open Failed.Exit Code:1";
|
||||
//std::cout << "Err.open Failed" << std::endl;
|
||||
return bRes;;
|
||||
}
|
||||
return bRes;
|
||||
}
|
||||
|
||||
void CZZ_SeiralPort_QT::Close()
|
||||
{
|
||||
m_pSerialPort->close();
|
||||
}
|
||||
|
||||
std::string CZZ_SeiralPort_QT::ReadAll(int waite)
|
||||
{
|
||||
if (!m_pSerialPort->waitForReadyRead(waite))
|
||||
{
|
||||
return "";
|
||||
|
||||
}
|
||||
if (
|
||||
m_pSerialPort->bytesAvailable() == 0
|
||||
)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
qbaRecv.clear();
|
||||
|
||||
qbaRecv = m_pSerialPort->readAll();
|
||||
|
||||
|
||||
std::string strRet(qbaRecv.constData(), qbaRecv.length());
|
||||
return strRet;
|
||||
|
||||
// std::string strRet;
|
||||
// char cBuf[MAXBUFFER];
|
||||
// int iRet = sio_read(m_piSettings.iPortNumber,cBuf, MAXBUFFER);
|
||||
// if (iRet==0)
|
||||
// {
|
||||
// strRet = "";
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// char *pRecv = new char[iRet];
|
||||
// memcpy(pRecv, cBuf, iRet);
|
||||
// //std::string strRet(pRecv);
|
||||
// //delete pRecv;
|
||||
// //return strRet;
|
||||
//
|
||||
// strRet.resize(iRet);
|
||||
// for (int i=0;i<iRet;i++)
|
||||
// {
|
||||
// strRet[i] = pRecv[i];
|
||||
// }
|
||||
// delete pRecv;
|
||||
// }
|
||||
// return strRet;
|
||||
}
|
||||
|
||||
int CZZ_SeiralPort_QT::Write(const std::string strSend)
|
||||
{
|
||||
QByteArray qbaTest(strSend.c_str(),(int)strSend.length());
|
||||
qint64 qi64Write = m_pSerialPort->write(qbaTest);
|
||||
m_pSerialPort->waitForBytesWritten(5000);
|
||||
if (qi64Write != qbaTest.size())
|
||||
{
|
||||
qDebug() << "Err:write Failed.Exit Code:1" << qi64Write;
|
||||
return qi64Write;
|
||||
}
|
||||
|
||||
return 0;
|
||||
// char* pcSend = (char*)strSend.c_str();
|
||||
// int iRet = sio_write(m_piSettings.iPortNumber, pcSend, (int)strSend.length());
|
||||
//
|
||||
// //delete pcSend;
|
||||
// if (iRet!= (int)strSend.length())
|
||||
// {
|
||||
// return iRet;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
// //sio_write();
|
||||
}
|
26
othersoft/shuttercali/source/LinearShutter/ZZ_SeiralPort.h
Normal file
26
othersoft/shuttercali/source/LinearShutter/ZZ_SeiralPort.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "VSMD12XMiscDefines.h"
|
||||
#include "AbstractPort.h"
|
||||
#include"qobject.h"
|
||||
class CZZ_SeiralPort_QT :public CAbstractPort,QObject
|
||||
{
|
||||
|
||||
private:
|
||||
PortInfo m_piSettings;
|
||||
QByteArray qbaSend, qbaRecv;
|
||||
QSerialPort *m_pSerialPort;
|
||||
public:
|
||||
CZZ_SeiralPort_QT();
|
||||
virtual ~CZZ_SeiralPort_QT();
|
||||
public:
|
||||
virtual void InitPort(PortInfo portinfo);
|
||||
virtual bool SetPort();
|
||||
virtual bool Open();
|
||||
virtual void Close();
|
||||
|
||||
virtual std::string ReadAll(int waittime = 5000);
|
||||
|
||||
virtual int Write(const std::string strSend);
|
||||
|
||||
};
|
||||
|
28
othersoft/shuttercali/source/LinearShutter/pch.h
Normal file
28
othersoft/shuttercali/source/LinearShutter/pch.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
////////////////////////////setings
|
||||
#include <QSettings>
|
||||
#include <QMetaEnum>
|
||||
////////////////////////////Basic
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QObject>
|
||||
////////////////////////////Thread
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
////////////////////////////json
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonParseError>
|
||||
////////////////////////////time
|
||||
#include <QtCore/QTime>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
////////////////////////////Serial I/O
|
||||
#include <QtSerialPort/QSerialPort>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
Reference in New Issue
Block a user