www.pudn.com > PCMtoWave.rar > SerialPortDlg.cpp
// SerialPortDlg.cpp : implementation file
//
#include "stdafx.h"
#include "wave.h"
#include "SerialPortDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define INDEX_OF_PERSON 1
#define INDEX_OF_COMMAND 1
/////////////////////////////////////////////////////////////////////////////
// CSerialPortDlg dialog
CSerialPortDlg::~CSerialPortDlg()
{
delete []rcvdArray;
}
CSerialPortDlg::CSerialPortDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSerialPortDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSerialPortDlg)
m_strReceiveData = _T("");
m_strSendData = _T("");
//}}AFX_DATA_INIT
n_ReceiveLength = 0;
rcvdArray = new char[2097152];//分配空间2M
reversed = 0;
person_index=INDEX_OF_PERSON;
command_index=INDEX_OF_COMMAND;
person_index2 = INDEX_OF_PERSON;
command_index2 = INDEX_OF_COMMAND;
}
void CSerialPortDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSerialPortDlg)
DDX_Control(pDX, IDC_MSCOMM1, m_ctrlComm);
DDX_Text(pDX, IDC_EDIT_RECEIVE, m_strReceiveData);
DDX_Text(pDX, IDC_EDIT_SEND, m_strSendData);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSerialPortDlg, CDialog)
//{{AFX_MSG_MAP(CSerialPortDlg)
ON_BN_CLICKED(IDC_BUTTON_OpenPort, OnBUTTONOpenPort)
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
ON_BN_CLICKED(IDC_BUTTON_SAVEPCM, OnButtonSavepcm)
ON_BN_CLICKED(IDC_BUTTON_SAVEWAV, OnButtonSavewav)
ON_BN_CLICKED(IDC_BUTTON_MANUALSEND, OnButtonManualsend)
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_BN_CLICKED(IDC_BUTTON_ZANTING, OnButtonZanting)
ON_BN_CLICKED(IDC_BUTTON_CONTINUE, OnButtonContinue)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_BN_CLICKED(IDC_BUTTON_RESTART, OnButtonRestart)
ON_BN_CLICKED(IDC_BUTTON_READFILEBTN, OnButtonReadfilebtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSerialPortDlg message handlers
int CSerialPortDlg::DoModal()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DoModal();
}
BEGIN_EVENTSINK_MAP(CSerialPortDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CSerialPortDlg)
ON_EVENT(CSerialPortDlg, IDC_MSCOMM1, 1 /* OnComm */, OnComm, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
//SerialPortDIALOG初始化
BOOL CSerialPortDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
n_ReceiveLength = 0;
reversed = 0;
// person_index=INDEX_OF_PERSON;
// command_index=INDEX_OF_COMMAND;
// person_index2 = INDEX_OF_PERSON;
// command_index2 = INDEX_OF_COMMAND;
GetModuleFileName(NULL,path.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
path.ReleaseBuffer ();
int nPos;
nPos=path.ReverseFind ('\\');
path=path.Left (nPos);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//串口接收数据并显示在编辑框
void CSerialPortDlg::OnComm()
{
// TODO: Add your control notification handler code here
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG len,k;
BYTE rxdata[2048]; //设置BYTE数组 An 8-bit integerthat is not signed.
for(k=0;k<2048;k++)
{
rxdata[k] = '0';
}
CString strtemp;
if(m_ctrlComm.GetCommEvent()==2) //事件值为2表示接收缓冲区内有字符
{ ////////以下你可以根据自己的通信协议加入处理代码
variant_inp=m_ctrlComm.GetInput(); //读缓冲区
safearray_inp=variant_inp; //VARIANT型变量转换为ColeSafeArray型变量
len=safearray_inp.GetOneDimSize(); //得到有效数据长度
for(k=0;k