📄 fspsoftview.cpp
字号:
// FspSoftView.cpp : implementation of the CFspSoftView class
//
#include "stdafx.h"
#include "FspSoft.h"
#include "FspSoftDoc.h"
#include "FspSoftView.h"
#include "Global.h"
#include "dll/GpibDll.h"
#include <math.h>
bool time_count_flag;
DWORD time_start;
DWORD time_stop;
DWORD WINAPI Thread_Timecounting(LPVOID lParam)
{
CFspSoftView * pview=(CFspSoftView *) lParam;
char szElapsedTime[10] = "";
DWORD time_elapsed=0;
while (time_count_flag)
{
time_stop =GetTickCount();
time_elapsed=(time_stop - time_start);///1000;(float)
time_elapsed%=3600000;
sprintf(szElapsedTime,"%d:%d:%d",time_elapsed/3600000,time_elapsed/60000,time_elapsed/1000);
pview->SetDlgItemText(IDC_STATIC_TIME, szElapsedTime);
Sleep(50);
}
return 0;
}
DWORD WINAPI ThreadTest( LPVOID lparam)
{
CFspSoftView *pview = (CFspSoftView *)lparam;
pview->OnTest();
time_count_flag=0;
return 0;
}
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFspSoftView
IMPLEMENT_DYNCREATE(CFspSoftView, CFormView)
BEGIN_MESSAGE_MAP(CFspSoftView, CFormView)
//{{AFX_MSG_MAP(CFspSoftView)
ON_BN_CLICKED(IDC_BUTTON3, SendMessage)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON1, OnRead)
ON_WM_CREATE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFspSoftView construction/destruction
CFspSoftView::CFspSoftView()
: CFormView(CFspSoftView::IDD)
{
//{{AFX_DATA_INIT(CFspSoftView)
m_SendMessage = _T("");
m_dwel= 0.0;
m_Number = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CFspSoftView::~CFspSoftView()
{
}
void CFspSoftView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFspSoftView)
DDX_Control(pDX, IDC_RICHEDIT1, m_edit);
DDX_Text(pDX, IDC_EDIT7, m_SendMessage);
DDX_Text(pDX, IDC_EDIT1, m_Number);
//}}AFX_DATA_MAP
}
void CFspSoftView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CFspSoftView printing
/////////////////////////////////////////////////////////////////////////////
// CFspSoftView diagnostics
#ifdef _DEBUG
void CFspSoftView::AssertValid() const
{
CFormView::AssertValid();
}
void CFspSoftView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CFspSoftDoc* CFspSoftView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFspSoftDoc)));
return (CFspSoftDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFspSoftView message handlers
void CFspSoftView::SendMessage()
{
UpdateData(TRUE);
m_fsp13.Write(m_SendMessage);
OutPut("Command:");
OutPut(m_SendMessage,CLR_BLUE);
OutPut("\r\n");
}
void CFspSoftView::OnButton4()
{
BOOL bsum=TRUE;
BOOL bfsp=TRUE;
m_sum200.SweepOn(FALSE);
/////////////visa初始化////////////////////////////////////////////////
OnReadini("SUM","portsum",m_portsum,this);
OnReadini("SUM","addrsum",m_addrsum,this);
OnReadini("FSP","portfsp",m_portfsp,this);
OnReadini("FSP","addrfsp",m_addrfsp,this);
OutPut("初始化visa.....\r\n",CLR_BLACK);
if (!m_sum200.OpenGpib(int(m_portsum),int(m_addrsum)))
{
OutPut("信号源初始化失败! \r\n",CLR_RED);
// bsum=FALSE;
}
else
{
OutPut("信号源初始化成功! \r\n",CLR_BLACK);
}
Sleep(2000);
if (!m_fsp13.OpenGpib(int(m_portfsp),int(m_addrfsp)))
{
OutPut("频谱仪初始化失败! \r\n",CLR_RED);
// bfsp=FALSE;
}
else
{
OutPut("频谱仪初始化成功! \r\n",CLR_BLACK);
}
Sleep(2000);
m_fsp13.SetTimeout(10000);
bsysinit=bsum&&bfsp;
}
void CFspSoftView::OnButton5()
{
if (!bsysinit)
{
AfxMessageBox("未初始化,或初始化不成功!");
}
else
{
time_start=GetTickCount();
time_stop=GetTickCount();
time_count_flag =1 ;
hthreadtest=CreateThread(NULL,0,ThreadTest,this,0,NULL);
hthreadtime=CreateThread(NULL,0,Thread_Timecounting,this,0,NULL);
}
}
void CFspSoftView::OnTest()
{
GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON5)->EnableWindow(FALSE);
OutPut("*********测试开始**************\r\n");
double dvalueX,dvalueY,m_result,m_Time;
m_sum200.OUTPUT(TRUE);
m_sum200.SweepOn(TRUE);
OnReadini("FSP","time",m_Time,this);
OnReadini("SUM","Result",m_result,this);
for (int i=0;i< 150;i++)
{
dvalueX=m_fsp13.GetMarkPeakX();
dvalueY=m_fsp13.GetMarkPeakY();
Sleep((int)m_Time);
tempstr.Format("%d: %.2f mHz的最大值 =%.2f \r\n",i+1,dvalueX/1000000,dvalueY);
if (fabs(m_result)<fabs(dvalueY))
{
OutPut(tempstr,CLR_BLACK);
}
else
{
OutPut(tempstr,CLR_RED);
break;
}
}
OutPut("*********测试结束**************\r\n");
m_sum200.SweepOn(FALSE);
m_sum200.OUTPUT(FALSE);
GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON4)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON5)->EnableWindow(TRUE);
}
void CFspSoftView::OutPut(CString Str,COLORREF cColor)
{
int nLength = m_edit.GetWindowTextLength();
m_edit.SetSel(nLength,nLength);
int numstr;
numstr=Strlong-Str.GetLength();
CHARFORMAT cf;
ZeroMemory(&cf, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |
CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
cf.dwEffects = 0;
// cf.yHeight = 15*15;//文字高度
cf.crTextColor = cColor; //文字颜色
// strcpy(cf.szFaceName ,_T("隶书"));//设置字体
m_edit.SetSel(Strlong,Strlong+Str.GetLength()); //设置处理区域
m_edit.SetSelectionCharFormat(cf);
m_edit.ReplaceSel(Str);
Strlong=Strlong+Str.GetLength();
}
void CFspSoftView::OnRead()
{
CString temp;
temp.Format("Peak Y值==%.3f \r\n",m_fsp13.GetMarkPeakY());
m_edit.ReplaceSel(temp);
temp.Format("Peak X值==%.3f \r\n",m_fsp13.GetMarkPeakX());
m_edit.ReplaceSel(temp);
}
double CFspSoftView::Comparemax(double *p,int length,double m_stand)
{
// m_stand=m_dResult;
double maxvalue = p[0];
CString csvalue,csinfo;
for (int j1 = 0;j1 < length;j1++)
{
if (maxvalue < p[j1])
{
maxvalue = p[j1];
}
else
{
continue;
}
}
/* if (maxvalue > m_stand)
{
csvalue.Format("错误%.3f\r\n",maxvalue);
OutPut(csvalue,CLR_BLACK);
}
else
{
csvalue.Format("正确%.3f\r\n",maxvalue);
OutPut(csvalue,CLR_BLACK);
}
*/ csvalue.Format("最大值==%.3f\r\n",maxvalue);
OutPut(csvalue,CLR_BLACK);
return maxvalue;
}
void CFspSoftView::OnSetExcel()
{
UpdateData (TRUE);
CString csSource;
if (""==m_Number)
{
AfxMessageBox("请输入序列号!");
}
else
{
CFileDialog Open(TRUE,"*.bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Excel Files (*.xls)|*.xls|All Files (*.*)|*.*||",
NULL);
if(Open.DoModal()==IDOK)
{
csSource=Open.GetPathName();
// csFile=Open.GetFileName();//文件名
}
m_csExcel=csSource;
int csindex=m_csExcel.ReverseFind('\\');
m_csExcel=m_csExcel.Left(csindex+1);
//////////////////////////////////////////////////////////////////////////
if (m_csExcel.Right(1) != "\\")
m_csExcel += "\\";
m_csExcel += m_Number;
m_csExcel += ".xls";
OutPut("csSource:",CLR_BLACK);
OutPut(csSource,CLR_BLACK);
OutPut("\r\nm_csExcel:",CLR_BLACK);
OutPut(m_csExcel,CLR_BLACK);
if (!::CopyFile(csSource, m_csExcel, FALSE))
{
OutPut("创建测试记录文件失败!\r\n",CLR_RED);
}
else
{
OutPut("创建测试记录文件完成!\r\n",CLR_BLACK);
}
}
//表格设置
m_AddressExel.Format("d:\\Test\\%s.xls",m_Number);
}
double CFspSoftView::ReadData(short icolumn, long irow, CString &csResult,CFspSoftView *lpUnit)
{
CSpreadSheet SS(lpUnit->m_AddressExel, "Set", false);
SS.ReadCell(csResult, icolumn, irow);
double x=(double)atof(csResult);
return x;
}
void CFspSoftView::WriteData(short icolumn, long irow, CString csResult,CFspSoftView *lpUnit)
{
CSpreadSheet SS(lpUnit->m_AddressExel, "Report");
SS.BeginTransaction();
SS.AddCell(csResult, icolumn, irow);
SS.Commit();
}
void CFspSoftView::AddRow(CString csResult,CString csResult2,CFspSoftView *lpUnit)
{
CSpreadSheet SS(lpUnit->m_AddressExel, "Report");
CStringArray sampleArray, testRow;
for(int i = 0; i < sizeof(strName)/sizeof(CString); i++)
{
sampleArray.RemoveAll();
sampleArray.Add(m_Number);
sampleArray.Add(csResult);
sampleArray.Add(csResult2);
SS.AddRow(sampleArray);
}
SS.AddRow(testRow); // 添加到尾部
}
void CFspSoftView::OnReadini(CString strSection,CString strSectionKey,double &strValue,CFspSoftView *lpUnit)
{
// char appPath[256];
// GetCurrentDirectory(256,appPath); //取得应用程序当前路径
CString FilePath;
// FilePath.Format("%s",appPath);
// strValue = _T("");
char inBuf[256];
FilePath=".\\Set.ini";
// strSection = "SetIL";
// strSectionKey ="m_TXIL924";
GetPrivateProfileString (strSection,strSectionKey, NULL, inBuf, 80, FilePath);
strValue=atof(inBuf);
// appPath=inBuf;
/*
lpUnit->OutPut(strSectionKey);
lpUnit->OutPut(" = ");
lpUnit->OutPut(inBuf);
lpUnit->OutPut("\r\n");
*/
}
void CFspSoftView::OnSaveini(CString strSection,CString strSectionKey,double bValue,CFspSoftView *lpUnit)
{
char appPath[256];
GetCurrentDirectory(256,appPath);
CString FilePath;
FilePath.Format("%s",appPath);
FilePath=".\\Set.ini";
CString strValue;
strValue.Format("%.3f",bValue);
WritePrivateProfileString (strSection,strSectionKey,strValue, FilePath);
}
BOOL CFspSoftView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
return CFormView::PreCreateWindow(cs);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -