// PM.cpp : implementation file
//

#include "stdafx.h"
#include "PeakTech_4055MV_4060.h"
#include "PM.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPM dialog


CPM::CPM(CWnd* pParent /*=NULL*/)
	: CDialog(CPM::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPM)
	m_pmDev = 180;
	m_pmFreq = 1000.0;
	//}}AFX_DATA_INIT
}


void CPM::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPM)
	DDX_Control(pDX, IDC_PMWAVE, m_comWave);
	DDX_Control(pDX, IDC_PMSTATE, m_comOutput);
	DDX_Control(pDX, IDC_PMFREQUNIT, m_comFreq);
	DDX_Text(pDX, IDC_PMDEV, m_pmDev);
	DDX_Text(pDX, IDC_PMFREQ, m_pmFreq);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CPM message handlers

void CPM::Send()
{
//	CString str12 = m_pMainWnd->m_text;
	
char *ptr;
	CString str,str_dev,str_freq,str_wave,str_output;
	m_comFreq.GetWindowText(str_freq);
	m_comWave.GetWindowText(str_wave);
	m_comOutput.GetWindowText(str_output);

	ULONG len;
	ptr = (char*)malloc(1024);
	UpdateData();
#if 1
	str.Format("PM:STATe %s",str_output);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);	
    m_str=str + "\r\n";
	
	Sleep(500);

	str.Format("PM:INTernal:FREQuency %f%s",m_pmFreq,str_freq);
	strcpy(ptr, str);	
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
	m_str= m_str + str +"\r\n";
	Sleep(200);
str.Format("PM:DEViation %ddeg",m_pmDev);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
	m_str= m_str + str +"\r\n";
#endif
	Sleep(100);
	Sleep(100);
	str.Format("PM:INTernal:FUNCtion %s",str_wave);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
		m_str= m_str + str +"\r\n";
    free(ptr);
}

BOOL CPM::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_comFreq.SetCurSel(1);
	m_comWave.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
}
