// BaseParaSet.cpp : implementation file
//

#include "stdafx.h"
#include "DEMO.h"
#include "BaseParaSet.h"
#include "CtrlCard.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CCtrlCard g_CtrlCard;
/////////////////////////////////////////////////////////////////////////////
// CBaseParaSet dialog
int effectlogic_x ;
int effectlogic_y ;
int effectlogic_z ;
int effectlogic_a ;
int effectlogic_b ;
int effectlogic_c ;
int registermode=0;

CBaseParaSet::CBaseParaSet(CWnd* pParent /*=NULL*/)
	: CDialog(CBaseParaSet::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBaseParaSet)
	m_nEffectLogic_x = -1;
	m_nEffectLogic_y = -1;
	m_nEffectLogic_z = -1;
	m_nNLimitMode_x = -1;
	m_nNLimitMode_y = -1;
	m_nNLimitMode_z = -1;
	m_nPLimitMode_x = -1;
	m_nPLimitMode_y = -1;
	m_nPLimitMode_z = -1;
	m_nPulseMode_x = -1;
	m_nPulseMode_y = -1;
	m_nPulseMode_z = -1;
	m_nStop0Mode_x = -1;
	m_nStop0Mode_y = -1;
	m_nStop0Mode_z = -1;
	m_nStop1Mode_x = -1;
	m_nStop1Mode_y = -1;
	m_nStop1Mode_z = -1;
	m_nHardLogic = -1;
	m_nHardStop = -1;
	m_nStop1Mode_a = -1;
	m_nStop0Mode_a = -1;
	m_nPLimitMode_a = -1;
	m_nNLimitMode_a = -1;
	m_nEffectLogic_a = -1;
	m_nPulseMode_a = -1;
	m_nRegMode = 0;
	m_nEffectLogic_b = -1;
	m_nEffectLogic_c = -1;
	m_nNLimitMode_b = -1;
	m_nNLimitMode_c = -1;
	m_nPLimitMode_b = -1;
	m_nPLimitMode_c = -1;
	m_nPulseMode_b = -1;
	m_nPulseMode_c = -1;
	m_nStop0Mode_b = -1;
	m_nStop0Mode_c = -1;
	m_nStop1Mode_b = -1;
	m_nStop1Mode_c = -1;
	//}}AFX_DATA_INIT
}


