// AM.cpp : implementation file
//

#include "stdafx.h"
#include "PeakTech_4055MV_4060.h"
#include "AM.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAM dialog


CAM::CAM(CWnd* pParent /*=NULL*/)
	: CDialog(CAM::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAM)
	m_amDept = 100;
	m_amFreq = 1000.0;
	//}}AFX_DATA_INIT
}


void CAM::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAM)
	DDX_Control(pDX, IDC_AMSTATE, m_comOutput);
	DDX_Control(pDX, IDC_AMWAVE, m_comWave);
	DDX_Control(pDX, IDC_AMFREQUNIT, m_comFreq);
	DDX_Text(pDX, IDC_AMDEPTH, m_amDept);
	DDX_Text(pDX, IDC_AMFreq, m_amFreq);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CAM message handlers

BOOL CAM::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
}

void CAM::Send()
{
 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();	str.Format("AM:STATe %s",str_output);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=str +  "\r\n";
#if 1
	Sleep(300);
	str.Format("AM:INTernal:FREQuency %f%s",m_amFreq,str_freq);
	strcpy(ptr, str);	
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str + "\r\n";	

	Sleep(200);
	Sleep(100);
	str.Format("AM:DEPTh %d%%",m_amDept);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str + "\r\n";
	Sleep(100);
	str.Format("AM: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";
#endif
    free(ptr);
}
