#pragma once // 下列 ifdef 块是创建使从 DLL 导出更简单的 // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 DIOSCTRLBOX_EXPORTS // 符号编译的。在使用此 DLL 的 // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将 // DIOSCTRLBOX_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的 // 符号视为是被导出的。 #ifndef DIOSCTRLBOX_EXPORTS #ifdef _WIN64 #ifdef _DEBUG #pragma comment(lib, "DiosCtrlBox64D.lib") #else #pragma comment(lib, "DiosCtrlBoxX64.lib") #endif #else #ifdef _DEBUG #pragma comment(lib, "DiosCtrlBoxD.lib") #else #pragma comment(lib, "DiosCtrlBox.lib") #endif #endif #endif #ifdef DIOSCTRLBOX_EXPORTS #define DIOSCTRLBOX_API __declspec(dllexport) #define DIOSCTRLBOX_C_API extern "C" __declspec(dllexport) #else #define DIOSCTRLBOX_API __declspec(dllimport) #define DIOSCTRLBOX_C_API extern "C" __declspec(dllimport) #endif #include "DPC.h" #include "Generator_Model_Def.h" #include "LogicDriver.h" #include "SerialSCF.h" #include "DiosLogicDeviceStructure.h" #include "Mech_Tomo.h" #include "Hsw_Tomo.h" #pragma pack(push, 1) #define DIOSCTRLCPU_COM_TIMEOUT (20000) #define PACKET_TITLE1 (0xEE) #define PACKET_TITLE2 (0x5A) typedef union _FunctionID { struct { unsigned char DEVID : 4;// unsigned char BLOCKID : 4;// }; unsigned char CharPart; } FUNCTIONID; typedef union _ShortData { struct { unsigned char Low;// unsigned char High;// }; unsigned short ShortPart; } SHORTDATA; typedef struct _CtrlPacketHead { unsigned char szTitle[2]; unsigned char FrameSize; unsigned char FrameId; unsigned char FrameCmd; unsigned char FuncId; unsigned char Data1; unsigned char Data2; unsigned char Data3; unsigned char Data4; }CTRLPACKETHEAD; typedef struct _TOMONODEINFO { //unsigned short Pos;先不要位置坐标 unsigned short Angle; }TOMONODEINFO; #pragma pack(pop) #define ROTATE_DIR_UP (0x00) #define ROTATE_DIR_DOWN (0x01) //IO ports //HSW #define FUNCPORTHSW1 (0x11) #define FUNCPORTHSW2 (0x12) //伺服电机状态 1:Ready //#define FUNCPORTSIFUSTATUS (0x14) #define FUNCPORTEXPNOTIFY (0x31) //Mech Move #define FUNCPORTMECHMOVE (0x15) #define FUNCPORTMECHMOVEPWM (0x16) #define FUNCPORTMECHMOVEDIR (0x17) #define FUNCPORTMECHMOVEPOS (0x21) //Detector ResetPos #define FUNCPORTRESETPOS (0x22) //rotate #define FUNCPORT_ROTATE_DIR (0x36) //rotate input #define FUNCPORT_ROTATE_INPUT (0x37) #define FUNCPORT_485 (0x43) //encode #define ENCODEPORT_A (0x32) #define ENCODEPORT_B (0x33) #define ENCODEPORT_Z (0x34) //MCU Ver #define MCU_VER (0x48) //rotate limit //#define FUNCPORT_ROTATE_HIGHLIMIT (0x13) #define FUNCPORT_ROTATE_LOWLIMIT (0x13) #define FUNCPORT_ROTATE_PARKINGPOS (0x14) #define NOTIFY_POS_MAX_LIMIT (20000) class DIOSCTRLBOX_API DiosCtrlBoxDPC : public LogicDriver { bool m_EncoderReadyStatus; std::string *m_pWorkpath; std::string *m_pSTMCMD; HAND_SWITCH m_CurrentHsw; EXAM_MODE m_CurrentExamMode; Mech_Tomo *m_pMech; Hsw_Tomo *m_pHsw; bool m_HitPrepPos; bool m_AngleCorrected; bool m_RsetPosChanged; //servo WORD m_ServoMode; WORD m_ServoGuanLiangB; WORD m_ServoRoundPulse; FLOAT m_TomoPositionConv; //电机参数 USHORT m_MotorPeriod; USHORT m_MotorEffectivePeriod; USHORT m_ServoEffectivePeriod; //为TOMO算法准备----begin FLOAT m_TomoAngleReqConvRate; FLOAT m_TomoAngleResConvRate; //detector FLOAT m_DetectorPrepTimePeriod; FLOAT m_MotorPerAngle; FLOAT m_TomoMoveConvRateA; FLOAT m_TomoMoveConvRateB; FLOAT m_TomoResetConvRateA; FLOAT m_TomoResetConvRateB; FLOAT m_TomoMoveSpeed; FLOAT m_TomoSpeedConv; FLOAT m_TomoMinDistance; //gen FLOAT m_TomoMinAngleLimit; FLOAT m_TomoMinMoveLimit; FLOAT m_TomoMoveOffset;// LogicPos = PhyOffset*Ratio + MoveOffset FLOAT m_SID; FLOAT m_AccDst;//1 FLOAT m_LatDst;//2 FLOAT m_SusDst;//3 FLOAT m_BrkDst;//4 FLOAT m_TomoWarmAngle; FLOAT m_TomoAngle; INT m_TomoStepCorr; INT m_TomoPeriodCorr; DWORD m_TomoAlgorythm; FLOAT m_EncoderConvA; FLOAT m_EncoderConvB; FLOAT m_EncoderPrecision; DWORD m_TomoWorkArea; INT m_LogicTomoPosParamCount; INT m_LogicTomoPosParamSize; FLOAT *m_pLogicTomoPosParams; INT *m_pLogicTomoRPeriodParams; INT *m_pLogicTomoRStepParams; INT m_LogicTomoFixStepCount; INT *m_pLogicTomoFixStepParams; DWORD m_NotifyCount; FLOAT m_pNotifiedTomoAngle[NOTIFY_POS_MAX_LIMIT]; FLOAT m_pNotifiedTomoPos[NOTIFY_POS_MAX_LIMIT]; //为TOMO算法准备----end FLOAT m_ResetParams[MECH_1D_POS_MAX]; FLOAT m_MoveParams[MECH_1D_POS_MAX]; FLOAT m_RotateParams[MECH_1D_POS_MAX]; SCFPacket *m_pSendPacket; SCFPacket *m_pReceivePacket; SCF *m_pSCFInstance; HMODULE m_DllFileHandle; unsigned char m_FrameId; //io status bool m_Level1HSW; bool m_Level2HSW; bool PrepCalculation(); bool Action(DWORD Timeout = DIOSCTRLCPU_COM_TIMEOUT); bool ReceiveAck(DWORD Timeout = DIOSCTRLCPU_COM_TIMEOUT); USHORT Distance_GetPhyAbsoluteOffsetOnly(FLOAT TargetLogicPos); USHORT Distance_GetPhyAbsoluteOffsetEx(FLOAT TargetLogicPos); USHORT Distance_GetPhyAbsoluteOffset(FLOAT TargetLogicPos); DWORD Angle_GetPhyRelativeOffset(FLOAT TargetLogicAngle, bool Req); INT Distance_GetphysicGrainTime(); USHORT Distance_Logic2Phy(FLOAT LogicDistance); FLOAT Distance_Phy2Logic(USHORT PhyDistance); FLOAT Detector_Phy2Logic(USHORT PhyDistance); DWORD Angle_Logic2Phy(FLOAT LogicAngle, bool Req); FLOAT Angle_Phy2Logic(USHORT PhyAngle, bool Req); bool IsSameAngle(FLOAT a, FLOAT b); bool IsSameHeight(FLOAT a, FLOAT b); bool IsSameHeightTomo(FLOAT a, FLOAT b); void PrintPacket(bool SendFlag); void PrintPacketEx(const char *pszTitle, const char *pPacket, int Len); bool BindRotationAndLimitSwitch(); bool WriteServo(UCHAR Target, UCHAR Cmd, USHORT Addr, USHORT Context); bool ConfigServo(); bool InitEncoder(); bool UnInitEncoder(); bool AtomRotate2LowLimit(DWORD Timeout = DIOSCTRLCPU_COM_TIMEOUT); bool AtomBlindRotateBackward(FLOAT BackwardAngle, DWORD Timeout = DIOSCTRLCPU_COM_TIMEOUT); char GetRotateDir(bool Up); public: DiosCtrlBoxDPC(void); virtual ~DiosCtrlBoxDPC(void); virtual bool DriverEntry(ResDataObject &Configuration); virtual bool SYSTEM_CALL Driver_Probe(ResDataObject& PARAM_OUT HardwareInfo); virtual bool SetDriverWorkPath(const char *pWorkPath); virtual PVOID SYSTEM_CALL LoadDriver();//无根节点 virtual void SYSTEM_CALL UnloadDriver(); bool LoadConfiguration(ResDataObject &connection); bool InitIOBOX(); RET_STATUS DATA_ACTION GetTomoResults(ResDataObject &result); //actions virtual bool Connect(); virtual void DisConnect(); virtual bool SYSTEM_CALL SetDeviceWorkPath(const char * PARAM_IN pWorkPath); //逻辑设备树的加载和卸载 virtual PVOID SYSTEM_CALL LoadLogicDevices(); virtual void SYSTEM_CALL UnloadLogicDevices(); virtual bool Device_Probe(ResDataObject &HardwareInfo); virtual DWORD SYSTEM_CALL OnNotify(HANDLE evtList[], DWORD count); static PACKET_RET DiosCtrlBoxDPC::EventCallback(const char * pRecData, DWORD nLength, DWORD & PacketLength); //io board ctrl------------- bool Action485(const char *pszPacket, DWORD PacketLen, DWORD Timeout); bool Ioctl_PWM_Simple(FUNCTIONID Id, unsigned int Distance); bool Ioctl3(FUNCTIONID Id, unsigned char Data1, unsigned char Data2, unsigned char Data3); bool Ioctl2(FUNCTIONID Id, unsigned char Data1, unsigned char Data2); bool Ioctl1(FUNCTIONID Id, unsigned char Data1); bool Ioctl_PWM(FUNCTIONID Id, unsigned char Param1, unsigned short FulPeriod, unsigned short HighPeriod, unsigned int PWM); bool Ioctl_PWM(FUNCTIONID Id, unsigned char Param1, unsigned short Pos, unsigned short FulPeriod, unsigned short HighPeriod, unsigned int PWM); bool Ioctl_dAdT(FUNCTIONID Id, unsigned char Param1,unsigned short AdVal);//CMD:0x01 bool Ioctl(FUNCTIONID Id, unsigned char *pDataBuff, unsigned int DataLen);//CMD:0x01 bool Write(FUNCTIONID Id, const char *pszContext, unsigned int PacketLen); bool WriteCOM(const char *pszContext, unsigned int PacketLen); bool Read_COMResponse(const char *pszContext, unsigned int PacketLen); int ReadEx(FUNCTIONID Id, char *pszReq, unsigned int ReqLen, char *pszRes, unsigned int ResLen); int Read(FUNCTIONID Id, unsigned char *pszContext, unsigned int PacketLen); //dispatch ctrl------------- void DispatchPacket(const char *pPacket); void DispatchNotifyPacket(const char *pPacket); void Dispatch_HSW(HAND_SWITCH hsw); void Dispatch_PeriodHit(); void Dispatch_PWMOffset(unsigned short PwmOffset, unsigned short TimeOffset); void Dispatch_HitPos(unsigned short PosOffset, unsigned short TimeOffset); void Dispatch_HitAngle(unsigned short AngleOffset); void Dispatch_StopMove(); void Dispatch_StopRotate(); void Dispatch_StopRotate_InTimeout(); void Dispatch_EncoderReady(); void Dispatch_TomoExpTrigger(bool Exp); void Dispatch_TomoExpPosTrigger(USHORT Pos); //base cmd------------------- bool GetSiFuStatus(); bool GetEncoderAngle(FLOAT &Angle); bool GetCurMechPos(); bool GetCurMechAngle(); bool GetResetHeight(); bool StopMove(); bool StopRotate(); bool StartMove(bool Up); bool StartMoveInSpeedMode(bool Up); bool StartMoveInPositionMode(bool Up); int MoveMechTo(FLOAT TargetPos);//马上返回.0:Moving,1:AtPos,-1:Error int RotateMechTo(FLOAT TargetAngle);//马上返回.0:Moving,1:AtPos,-1:Error bool ResetAngleAtom(); bool ResetAngleAtom_Function(); int MoveMechToTomoStartPos();// 0:Moving,1:AtPos,-1:mechError int MoveMechToTomoEndPos();// 0:Moving,1:AtPos,-1:mechError //tomo params bool SetTomoParams(); bool ClearTomoParams(); bool SetTomoParams_Pos(); bool SetTomoParams_Open(); //open cmd ------------------------------------------------------ bool SwitchExam(EXAM_MODE mode); //原子操作:MoveMech,RotateMech,ActionMech,RESET bool MoveMechAtom(FLOAT Pos,DWORD Timeout); bool BlindRotateMech(FLOAT Angle, DWORD Timeout); bool AtomBlindRotate(FLOAT Angle, DWORD Timeout); bool RotateMechAtom(FLOAT Angle, DWORD Timeout); bool ActionMechAtom(FLOAT Pos, FLOAT Angle,DWORD Timeout); bool StopMech(); bool RESET(DWORD Timeout); //状态机相关 bool FramePrep();//check resetpos,make calculation possible. bool FrameReady();//after ready.wait HSW ACTION. bool FrameStart();//start move bool FrameEnd();//Stop Mech bool FramePost();//ResetMechWithHSW first.and return. //状态机异常 bool FrameError(); bool FrameRecover(); bool SeqError(); bool SeqEnd(); }; DIOSCTRLBOX_C_API DriverDPC* GetDriverDPC(); DIOSCTRLBOX_C_API void ReleaseDriverDPC(DriverDPC *p);