// FM.cpp : implementation file
//

#include "stdafx.h"
#include "PeakTech_4055MV_4060.h"
#include "FM.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFM dialog


CFM::CFM(CWnd* pParent /*=NULL*/)
	: CDialog(CFM::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFM)
	m_fmDev = 1000.0;
	m_fmFreq = 1000.0;
	//}}AFX_DATA_INIT
}


void CFM::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFM)
	DDX_Control(pDX, IDC_FMWAVE, m_comWave);
	DDX_Control(pDX, IDC_FMSTATE, m_comOutput);
	DDX_Control(pDX, IDC_FMFREQUNIT, m_comMode);
	DDX_Control(pDX, IDC_FMDEVUNIT, m_comDev);
	DDX_Text(pDX, IDC_FMDEV, m_fmDev);
	DDX_Text(pDX, IDC_FMFreq, m_fmFreq);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFM, CDialog)
	//{{AFX_MSG_MAP(CFM)
	ON_WM_CANCELMODE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFM message handlers

BOOL CFM::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_comDev.SetCurSel(2);
	m_comMode.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
}


void CFM::Send()
{
    char *ptr;
	CString str,str_dev,str_freq,str_wave,str_output;
	m_comDev.GetWindowText(str_dev);
	m_comMode.GetWindowText(str_freq);
	m_comWave.GetWindowText(str_wave);
	m_comOutput.GetWindowText(str_output);
	ULONG len;
	ptr = (char*)malloc(1024);
	UpdateData();

	str.Format("FM:STATe %s",str_output);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
	m_str=str + "\r\n";
	
	Sleep(300);
	str.Format("FM:INTernal:FREQuency %f%s",m_fmFreq,str_freq);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str +  "\r\n";

	Sleep(100);	Sleep(200);
	str.Format("FM:DEViation %f%s",m_fmDev,str_dev);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str +  "\r\n";


	Sleep(100);
	str.Format("FM: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);
}