void CBaseParaSet::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBaseParaSet)
	DDX_Radio(pDX, IDC_EFFECTLOGIC_X, m_nEffectLogic_x);
	DDX_Radio(pDX, IDC_EFFECTLOGIC_Y, m_nEffectLogic_y);
	DDX_Radio(pDX, IDC_EFFECTLOGIC_Z, m_nEffectLogic_z);
	DDX_Radio(pDX, IDC_NLIMITMODE_X, m_nNLimitMode_x);
	DDX_Radio(pDX, IDC_NLIMITMODE_Y, m_nNLimitMode_y);
	DDX_Radio(pDX, IDC_NLIMITMODE_Z, m_nNLimitMode_z);
	DDX_Radio(pDX, IDC_PLIMITMODE_X, m_nPLimitMode_x);
	DDX_Radio(pDX, IDC_PLIMITMODE_Y, m_nPLimitMode_y);
	DDX_Radio(pDX, IDC_PLIMITMODE_Z, m_nPLimitMode_z);
	DDX_Radio(pDX, IDC_PULSEMODE_X, m_nPulseMode_x);
	DDX_Radio(pDX, IDC_PULSEMODE_Y, m_nPulseMode_y);
	DDX_Radio(pDX, IDC_PULSEMODE_Z, m_nPulseMode_z);
	DDX_Radio(pDX, IDC_STOP0MODE_X, m_nStop0Mode_x);
	DDX_Radio(pDX, IDC_STOP0MODE_Y, m_nStop0Mode_y);
	DDX_Radio(pDX, IDC_STOP0MODE_Z, m_nStop0Mode_z);
	DDX_Radio(pDX, IDC_STOP1MODE_X, m_nStop1Mode_x);
	DDX_Radio(pDX, IDC_STOP1MODE_Y, m_nStop1Mode_y);
	DDX_Radio(pDX, IDC_STOP1MODE_Z, m_nStop1Mode_z);
	DDX_Radio(pDX, IDC_HARDLOGIC, m_nHardLogic);
	DDX_Radio(pDX, IDC_HARDSTOP, m_nHardStop);
	DDX_Radio(pDX, IDC_STOP1MODE_A, m_nStop1Mode_a);
	DDX_Radio(pDX, IDC_STOP0MODE_A, m_nStop0Mode_a);
	DDX_Radio(pDX, IDC_PLIMITMODE_A, m_nPLimitMode_a);
	DDX_Radio(pDX, IDC_NLIMITMODE_A, m_nNLimitMode_a);
	DDX_Radio(pDX, IDC_EFFECTLOGIC_A, m_nEffectLogic_a);
	DDX_Radio(pDX, IDC_PULSEMODE_A, m_nPulseMode_a);
	DDX_Radio(pDX, IDC_REGISTER_MODE0, m_nRegMode);
	DDX_Radio(pDX, IDC_EFFECTLOGIC_B, m_nEffectLogic_b);
	DDX_Radio(pDX, IDC_EFFECTLOGIC_C, m_nEffectLogic_c);
	DDX_Radio(pDX, IDC_NLIMITMODE_B, m_nNLimitMode_b);
	DDX_Radio(pDX, IDC_NLIMITMODE_C, m_nNLimitMode_c);
	DDX_Radio(pDX, IDC_PLIMITMODE_B, m_nPLimitMode_b);
	DDX_Radio(pDX, IDC_PLIMITMODE_C, m_nPLimitMode_c);
	DDX_Radio(pDX, IDC_PULSEMODE_B, m_nPulseMode_b);
	DDX_Radio(pDX, IDC_PULSEMODE_C, m_nPulseMode_c);
	DDX_Radio(pDX, IDC_STOP0MODE_B, m_nStop0Mode_b);
	DDX_Radio(pDX, IDC_STOP0MODE_C, m_nStop0Mode_c);
	DDX_Radio(pDX, IDC_STOP1MODE_B, m_nStop1Mode_b);
	DDX_Radio(pDX, IDC_STOP1MODE_C, m_nStop1Mode_c);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBaseParaSet, CDialog)
	//{{AFX_MSG_MAP(CBaseParaSet)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBaseParaSet message handlers

