#ifndef _CTRL_H_ #define _CTRL_H_ #include "task.h" //#include "dac.h" #include "fuzzy.h" #define HALL #undef HALL #define MAX_SAMPLE 30 /////////////////////////////////////////////////////////////////// typedef struct { //DA转换器线性校准 double Ka ; //斜率 double C; //节距 double Reserve[6]; char Reserve2[14]; unsigned short ValidCRC; }_DAC_Param; ///////////////////////////////////////////////////////////////////// typedef struct db { struct { USHORT cRightToMiddle1; //放样位到预分解1 USHORT cRightToMiddle2; //放样位到预分解2 USHORT cRightToLeft; //放样位到高温位 //样车运行时间 USHORT cTimeDecompose1; //分解时间1 USHORT cTimeDecompose2; //分解时间2 USHORT cTimeDelay; //结束延时 ///////////////////////////////////////////2015-8-13 USHORT sMaxTestTime; //最大实验时间 UCHAR bAutoCly; //自动测硫仪 UCHAR cCoolTime; UCHAR MaxSampleCnt; //最大样品数目 UCHAR m_ResetPos; //复位样位 short m_WarmSpeed; //最大升温速度 UCHAR bReserve[4]; //保留 ULONG sReserve[9]; //保留 //2015-8-13 ////////////////////////////////////////////// long lDestTempADValue; //目标温度AD值 // long lDStartDJADValue; long lDEndDJADValue; USHORT cTimeoutSamplePosN; //样盘移动一位的超时时间 USHORT cTimeoutSamplePos1; //样盘移动到第一位的超时时间 }DownloadWorkParam; _DAC_Param DAC_Param; /////////////////////////////////////////////////////////////////// union //输出寄存器 { struct { UINT DC_SAMPLE_DIR :1; //样车方向 DC UINT DC_SAMPLE_RUN :1; //样车运行 UINT DJ_DJ :1; //电解控制接通 UINT DC_SPEAKER :1; //进水 UINT DC_SAMPLE_POS_DIR :1; //样位旋转方向 UINT DC_SAMPLE_POS_RUN :1; //样位旋转运行 UINT DC_PUMB :1; //气泵 UINT DC_JB :1; //搅拌 UINT cReserve :24; }iCoil8s; UCHAR iCoil8; UINT iCoil16; }OutputCoil; //32BIT union //此部分已经作废 { struct { UINT DC_POS_PUT_SAMPLE :1; UINT DC_POS_HIGH_TEMP :1; UINT DC_POS_PUT_SAMPLE_AUTO :1; UINT DC_POS_HIGH_TEMP_AUTO :1; UINT DC_SAMPLE_NON :1; UINT DC_SAMPLE_NO1 :1; UINT DC_InputRes1 :10; }cInputReg8s; UCHAR cInputReg8; USHORT cInputReg16; UINT cInputReg32; }InputStatus; //32BIT ///////////////////////////////////////////////////////////////// struct { long lPreChlPol; long lChlPol; //32BIT long lPreTemp; long lTemp; //32BIT long lPreChlVDJ; long lVDJ; long reserve[2]; }AdValue; /////////////////////////////////////////////////////// struct { UCHAR DJSwitch; //电解开关 USHORT DJVALUE; //电解DA值 ULONG lDJSum; //DJ开环值求和 UCHAR lDJReserve; //保留 long cPreFreq; //过去的电流积分值 //32BIT long cCurrFreq; //当前的电流积分值 //32BIT }Freq; /////////////////////////////////////////////////////////////// struct { UCHAR cPos; //样杆位置 SCHAR cSampleMoving; //样品电机正在移动 UCHAR cSampleMotorDir; //样车运行方向 SCHAR cMotorDlyTimer; //延时启动定时器 int MotorSampleRunTime; //样车运行时间 int MotorSampleTimeOutCnt; //到位超时时间 }MotorCtrl; ////////////////////////////////////////////////////////////// AI_CONTROL Ai_CTRL; ////////////////////////////////////////////////////////////// struct { UCHAR cDestPos; //样盘目标位置 SCHAR cSamplePos; //样盘当前位置 SCHAR cSamplePosMoving; //样盘电机正在移动 UCHAR cSamplePosMotorDir; //样盘运行方向 SCHAR cMotorDlyTimer; //延时启动定时器 UCHAR cReserve; USHORT iTimeout; //样盘运行时间 UINT EncodePos; //光 编码器位置 }PosCtrl; ///////////////////////////////////////////////////////////////// struct { UCHAR CmdType; UCHAR CmdParam1; UCHAR CmdParam2; UCHAR CmdParam3; UCHAR CmdReserve[16]; }Cmd; UCHAR cID; //IED站号 UCHAR cTestState; UCHAR cCoolTime; UCHAR cResetState; ULONG cStateTime; ULONG cTestTimer; //总共测试时间 char ErrorInfo[32]; //错误信息 char InstrumentName[18]; struct SecruitInfo { char uID[8]; char cCompany[64]; //公司名称 long lStartDate; long lEndDate; long lCurrentDate; long lreserve; char cReserveInfo[32]; char cCRC[8]; }Info; struct { USHORT SamplePos[MAX_SAMPLE]; //预留40个样品的位置 }POSEncode; }IED_DATABASE; extern IED_DATABASE IED; //////////////////////////////////////////////////////////////////////////////////////////////// enum MOTORPOS {POS_UNKNOWN = 0,POS_PUT_SAMPLE,POS_MIDDLE_1,POS_MIDDLE_2,POS_HIGH_TEMP }; //enum HALLPOS {POS_LEFT = 0,POS_RIGHT }; //样车位置 #ifdef HALL //v6 版本错误交换 //#define POS_LEFT 0 //#define POS_RIGHT 1 #define POS_LEFT 1 #define POS_RIGHT 0 #else #define POS_LEFT 3 #define POS_RIGHT 2 #endif #define POS_LEFT_MANUAL 1 #define POS_RIGHT_MANUAL 0 #define POS_LEFT_AUTO 3 #define POS_RIGHT_AUTO 2 #define SAMPLE_POS_N 4 #define SAMPLE_POS_1 5 #define PIN_MANUAL 0 //#define MAX_SAMPLE_COUNT 25L #define MAX_SAMPLE_COUNT (IED.DownloadWorkParam.MaxSampleCnt) enum MOTOR_SAMPLE_DIR{MOTOR_MOVE_LEFT=0,MOTOR_MOVE_RIGHT}; //送样电机运行方向 //////////////////////////////////////////////////////////////////////////////////////////////// //命令 enum CmdType{ CMD_NAK=0, //无命令 CMD_SETID, //设置ID CMD_SETPW, //设置密码 CMD_LOGON, //登录 CMD_SETDATETIME, //设置时间 CMD_READDATETIME, //读取时间 CMD_RESET_INST, //复位设备 CMD_MOVEMOTORSAMPLE, //移动样车 param1 放样位0 中间位1 中间位2 高温位3 CMD_MOVEMOTORSAMPLENO,//移动样品转盘 PARAM 目标样位 CMD_START_MEASURE, //启动测试 CMD_STOP_MEASURE, //停止测试 CMD_ELE, //启动300mA电解 param1 1 0 CMD_WARMUP, //温度升温 param1 1 0 CMD_ADJ_CUR, CMD_MOVEMOTORSAMPLE_ENCODEPOS, //走1/20样位置 // 1/20*200 // 1/4样位置 *200 CMD_MOVEMOTORSAMPLE_ENCODEPOS_STOP, //停车 }; #define COMMAND_CMD 0x7F /////////////////////////////////////////////////////////////////// enum{RESET_INIT=1,RESET_POS,RESET_SAMPLE_POS,RESET_SAMPLE_POS_END,RESET_END,RESET_END1}; void InitPort(void); void InitIED(void); SCHAR MovMotor(UCHAR cPos); void TaskStopMotor(void); void TaskParsaCmd(void); void JB(char bEnable); void Pumb(char bEnable); void DelayCheckPos(void* param); void TaskStopSamplePos(void); void TaskStopSamplePos2(void); int MoveSamplePos(int cPos); void TaskReset(void); void TaskManualMovePos(void); void TaskBeep(void) ; void Beep(UCHAR cNumBeep,UINT beepTime); void StopDJ(void); void StopSamplePosMotor(void); void StopSampleMotor(void); void MoveSampleEncodePos(int EncodePos); void TaskStopSampleEncodePos(void); void IdleRoutine(void); #endif