// PWM.cpp : implementation file
//

#include "stdafx.h"
#include "PeakTech_4055MV_4060.h"
#include "PWM.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPWM dialog


CPWM::CPWM(CWnd* pParent /*=NULL*/)
	: CDialog(CPWM::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPWM)
	m_pwmDev = 50;
	m_pwmFreq = 1000.0;
	//}}AFX_DATA_INIT
}


void CPWM::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPWM)
	DDX_Control(pDX, IDC_PWMWAVE, m_comWave);
	DDX_Control(pDX, IDC_PWMSTATE, m_comOutput);
	DDX_Control(pDX, IDC_PWMFREQUNIT, m_comFreq);
	DDX_Text(pDX, IDC_PWMDEV, m_pwmDev);
	DDX_Text(pDX, IDC_PWMFreq, m_pwmFreq);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CPWM message handlers

BOOL CPWM::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 CPWM::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("PWM:STATe %s",str_output);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=str + "\r\n";
	Sleep(100);
	Sleep(200);	
	str.Format("PWM:INTernal:FREQuency %f%s",m_pwmFreq,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("PWM:DCYCle %d%%",m_pwmDev);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str +"\r\n";

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