BOOL CBaseParaSet::OnInitDialog() 
{
	CDialog::OnInitDialog();
	//************基本参数设置***********//

	//**********输出脉冲方式*************//
	//    0-脉冲＋脉冲   1－脉冲＋方向   //
	//        默认模式为脉冲＋方向       //
	//***********************************//
    m_nPulseMode_x  = 1;
	m_nPulseMode_y  = 1;
	m_nPulseMode_z  = 1;
	m_nPulseMode_a  = 1;
	m_nPulseMode_b  = 1;
	m_nPulseMode_c  = 1;
	//**********正限位模式设定***********//
	//    0-正限位有效   1－正限位无效   //
	//        默认模式为正限位有效       //
	//***********************************//
	m_nPLimitMode_x = 0;
	m_nPLimitMode_y = 0;
	m_nPLimitMode_z = 0;
	m_nPLimitMode_a = 0;
	m_nPLimitMode_b = 0;
	m_nPLimitMode_c = 0;
	//**********负限位模式设定***********//
	//    0-负限位有效   1－负限位无效   //
	//        默认模式为负限位有效       //
	//***********************************//
	m_nNLimitMode_x = 0;
	m_nNLimitMode_y = 0;
	m_nNLimitMode_z = 0;
	m_nNLimitMode_a = 0;
	m_nNLimitMode_b = 0;
	m_nNLimitMode_c = 0;
	//***********STOP0模式设定***********//
	//       0-无效   1－有效            //
	//        默认模式为无效             //
	//***********************************//
	m_nStop0Mode_x  = 0;
	m_nStop0Mode_y  = 0;
	m_nStop0Mode_z  = 0;
	m_nStop0Mode_a  = 0;
	m_nStop0Mode_b  = 0;
	m_nStop0Mode_c  = 0;
	//***********STOP1模式设定***********//
	//       0-无效   1－有效            //
	//        默认模式为无效             //
	//***********************************//
	m_nStop1Mode_x  = 0;
	m_nStop1Mode_y  = 0;
	m_nStop1Mode_z  = 0;
	m_nStop1Mode_a  = 0;
	m_nStop1Mode_b  = 0;
	m_nStop1Mode_c  = 0;
	//***********电平模式设定************//
	//此为限位、STOP0、STOP1模式下电平设定//
	//   0-低电平有效   1－高电平有效    //
	//        默认模式为低电平效         //
	//***********************************//
	m_nEffectLogic_x = 0;
	m_nEffectLogic_y = 0;
	m_nEffectLogic_z = 0;
	m_nEffectLogic_a = 0;
	m_nEffectLogic_b = 0;
	m_nEffectLogic_c = 0;
	//***********硬件停止设定************//
	//     此为硬件停止功能设定          //
	// m_nHardStop 0-无效   1-有效       //
	// m_nHardLogic 0-低电平  1-高电平   //
	//       默认为无效                  //
	//***********************************//
	m_nHardStop      = 0;
	m_nHardLogic     = 0;

	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBaseParaSet::OnOK() 
{
	UpdateData();

	effectlogic_x=m_nEffectLogic_x;
	
	effectlogic_y=m_nEffectLogic_y;
	
	effectlogic_z=m_nEffectLogic_z;
	
	effectlogic_a=m_nEffectLogic_a;

	effectlogic_b=m_nEffectLogic_b;
	
	effectlogic_c=m_nEffectLogic_c;
	
	registermode=m_nRegMode;

	int  pulsemode[]={m_nPulseMode_x, m_nPulseMode_y, m_nPulseMode_z, m_nPulseMode_a, m_nPulseMode_b, m_nPulseMode_c};    //脉冲输出方式      

	int  plimitmode[]={m_nPLimitMode_x, m_nPLimitMode_y, m_nPLimitMode_z, m_nPLimitMode_a, m_nPLimitMode_b, m_nPLimitMode_c};   //正限位模式 

	int  nlimitmode[]={m_nNLimitMode_x, m_nNLimitMode_y, m_nNLimitMode_z, m_nNLimitMode_a, m_nNLimitMode_b, m_nNLimitMode_c};   //负限位模式
	
	int  stop0mode[]={m_nStop0Mode_x, m_nStop0Mode_y, m_nStop0Mode_z,m_nStop0Mode_a, m_nStop0Mode_b,m_nStop0Mode_c};         //stop0模式

	int  stop1mode[]={m_nStop1Mode_x, m_nStop1Mode_y, m_nStop1Mode_z,m_nStop1Mode_a, m_nStop1Mode_b,m_nStop1Mode_c};         //stop1模式

	int  effectlogic[]={m_nEffectLogic_x, m_nEffectLogic_y, m_nEffectLogic_z, m_nEffectLogic_a, m_nEffectLogic_b, m_nEffectLogic_c};  //电平

	for(int i=1; i<MAXAXIS+1; i++)
	{
		//脉冲输出方式设置
		g_CtrlCard.Setup_PulseMode(i, pulsemode[i-1]);             

		//限位模式设置
		g_CtrlCard.Setup_LimitMode(i, plimitmode[i-1], nlimitmode[i-1], effectlogic[i-1]);

		//stop0信号模式设置
		g_CtrlCard.Setup_Stop0Mode(i, stop0mode[i-1], effectlogic[i-1]);

		//stop1信号模式设置
		g_CtrlCard.Setup_Stop1Mode(i, stop1mode[i-1], effectlogic[i-1]);
	}

	//硬件停止信号模式设置
	g_CtrlCard.Setup_HardStop(m_nHardStop, m_nHardLogic);

	CDialog::OnOK();
}
