📄 eubrsdlg.cpp
字号:
// EUBRSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "EUBRS.h"
#include "EUBRSDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CEUBRSDlg dialog
CEUBRSDlg::CEUBRSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEUBRSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEUBRSDlg)
m_da1 = 0.1f;
m_da2 = 0.2f;
m_da3 = 0.3f;
m_da4 = 0.4f;
m_da5 = 0.5f;
m_da6 = 0.6f;
m_da7 = 0.7f;
m_da8 = 0.8f;
m_range1 = 5;
m_range2 = 5;
m_range3 = 5;
m_range4 = 5;
m_range5 = 5;
m_range6 = 5;
m_range7 = 5;
m_range8 = 5;
m_scanmethod = 1;
m_ch1 = TRUE;
m_ch2 = TRUE;
m_ch3 = TRUE;
m_ch4 = TRUE;
m_ch5 = TRUE;
m_ch6 = TRUE;
m_ch7 = TRUE;
m_ch8 = TRUE;
m_high = 0.5f;
m_scanspeed = 100;
m_segment = 10;
m_start = 0.0f;
m_timeall = 100;
m_timedelay = 0;
m_timedelayit = 0;
m_interval = 10;
m_intervalit = 100;
m_low = -0.3f;
m_pn = 1;
m_lab = _T("");
m_map = _T("");
m_commstate = _T("");
m_ss = _T("Data:");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CEUBRSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEUBRSDlg)
DDX_Control(pDX, IDC_BUTTON2, m_RangePress);
DDX_Control(pDX, IDC_BUTTON1, m_DAPress);
DDX_Control(pDX, IDC_BUTTON_Start, m_SStart);
DDX_Control(pDX, IDC_BUTTON_DeleteData, m_Delete);
DDX_Control(pDX, IDC_BUTTON_StopSample, m_Stop);
DDX_Control(pDX, IDC_PROGRESS2, m_pp);
DDX_Text(pDX, IDC_EDIT_DA1, m_da1);
DDV_MinMaxFloat(pDX, m_da1, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_DA2, m_da2);
DDV_MinMaxFloat(pDX, m_da2, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_DA3, m_da3);
DDV_MinMaxFloat(pDX, m_da3, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_DA4, m_da4);
DDV_MinMaxFloat(pDX, m_da4, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_DA5, m_da5);
DDV_MinMaxFloat(pDX, m_da5, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_DA6, m_da6);
DDV_MinMaxFloat(pDX, m_da6, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_DA7, m_da7);
DDV_MinMaxFloat(pDX, m_da7, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_DA8, m_da8);
DDV_MinMaxFloat(pDX, m_da8, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_range1, m_range1);
DDV_MinMaxInt(pDX, m_range1, 0, 5);
DDX_Text(pDX, IDC_EDIT_range2, m_range2);
DDV_MinMaxInt(pDX, m_range2, 0, 5);
DDX_Text(pDX, IDC_EDIT_range3, m_range3);
DDV_MinMaxInt(pDX, m_range3, 0, 5);
DDX_Text(pDX, IDC_EDIT_range4, m_range4);
DDV_MinMaxInt(pDX, m_range4, 0, 5);
DDX_Text(pDX, IDC_EDIT_range5, m_range5);
DDV_MinMaxInt(pDX, m_range5, 0, 5);
DDX_Text(pDX, IDC_EDIT_range6, m_range6);
DDV_MinMaxInt(pDX, m_range6, 0, 5);
DDX_Text(pDX, IDC_EDIT_range7, m_range7);
DDV_MinMaxInt(pDX, m_range7, 0, 5);
DDX_Text(pDX, IDC_EDIT_range8, m_range8);
DDV_MinMaxInt(pDX, m_range8, 0, 5);
DDX_Text(pDX, IDC_EDIT_ScanMethod, m_scanmethod);
DDV_MinMaxInt(pDX, m_scanmethod, 1, 2);
DDX_Check(pDX, IDC_CHECK_Channel1, m_ch1);
DDX_Check(pDX, IDC_CHECK_Channel2, m_ch2);
DDX_Check(pDX, IDC_CHECK_Channel3, m_ch3);
DDX_Check(pDX, IDC_CHECK_Channel4, m_ch4);
DDX_Check(pDX, IDC_CHECK_Channel5, m_ch5);
DDX_Check(pDX, IDC_CHECK_Channel6, m_ch6);
DDX_Check(pDX, IDC_CHECK_Channel7, m_ch7);
DDX_Check(pDX, IDC_CHECK_Channel8, m_ch8);
DDX_Text(pDX, IDC_EDIT_High, m_high);
DDV_MinMaxFloat(pDX, m_high, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_ScanSpeed, m_scanspeed);
DDX_Text(pDX, IDC_EDIT_Segment, m_segment);
DDX_Text(pDX, IDC_EDIT_Start, m_start);
DDV_MinMaxFloat(pDX, m_start, -2.048f, 2.048f);
DDX_Text(pDX, IDC_EDIT_TimeAll, m_timeall);
DDX_Text(pDX, IDC_EDIT_TimeDelay, m_timedelay);
DDX_Text(pDX, IDC_EDIT_TimeDelayIT, m_timedelayit);
DDX_Text(pDX, IDC_EDIT_Interval, m_interval);
DDX_Text(pDX, IDC_EDIT_IntervalIT, m_intervalit);
DDX_Text(pDX, IDC_EDIT_Low, m_low);
DDX_Text(pDX, IDC_EDIT_PN, m_pn);
DDV_MinMaxInt(pDX, m_pn, 1, 2);
DDX_Text(pDX, IDC_STATIC_Message, m_lab);
DDX_Text(pDX, IDC_STATIC_map, m_map);
DDX_Text(pDX, IDC_STATIC_COMMSTATE, m_commstate);
DDX_Text(pDX, IDC_STATIC_SS, m_ss);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEUBRSDlg, CDialog)
//{{AFX_MSG_MAP(CEUBRSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON_Start, OnBUTTONStart)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_DeleteData, OnBUTTONDeleteData)
ON_BN_CLICKED(IDC_BUTTON_StopSample, OnBUTTONStopSample)
ON_MESSAGE(WM_DATASAVE,OnDataSave)
ON_BN_CLICKED(IDC_BUTTON_Detecting, OnBUTTONDetecting)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_CHECK_Channel1, OnCHECKChannel1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEUBRSDlg message handlers
BOOL CEUBRSDlg::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
/*CEUBRSApp *app = (CEUBRSApp *)AfxGetApp();
app->FindParamOutpt = FALSE ;
app->USBDevice = new CCyUSBDevice(m_hWnd); // Create an instance of CCyUSBDevice
app->GetPort(); */
GetBuffer();
canrec = false;
m_SStart.EnableWindow(TRUE);
m_Stop.EnableWindow(FALSE);
m_Delete.EnableWindow(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CEUBRSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
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 CEUBRSDlg::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 CEUBRSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CEUBRSDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
CEUBRSApp *app = (CEUBRSApp *)AfxGetApp();
if(app->USBDevice->IsOpen())
app->USBDevice->Close();
if (app->USBDevice)
delete app->USBDevice;
DeleteBuffer();
// TODO: Add your message handler code here
}
void CEUBRSDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CEUBRSDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CEUBRSApp *app = (CEUBRSApp *)AfxGetApp();
bool flag1[8];
float da[8];
int but1;
if( !app->FindParamOutpt )
{
MessageBox("未发现端口!","Warning!");
}
else
{
m_DAPress.EnableWindow(FALSE);
unsigned char *str = app->com_str ;
UpdateData(TRUE) ; // 获取各个设置
da[0] = (m_da1+2.048)/4.096;//把设置的电压值计算到DA设置的范围之内(0x000 ----- 0xfff)
da[1] = (m_da2+2.048)/4.096;
da[2] = (m_da3+2.048)/4.096;
da[3] = (m_da4+2.048)/4.096;
da[4] = (m_da5+2.048)/4.096;
da[5] = (m_da6+2.048)/4.096;
da[6] = (m_da7+2.048)/4.096;
da[7] = (m_da8+2.048)/4.096;
str[0] = 0x42 ;//起始指令
str[1] = 0x44 ;//操作类型
str[5] = 0x4A ;//终止指令
for(but1=0;but1<8;but1++)//将八路设置值存入发送缓冲
{
flag1[but1] = false;
str[2] = but1+1 ;
da[but1] = da[but1]*4095;
str[3] = ((int)da[but1])/256;
str[4] = ((int)da[but1])%256;
app->ParamOutEndpt->TimeOut = 2000;
flag1[but1] = app->SendParam (str,6) ;
Sleep(200);
}
m_DAPress.EnableWindow(TRUE);
if( flag1[0]&&flag1[1]&&flag1[2]&&flag1[3]&&flag1[4]&&flag1[5]&&flag1[6]&&flag1[7])
{
MessageBox("八路DA 配置成功!") ;
}
else
{
MessageBox("DA配置失败,请检查硬件!") ;
}
}
}
void CEUBRSDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CEUBRSApp *app = (CEUBRSApp *)AfxGetApp();
bool flagrange = false;
if( !app->FindParamOutpt )
{
MessageBox("未发现端口!","Warning!");
}
else
{
m_RangePress.EnableWindow(FALSE);
unsigned char *str = app->com_str ;
UpdateData(TRUE) ; // 获取各个设置
str[0] = 0x42 ;
str[1] = 0x41 ;
str[2] = m_range1;
str[3] = m_range2;
str[4] = m_range3;
str[5] = m_range4;
str[6] = m_range5;
str[7] = m_range6;
str[8] = m_range7;
str[9] = m_range8;
str[10] = 0x4A ;
flagrange = app->SendParam (str,11) ;//发送
Sleep(300);
m_RangePress.EnableWindow(TRUE);
}
if(flagrange)//检测是否发送成功
{
MessageBox("量程配置成功!") ;
}
else
{
MessageBox("量程配置失败,请检查硬件!") ;
}
}
void CEUBRSDlg::OnBUTTONStart()
{
// TODO: Add your control notification handler code here
CEUBRSApp *app = (CEUBRSApp *)AfxGetApp();
unsigned char *str = app->com_str ;
bool flagstart = false;
int startcount;
if( !app->FindParamOutpt )//检测是否检测到传输设备
{
MessageBox("未发现端口!","Warning!");
}
else
{
UpdateData(TRUE) ; // 获取各个设置
int Way;
float start,low,high;
Way = 0;//设置要启动的采样路数
if(m_ch1) Way = Way + 1;if(m_ch2) Way = Way + 2;if(m_ch3) Way = Way + 4;if(m_ch4) Way = Way + 8;
if(m_ch5) Way = Way + 16;if(m_ch6) Way = Way + 32;if(m_ch7) Way = Way + 64;if(m_ch8) Way = Way + 128;
start = (m_start + 2.048)/4.096;//循环伏安法扫描的初始&最高电压设置
high = (m_high + 2.048)/4.096;
low = (m_low + 2.048)/4.096;
start = start*4095;
high = high*4095;
low = low*4095;
if(m_scanmethod == 1)
{
if(m_pn = 1)
TimeSample = (high - start)/m_scanspeed + (m_segment - 1)*(high - low)/m_scanspeed;
else
TimeSample = (start - low)/m_scanspeed + (m_segment - 1)*(high - low)/m_scanspeed; //总的采样时间计算
TimeAll = TimeSample + m_timedelay;
str[0] = 0x42 ;
str[1] = 0x52 ; //启动
str[2] = m_timedelay;
str[3] = m_segment/256;
str[4] = m_segment%256;
str[5] = m_interval;
str[6] = m_scanspeed/256;
str[7] = m_scanspeed%256;
str[8] = Way;
str[9] = m_pn;
str[10] = (int)(start/256) ;
str[11] = (int)((int)start%256) ;
str[12] = (int)(low/256);
str[13] = (int)((int)low%256);
str[14] = (int)(high/256);
str[15] = (int)((int)high%256);
str[16] = 1;
str[17] = ((long)TimeSample*m_scanspeed/m_interval)/256;
str[18] = ((long)TimeSample*m_scanspeed/m_interval)%256;
str[19] = 0x4A;
}
else
{
TimeSample = m_timeall;
TimeAll = TimeSample + m_timedelayit;
str[0] = 0x42 ;
str[1] = 0x52 ;
str[2] = m_timedelayit;
str[3] = m_timeall/256;
str[4] = m_timeall%256;
str[6] = m_intervalit/256;
str[7] = m_intervalit%256;
str[8] = Way;
str[16] = 2;
str[17] = ((long)TimeSample*1000/m_intervalit)/256;
str[18] = ((long)TimeSample*1000/m_intervalit)%256;
str[19] = 0x4A;
}
// GetBuffer();
InitQuene();
for(startcount=0;startcount<8;startcount++)
DataSavingCount[startcount] = 0;
SetTimer(2,35,NULL);
canrec = true;
flagstart = app->SendParam (str,20) ;
app->ParamInEndpt->Abort();
Sleep(200);
TimeCount = TimeAll;
}
if(flagstart)
{
SetTimer(1,1000,NULL) ;
//SetTimer(3,15,NULL);
m_pp.SetRange(0,30);
pCount = 0;
m_commstate = "配置成功,启动采样正常.";
m_SStart.EnableWindow(FALSE);
m_Stop.EnableWindow(TRUE);
m_Delete.EnableWindow(FALSE);
UpdateData(FALSE) ;
}
else
{
m_commstate = "配置失败,请检查硬件,然后重新启动程序!";
UpdateData(FALSE) ;
}
}
void CEUBRSDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int TimerCount;
CEUBRSApp *app = (CEUBRSApp *)AfxGetApp();
RecLen = 1024;
ZeroMemory(RecBuf,2048);
if(nIDEvent == 1)
{
char strr[20];
if(TimeCount > TimeSample)
{
sprintf(strr,"%d",TimeCount - TimeSample);
m_map = "Delaying";
m_lab = strr;//"Delaying";//
m_lab = m_lab + "Sec";
UpdateData(FALSE) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -