// Burst.cpp : implementation file
//

#include "stdafx.h"
#include "PeakTech_4055MV_4060.h"
#include "Burst.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBurst dialog


CBurst::CBurst(CWnd* pParent /*=NULL*/)
	: CDialog(CBurst::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBurst)
	m_burstPeriod = 0.1;
	m_burstPhase = 0;
	m_burstNcycle = 3;
	//}}AFX_DATA_INIT
}


void CBurst::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBurst)
	DDX_Control(pDX, IDC_Burst_STATE, m_comOutput);
	DDX_Control(pDX, IDC_BURST_SOURCE, m_comSource);
	DDX_Control(pDX, IDC_BURST_PERIOD_UNIT, m_comPeriod);
	DDX_Text(pDX, IDC_BURST_PERIOD, m_burstPeriod);
	DDX_Text(pDX, IDC_BURST_PHASE, m_burstPhase);
	DDX_Text(pDX, IDC_BURST_NCYCLES, m_burstNcycle);
	DDV_MinMaxInt(pDX, m_burstNcycle, 1, 9);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBurst, CDialog)
	//{{AFX_MSG_MAP(CBurst)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBurst message handlers

BOOL CBurst::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_comPeriod.SetCurSel(0);
	m_comSource.SetCurSel(0);
	m_comOutput.SetCurSel(0);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBurst::Send()
{
char *ptr;
	CString str,str_period,str_source,str_output;
	m_comPeriod.GetWindowText(str_period);
	m_comSource.GetWindowText(str_source);
	m_comOutput.GetWindowText(str_output);

	ULONG len;
	ptr = (char*)malloc(1024);
	UpdateData();	
	str.Format("BURSt:STATe %s",str_output);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
		m_str=str + "\r\n";
Sleep(200);
	str.Format("BURSt:INTernal:PERiod %f%s",m_burstPeriod,str_period);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str + "\r\n";
	Sleep(200);
	str.Format("BURSt:NCYCles %d",m_burstNcycle);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str + "\r\n";
	Sleep(200);
	str.Format("BURSt:PHASe %ddeg",m_burstPhase);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str +"\r\n";
	
	Sleep(100);
	str.Format("TRIGger:SOURce %s",str_source);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str +  "\r\n";
    free(ptr);
}

void CBurst::OnButton1() 
{
	// TODO: Add your control notification handler code here
		// TODO: Add your control notification handler code here
	    char *ptr;
	CString str;
	ULONG len;

	ptr = (char*)malloc(1024);
	str="*TRG";
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
	m_str=str ;
	free(ptr);	
}
