由于使用备受各位大神鄙视的VC6.0,但问题实在分析不清楚,请各位帮忙解决一下。
且使用了RELEASE的obj文件,所以不能调试。
由于代码稍微有点多,不是太方便拷贝,请有空帮忙解决的大神们留下邮箱地址,我将代码发给你们进行检查。在线等
我的头文件#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "frame.h"
#include "mscomm.h"
#include "stdio.h"
#include "sfu.h"
/////////////////////////////////////////////////////////////////////////////
// CSerial_twoDlg dialog
#define WM_MY_MESSAGE (WM_USER+200)
typedef struct ber
{
int count;
int total;
}BER;
class CSerial_twoDlg : public CDialog
{
// Construction
public:
CSerial_twoDlg(CWnd* pParent = NULL); // standard constructor
int LogRecord(char* record);
int GetCommandFrame(unsigned char command,PTUNER_SETTING tuner_para=NULL);
/*int ProcessMessage(WPARAM wParam,LPARAM lParam);*/
CMSComm myComm;
FILE *logfile;
FILE *Resultfile;
CString logfilename;
CString resultname;
int device;
// Dialog Data
//{{AFX_DATA(CSerial_twoDlg)
enum { IDD = IDD_SERIAL_TWO_DIALOG };
CString m_info;
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSerial_twoDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
private:
static unsigned char command_frame[25];//命令帧
static unsigned char test;//测试类型
unsigned char modulation_system;
static unsigned char serialstatus;
static unsigned char tuner_setting_status;
protected:
HICON m_hIcon; // Generated message map functions
//{{AFX_MSG(CSerial_twoDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnDvbs(PTUNER_SETTING tuner_para=NULL);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnCommMscomm();
afx_msg int ProcessMessage(WPARAM wParam,LPARAM lParam);
afx_msg void OnSfu();
afx_msg void OnSend();
afx_msg void OnUp();
afx_msg void OnButton3();
afx_msg void OnSaveConfig();
afx_msg void OnDown();
afx_msg void OnSendRCommand();
afx_msg void HandShake();
afx_msg void SetTuner(PTUNER_SETTING tuner_para=NULL);
DECLARE_EVENTSINK_MAP()
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_SERIAL_TWODLG_H__EAADC58B_1612_4953_A386_5FB212667DD4__INCLUDED_)
且使用了RELEASE的obj文件,所以不能调试。
由于代码稍微有点多,不是太方便拷贝,请有空帮忙解决的大神们留下邮箱地址,我将代码发给你们进行检查。在线等
我的头文件#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "frame.h"
#include "mscomm.h"
#include "stdio.h"
#include "sfu.h"
/////////////////////////////////////////////////////////////////////////////
// CSerial_twoDlg dialog
#define WM_MY_MESSAGE (WM_USER+200)
typedef struct ber
{
int count;
int total;
}BER;
class CSerial_twoDlg : public CDialog
{
// Construction
public:
CSerial_twoDlg(CWnd* pParent = NULL); // standard constructor
int LogRecord(char* record);
int GetCommandFrame(unsigned char command,PTUNER_SETTING tuner_para=NULL);
/*int ProcessMessage(WPARAM wParam,LPARAM lParam);*/
CMSComm myComm;
FILE *logfile;
FILE *Resultfile;
CString logfilename;
CString resultname;
int device;
// Dialog Data
//{{AFX_DATA(CSerial_twoDlg)
enum { IDD = IDD_SERIAL_TWO_DIALOG };
CString m_info;
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSerial_twoDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
private:
static unsigned char command_frame[25];//命令帧
static unsigned char test;//测试类型
unsigned char modulation_system;
static unsigned char serialstatus;
static unsigned char tuner_setting_status;
protected:
HICON m_hIcon; // Generated message map functions
//{{AFX_MSG(CSerial_twoDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnDvbs(PTUNER_SETTING tuner_para=NULL);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnCommMscomm();
afx_msg int ProcessMessage(WPARAM wParam,LPARAM lParam);
afx_msg void OnSfu();
afx_msg void OnSend();
afx_msg void OnUp();
afx_msg void OnButton3();
afx_msg void OnSaveConfig();
afx_msg void OnDown();
afx_msg void OnSendRCommand();
afx_msg void HandShake();
afx_msg void SetTuner(PTUNER_SETTING tuner_para=NULL);
DECLARE_EVENTSINK_MAP()
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_SERIAL_TWODLG_H__EAADC58B_1612_4953_A386_5FB212667DD4__INCLUDED_)
#include "serial_two.h"
#include "serial_twoDlg.h"
#include "crc.h"
#include "time.h"
#include "sfu.h"
#include "s_control.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MYDEBUG
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
unsigned char CSerial_twoDlg::command_frame[25]={'\0'};//初始化命令帧空间
unsigned char CSerial_twoDlg::test=0;//测试类型
unsigned char CSerial_twoDlg::serialstatus=0;//初始串口状态为未连接状态
unsigned char serialretry=0;
unsigned char CSerial_twoDlg::tuner_setting_status=0;//tuner设定成功后为1;
TUNER_STATUS mytuner={-1};
UINT retrytimer=1;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CSerial_twoDlg dialogCSerial_twoDlg::CSerial_twoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSerial_twoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSerial_twoDlg)
m_info = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); /*初始化modulation_system*/
}void CSerial_twoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSerial_twoDlg)
DDX_Text(pDX, IDC_info, m_info);
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CSerial_twoDlg, CDialog)
//{{AFX_MSG_MAP(CSerial_twoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_DVBS, OnDvbs)
ON_WM_TIMER()
ON_MESSAGE(WM_MY_MESSAGE,ProcessMessage)
ON_BN_CLICKED(IDC_SFU, OnSfu)
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_BN_CLICKED(IDC_BUTTON2, OnUp)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_SaveConfig, OnSaveConfig)
ON_BN_CLICKED(IDC_DOWN, OnDown)
ON_BN_CLICKED(IDC_SEND_R_COMMAND, OnSendRCommand)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CSerial_twoDlg message handlers
BOOL CSerial_twoDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
device=0;
CTime time_t=CTime::GetCurrentTime();
logfilename=time_t.Format("%B_%d_%H_%M");
logfilename+=".txt";
resultname="reslut";
resultname+=time_t.Format("%B_%d_%H_%M");
resultname+=".txt";
DWORD style=WS_VISIBLE|WS_CHILD;
if (!myComm.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM1))
{
AfxMessageBox("failed to creat the mscomm!");
return FALSE;
}
else
{
if(myComm.GetPortOpen())
{
myComm.SetPortOpen(0);
}
myComm.SetCommPort(3);
myComm.SetSettings("115200,N,8,1");
myComm.SetInBufferSize(1024);//设置串口BUFFER的大小
myComm.SetInBufferCount(0);//清空串口buffer
myComm.SetInputMode(1);//设置读取方式为二进制方式
//为什么这样设置?读取五个,后面岂不是没?
//myComm.SetInputLen(5);
myComm.SetInputLen(20);//设置一次读取字节数
myComm.SetRThreshold(1);
myComm.SetPortOpen(1);
if(myComm.GetPortOpen())
{
LogRecord("创建串口失败\n");
m_info+="创建串口失败\r\n";
}
}
if((logfile=fopen( logfilename.GetBuffer(logfilename.GetLength()),"wb+" )) == NULL)
{
m_info+="logfile创建失败\r\n";
myComm.SetPortOpen(0);
logfilename.ReleaseBuffer();
exit(1);
}
else
{
/*fprintf(logfile,"logfile创建成功\n");*/
LogRecord("logfile创建成功\n");
/*
m_info+=logfilename.GetBuffer(logfilename.GetLength());
m_info+="\r\n";*/
m_info+="logfile创建成功\r\n";
UpdateData(0);
logfilename.ReleaseBuffer();
}
if((Resultfile=fopen( resultname.GetBuffer(logfilename.GetLength()),"wb+" )) == NULL)
{
m_info+="Resultfile创建失败\r\n";
myComm.SetPortOpen(0);
resultname.ReleaseBuffer();
exit(1);
}
else
{
LogRecord("resultfile创建成功\n");
m_info+="resultfile创建成功\r\n";
UpdateData(0);
resultname.ReleaseBuffer();
}// device=GetGPIBHandle();
// if(!device)
// {
// LogRecord("未能找到GPIB连接卡\n");
// }
return TRUE; // return TRUE unless you set the focus to a control
}
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CSerial_twoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSerial_twoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}unsigned int COUNT_PARSE(BYTE *receive,unsigned char star,unsigned char end)
{
unsigned int result=0;
result=receive[star]<<8;
result|=receive[star+1]<<0;
// result|=receive[star+2]<<8;
// result|=receive[star+3];
return result;
}
int CSerial_twoDlg::LogRecord(char* record)
{
if((logfile=fopen(logfilename,"a+"))!=NULL)
{
if(fprintf(logfile,record))
{
fclose(logfile);
return 1;
}
else
{
m_info+="logrecord failed\r\n";
UpdateData(0);
return 0;
}
}
else
{
m_info+="文件打开失败";
return 0;
}}int CSerial_twoDlg::ProcessMessage(WPARAM wParam,LPARAM lParam)
{ CByteArray Array;
int i=0;
CString str=(char*)wParam;
/*str.Format("%s",(char*)wParam);*/
/*LogRecord(str.GetBuffer(str.GetLength()));*/
m_info+="\r\nProcessMessage函数\r\n";
m_info+=str;
m_info+="\r\n";
str.ReleaseBuffer(); /*if(strcmp((char*)wParam,"T"))*/
/*无法比较用strcmp来进行比较判断*/
if("T"==str)
{
GetCommandFrame('R');
Array.RemoveAll();
Array.SetSize(5);
for(int i=0;i<5;i++)
{
Array.SetAt(i,command_frame[i]);
str.Format("%x_",command_frame[i]);
if(0==i)
{
LogRecord("ProcessMessage发送数据 R:\n");
}
LogRecord(str.GetBuffer(str.GetLength()));
m_info+=str;
if(i==4)
{
LogRecord("\n");
m_info+="\r\n";
}
str.ReleaseBuffer();
UpdateData(0); }
myComm.SetOutput(COleVariant(Array));
LogRecord("ProcessMessage已发送R命令\n");
Sleep(1000);
return 1;
}
else
{
LogRecord("处理消息不为T\n");
m_info+="处理消息不为T\r\n";
return 0;
}
if("P"==str)
{
LogRecord("p命令被处理\n");
m_info+="p命令被处理\r\n";
}
}int CSerial_twoDlg::GetCommandFrame(unsigned char command,PTUNER_SETTING tuner_para)
{
memset(command_frame,-1,25);
if(command=='H'||command=='R'||command=='D')
{
command_frame[0]=0xAA;
command_frame[1]=command;
command_frame[2]=0x0;
command_frame[3]=0x1;
command_frame[4]=CRC(command_frame,4);
return 1;
}
if(command=='S')
{
if(tuner_para!=NULL)
{
/*if(tuner_para->DV)*/
if(modulation_system==0x0)
{
command_frame[0]=0xaa;
command_frame[1]=command;
command_frame[2]=0x0;
command_frame[3]=0xc;//command_lenth
command_frame[4]=((tuner_para->tuner_s_para.frequence*1000000)&0xff000000)>>24;//保留高8位
command_frame[5]=((tuner_para->tuner_s_para.frequence*1000000)&0x00ff0000)>>16;
command_frame[6]=((tuner_para->tuner_s_para.frequence*1000000)&0x0000ff00)>>8;
command_frame[7]=(tuner_para->tuner_s_para.frequence*1000000)&0x000000ff;
command_frame[8]=0x0;//调制模式
command_frame[9]=((tuner_para->tuner_s_para.symbol_rate*1000000)&0xff000000)>>24;
command_frame[10]=((tuner_para->tuner_s_para.symbol_rate*1000000)&0x00ff0000)>>16;
command_frame[11]=((tuner_para->tuner_s_para.symbol_rate*1000000)&0x0000ff00)>>8;
command_frame[12]=(tuner_para->tuner_s_para.symbol_rate*1000000)&0x000000ff;
/*if((tuner_para->tuner_s_para.fec_inner)==3/4)*/ //浮点数比较通常容易出差
command_frame[13]=0x3; //FEC-INNER
// else
// {
// command_frame[13]=0x3;
// LogRecord("错误的FEC\n");
// }
command_frame[14]=tuner_para->tuner_s_para.power;
command_frame[15]=CRC(command_frame,15);
return 1;
}
else
{
LogRecord("构造DVBS命令帧失败\n");
return 0;
}
} }
return 1;
}void CSerial_twoDlg::HandShake()
{
CByteArray Array;
CString str;
GetCommandFrame('H');
Array.RemoveAll();
Array.SetSize(5);
for(int i=0;i<5;i++)
{
Array.SetAt(i,command_frame[i]);
str.Format("%x_",command_frame[i]);
if(0==i)
{
LogRecord("发送数据:\n");
}
LogRecord(str.GetBuffer(str.GetLength()));
m_info+=str;
if(i==4)
{
LogRecord("\n");
m_info+="\r\n";
}
str.ReleaseBuffer();
UpdateData(0);
}
myComm.SetOutput(COleVariant(Array));
m_info+="握手参数已发送完毕\r\n";
MessageBox("握手参数已发送完毕");
Sleep(10);}void CSerial_twoDlg::SetTuner(PTUNER_SETTING tuner_para)
{
CByteArray Array;
CString str;
TUNER_SETTING mytest={1150,27500,3,1};
modulation_system=0;
if(0==modulation_system)
{
if(!GetCommandFrame('S',&mytest))
{
LogRecord("命令帧失败\n");
}
else
{
unsigned short length=16;
Array.RemoveAll();
Array.SetSize(length);
for(int i=0;i<length;i++)
{
Array.SetAt(i,command_frame[i]);
if(0==i)
{
LogRecord("DVBS发送数据为:\n");
m_info+="DVBS发送数据为:\r\n";
}
str.Format("%x_",command_frame[i]);
LogRecord(str.GetBuffer(str.GetLength()));
m_info+=str;
if(length==15) //每打印16个数据就换行
{
LogRecord("\n");
m_info+="\r\n";
}
str.ReleaseBuffer();
UpdateData(0);
}
myComm.SetOutput(COleVariant(Array));
m_info+="tuner参数已发送完毕\r\n";
LogRecord("tuner参数已发送完毕\n");
}
}
Sleep(10);
}
debug的话都不能编译通过。
还会自己关闭的对话框没见过~~估计是你代码问题