📄 verifyammterview.cpp
字号:
// VerifyAmmterView.cpp : implementation of the CVerifyAmmterView class
//
#include "stdafx.h"
#include "VerifyAmmter.h"
#include "math.h"
#include "Dialog2.h"
#include "VerifyAmmterSet.h"
#include "VerifyAmmterDoc.h"
#include "VerifyAmmterView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVerifyAmmterView
IMPLEMENT_DYNCREATE(CVerifyAmmterView, CRecordView)
BEGIN_MESSAGE_MAP(CVerifyAmmterView, CRecordView)
//{{AFX_MSG_MAP(CVerifyAmmterView)
ON_CBN_CLOSEUP(IDC_LIST1_POWER, OnCloseupList1Power)
ON_CBN_CLOSEUP(IDC_LIST1_PHASE, OnCloseupList1Phase)
ON_CBN_CLOSEUP(IDC_LIST1_CURRENT, OnCloseupList1Current)
ON_BN_CLICKED(IDC_POWER1_VERIFY_BUTTON, OnPower1VerifyButton)
ON_BN_CLICKED(IDC_PHASE1_VERIFY_BUTTON, OnPhase1VerifyButton)
ON_BN_CLICKED(IDC_VOLTAGE1_VERIFY_BUTTON, OnVoltage1VerifyButton)
ON_BN_CLICKED(IDC_CURRENT1_VERIFY_BUTTON, OnCurrent1VerifyButton)
ON_BN_CLICKED(IDC_POWER1_MAN_BUTTON, OnPower1ManButton)
ON_BN_CLICKED(IDC_PHASE1_MAN_BUTTON, OnPhase1ManButton)
ON_BN_CLICKED(IDC_VOLATGE1_MAN_BUTTON, OnVolatge1ManButton)
ON_BN_CLICKED(IDC_CURRENT1_MAN_BUTTON, OnCurrent1ManButton)
ON_BN_CLICKED(IDC_VOLTAGE1_TRAN_BUTTON, OnVoltage1TranButton)
ON_BN_CLICKED(IDC_CURRENT1_TRAN_BUTTON, OnCurrent1TranButton)
ON_BN_CLICKED(IDC_VERIFY_BUTTON1, OnVerifyButton1)
ON_BN_CLICKED(IDC_ADD_BUTTON1, OnAddButton1)
ON_CBN_CLOSEUP(IDC_LIST2_PHASE, OnCloseupList2Phase)
ON_CBN_CLOSEUP(IDC_LIST2_POWER, OnCloseupList2Power)
ON_CBN_CLOSEUP(IDC_LIST2_CURRENT, OnCloseupList2Current)
ON_BN_CLICKED(IDC_POWER2_VERIFY_BUTTON, OnPower2VerifyButton)
ON_BN_CLICKED(IDC_PHASE2_VERIFY_BUTTON, OnPhase2VerifyButton)
ON_BN_CLICKED(IDC_VOLTAGE2_VERIFY_BUTTON, OnVoltage2VerifyButton)
ON_BN_CLICKED(IDC_CURRENT2_VERIFY_BUTTON, OnCurrent2VerifyButton)
ON_BN_CLICKED(IDC_POWER2_MAN_BUTTON, OnPower2ManButton)
ON_BN_CLICKED(IDC_PHASE2_MAN_BUTTON, OnPhase2ManButton)
ON_BN_CLICKED(IDC_VOLATGE2_MAN_BUTTON, OnVolatge2ManButton)
ON_BN_CLICKED(IDC_CURRENT2_MAN_BUTTON, OnCurrent2ManButton)
ON_BN_CLICKED(IDC_VOLTAGE2_TRAN_BUTTON, OnVoltage2TranButton)
ON_BN_CLICKED(IDC_CURRENT2_TRAN_BUTTON, OnCurrent2TranButton)
ON_BN_CLICKED(IDC_VERIFY_BUTTON2, OnVerifyButton2)
ON_BN_CLICKED(IDC_ADD_BUTTON2, OnAddButton2)
ON_CBN_CLOSEUP(IDC_LIST3_POWER, OnCloseupList3Power)
ON_CBN_CLOSEUP(IDC_LIST3_PHASE, OnCloseupList3Phase)
ON_CBN_CLOSEUP(IDC_LIST3_CURRENT, OnCloseupList3Current)
ON_BN_CLICKED(IDC_POWER3_VERIFY_BUTTON, OnPower3VerifyButton)
ON_BN_CLICKED(IDC_PHASE3_VERIFY_BUTTON, OnPhase3VerifyButton)
ON_BN_CLICKED(IDC_VOLTAGE3_VERIFY_BUTTON, OnVoltage3VerifyButton)
ON_BN_CLICKED(IDC_CURRENT4_VERIFY_BUTTON, OnCurrent4VerifyButton)
ON_BN_CLICKED(IDC_POWER3_MAN_BUTTON, OnPower3ManButton)
ON_BN_CLICKED(IDC_PHASE3_MAN_BUTTON, OnPhase3ManButton)
ON_BN_CLICKED(IDC_VOLATGE3_MAN_BUTTON, OnVolatge3ManButton)
ON_BN_CLICKED(IDC_CURRENT3_MAN_BUTTON, OnCurrent3ManButton)
ON_BN_CLICKED(IDC_VOLTAGE3_TRAN_BUTTON, OnVoltage3TranButton)
ON_BN_CLICKED(IDC_CURRENT3_TRAN_BUTTON, OnCurrent3TranButton)
ON_BN_CLICKED(IDC_VERIFY_BUTTON3, OnVerifyButton3)
ON_BN_CLICKED(IDC_ADD_BUTTON3, OnAddButton3)
ON_CBN_CLOSEUP(IDC_LIST4_POWER, OnCloseupList4Power)
ON_CBN_CLOSEUP(IDC_LIST4_PHASE, OnCloseupList4Phase)
ON_CBN_CLOSEUP(IDC_LIST4_CURRENT, OnCloseupList4Current)
ON_BN_CLICKED(IDC_POWER4_VERIFY_BUTTON, OnPower4VerifyButton)
ON_BN_CLICKED(IDC_PHASE4_VERIFY_BUTTON, OnPhase4VerifyButton)
ON_BN_CLICKED(IDC_VOLTAGE4_VERIFY_BUTTON, OnVoltage4VerifyButton)
ON_BN_CLICKED(IDC_CURRENT3_VERIFY_BUTTON, OnCurrent3VerifyButton)
ON_BN_CLICKED(IDC_POWER4_MAN_BUTTON, OnPower4ManButton)
ON_BN_CLICKED(IDC_PHASE4_MAN_BUTTON, OnPhase4ManButton)
ON_BN_CLICKED(IDC_VOLATGE4_MAN_BUTTON, OnVolatge4ManButton)
ON_BN_CLICKED(IDC_CURRENT4_MAN_BUTTON, OnCurrent4ManButton)
ON_BN_CLICKED(IDC_VOLTAGE4_TRAN_BUTTON, OnVoltage4TranButton)
ON_BN_CLICKED(IDC_CURRENT4_TRAN_BUTTON, OnCurrent4TranButton)
ON_BN_CLICKED(IDC_VERIFY_BUTTON4, OnVerifyButton4)
ON_BN_CLICKED(IDC_ADD_BUTTON4, OnAddButton4)
ON_BN_CLICKED(IDC_NUMBER_BUTTON1, OnNumberButton1)
ON_BN_CLICKED(IDC_NUMBER_BUTTON2, OnNumberButton2)
ON_BN_CLICKED(IDC_NUMBER_BUTTON3, OnNumberButton3)
ON_BN_CLICKED(IDC_NUMBER_BUTTON4, OnNumberButton4)
ON_CBN_CLOSEUP(IDC_LIST1_VOLTAGE, OnCloseupList1Voltage)
ON_CBN_CLOSEUP(IDC_LIST2_VOLTAGE, OnCloseupList2Voltage)
ON_CBN_CLOSEUP(IDC_LIST3_VOLTAGE, OnCloseupList3Voltage)
ON_CBN_CLOSEUP(IDC_LIST4_VOLTAGE, OnCloseupList4Voltage)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVerifyAmmterView construction/destruction
CVerifyAmmterView::CVerifyAmmterView()
: CRecordView(CVerifyAmmterView::IDD)
{
//{{AFX_DATA_INIT(CVerifyAmmterView)
m_pSet = NULL;
m_power = _T("");
m_phase = _T("");
m_error1 = 0.0;
m_error2 = 0.0;
m_current = _T("");
m_transfer2 = _T("");
m_voltage = _T("");
m_transfer1 = _T("");
m_number1 = _T("");
m_power2 = _T("");
m_phase2 = _T("");
m_error22 = 0.0;
m_transfer21 = _T("");
m_voltage2 = _T("");
m_transfer22 = _T("");
m_current2 = _T("");
m_power3 = _T("");
m_power4 = _T("");
m_phase3 = _T("");
m_phase4 = _T("");
m_error21 = 0.0;
m_error31 = 0.0;
m_error41 = 0.0;
m_error32 = 0.0;
m_error42 = 0.0;
m_voltage3 = _T("");
m_voltage4 = _T("");
m_current3 = _T("");
m_transfer32 = _T("");
m_current4 = _T("");
m_transfer42 = _T("");
m_transfer31 = _T("");
m_transfer41 = _T("");
m_number2 = _T("");
m_number3 = _T("");
m_number4 = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CVerifyAmmterView::~CVerifyAmmterView()
{
}
void CVerifyAmmterView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVerifyAmmterView)
DDX_Control(pDX, IDC_LIST4_VOLTAGE, m_list44);
DDX_Control(pDX, IDC_LIST3_VOLTAGE, m_list34);
DDX_Control(pDX, IDC_LIST2_VOLTAGE, m_list24);
DDX_Control(pDX, IDC_LIST1_VOLTAGE, m_list4);
DDX_Control(pDX, IDC_LIST4_POWER, m_list41);
DDX_Control(pDX, IDC_LIST4_PHASE, m_list42);
DDX_Control(pDX, IDC_LIST4_CURRENT, m_list43);
DDX_Control(pDX, IDC_LIST3_POWER, m_list31);
DDX_Control(pDX, IDC_LIST3_PHASE, m_list32);
DDX_Control(pDX, IDC_LIST3_CURRENT, m_list33);
DDX_Control(pDX, IDC_LIST2_POWER, m_list21);
DDX_Control(pDX, IDC_LIST2_PHASE, m_list22);
DDX_Control(pDX, IDC_LIST2_CURRENT, m_list23);
DDX_Control(pDX, IDC_LIST1_CURRENT, m_list3);
DDX_Control(pDX, IDC_LIST1_PHASE, m_list2);
DDX_Control(pDX, IDC_LIST1_POWER, m_list1);
DDX_Control(pDX, IDC_MSCOMM1, m_ctrlcomm);
DDX_Text(pDX, IDC_POWER1_VERIFY, m_power);
DDX_Text(pDX, IDC_PHASE1_VERIFY, m_phase);
DDX_Text(pDX, IDC_POWER1_ERROR, m_error1);
DDX_Text(pDX, IDC_PHASE1_ERROR, m_error2);
DDX_Text(pDX, IDC_CURRENT1_TRANS, m_current);
DDX_Text(pDX, IDC_CURRENT1_VERIFY, m_transfer2);
DDX_Text(pDX, IDC_VOLTAGE1_TRANS, m_voltage);
DDX_Text(pDX, IDC_VOLTAGE1_VERIFY, m_transfer1);
DDX_Text(pDX, IDC_FORM_NUM_EDIT, m_number1);
DDX_Text(pDX, IDC_POWER2_VERIFY, m_power2);
DDX_Text(pDX, IDC_PHASE2_VERIFY, m_phase2);
DDX_Text(pDX, IDC_PHASE2_ERROR, m_error22);
DDX_Text(pDX, IDC_VOLTAGE2_VERIFY, m_transfer21);
DDX_Text(pDX, IDC_VOLTAGE2_TRANS, m_voltage2);
DDX_Text(pDX, IDC_CURRENT2_VERIFY, m_transfer22);
DDX_Text(pDX, IDC_CURRENT2_TRANS, m_current2);
DDX_Text(pDX, IDC_POWER3_VERIFY, m_power3);
DDX_Text(pDX, IDC_POWER4_VERIFY, m_power4);
DDX_Text(pDX, IDC_PHASE3_VERIFY, m_phase3);
DDX_Text(pDX, IDC_PHASE4_VERIFY, m_phase4);
DDX_Text(pDX, IDC_POWER2_ERROR, m_error21);
DDX_Text(pDX, IDC_POWER3_ERROR, m_error31);
DDX_Text(pDX, IDC_POWER4_ERROR, m_error41);
DDX_Text(pDX, IDC_PHASE3_ERROR, m_error32);
DDX_Text(pDX, IDC_PHASE4_ERROR, m_error42);
DDX_Text(pDX, IDC_VOLTAGE3_TRANS, m_voltage3);
DDX_Text(pDX, IDC_VOLTAGE4_TRANS, m_voltage4);
DDX_Text(pDX, IDC_CURRENT3_TRANS, m_current3);
DDX_Text(pDX, IDC_CURRENT3_VERIFY, m_transfer32);
DDX_Text(pDX, IDC_CURRENT4_TRANS, m_current4);
DDX_Text(pDX, IDC_CURRENT4_VERIFY, m_transfer42);
DDX_Text(pDX, IDC_VOLTAGE3_VERIFY, m_transfer31);
DDX_Text(pDX, IDC_VOLTAGE4_VERIFY, m_transfer41);
DDX_Text(pDX, IDC_FORM_NUM_EDIT2, m_number2);
DDX_Text(pDX, IDC_FORM_NUM_EDIT3, m_number3);
DDX_Text(pDX, IDC_FORM_NUM_EDIT4, m_number4);
//}}AFX_DATA_MAP
}
BOOL CVerifyAmmterView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CVerifyAmmterView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_verifyAmmterSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
CString str;
for(int i=0;i<=5;i++){
str.Format("%d",i+1);
m_list1.AddString(str);
m_list2.AddString(str);
m_list3.AddString(str);
m_list4.AddString(str);
m_list21.AddString(str);
m_list22.AddString(str);
m_list23.AddString(str);
m_list24.AddString(str);
m_list31.AddString(str);
m_list32.AddString(str);
m_list33.AddString(str);
m_list34.AddString(str);
m_list41.AddString(str);
m_list42.AddString(str);
m_list43.AddString(str);
m_list44.AddString(str);
}
m_list1.SetCurSel(0);
m_list2.SetCurSel(0);
m_list3.SetCurSel(0);
m_list4.SetCurSel(0);
m_list21.SetCurSel(0);
m_list22.SetCurSel(0);
m_list23.SetCurSel(0);
m_list24.SetCurSel(0);
m_list31.SetCurSel(0);
m_list32.SetCurSel(0);
m_list33.SetCurSel(0);
m_list34.SetCurSel(0);
m_list41.SetCurSel(0);
m_list42.SetCurSel(0);
m_list43.SetCurSel(0);
m_list44.SetCurSel(0);
for(i=0;i<=5;i++){
power[i]=0xffffff;
error_power[i]=0.99;
power2[i]=0xffffff;
error_power2[i]=0.99;
power2[i]=0xffffff;
error_power2[i]=0.99;
power2[i]=0xffffff;
error_power2[i]=0.99;
phase2[i]=0xffffff;
error_phase2[i]=0.99;
phase2[i]=0xffffff;
error_phase2[i]=0.99;
phase2[i]=0xffffff;
error_phase2[i]=0.99;
phase2[i]=0xffffff;
error_phase2[i]=0.99;
disp_voltage[i]=1.5;
disp_voltage2[i]=1.5;
disp_voltage3[i]=1.5;
disp_voltage4[i]=1.5;
disp_current[i]=1.5;
disp_current2[i]=1.5;
disp_current3[i]=1.5;
disp_current4[i]=1.5;
}
sel1=0; //初始化power
sel2=0;//phsase
sel3=0;//current
sel4=0;//voltage
// transfer1=0x2b00f1; //初始化上传电压数值
// transfer2=0x7c000;//初始化上传电流数值
int transfer=0xffffff;
m_power.Format("%.6x",(DWORD)power[0]);
m_phase.Format("%.6x",(DWORD)phase[0]);
m_transfer2.Format("%.6x",(DWORD)current[0]);
m_error1=error_power[0];
m_error2=error_phase[0];
// m_voltage=180;
// m_current=1.5;
m_transfer1.Format("%.6x",(DWORD)transfer);
UpdateData(FALSE);
m_ctrlcomm.SetCommPort(1);
m_ctrlcomm.SetInBufferSize(1024);
m_ctrlcomm.SetOutBufferSize(512);
m_ctrlcomm.SetSettings("300,n,8,1");
if(!m_ctrlcomm.GetPortOpen())
m_ctrlcomm.SetPortOpen(TRUE);
// AfxMessageBox("hellp");
m_ctrlcomm.SetRThreshold(1);
m_ctrlcomm.SetInputMode(1);
m_ctrlcomm.SetInputLen(0);
m_ctrlcomm.GetInput();
}
/////////////////////////////////////////////////////////////////////////////
// CVerifyAmmterView printing
BOOL CVerifyAmmterView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CVerifyAmmterView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CVerifyAmmterView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CVerifyAmmterView diagnostics
#ifdef _DEBUG
void CVerifyAmmterView::AssertValid() const
{
CRecordView::AssertValid();
}
void CVerifyAmmterView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CVerifyAmmterDoc* CVerifyAmmterView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVerifyAmmterDoc)));
return (CVerifyAmmterDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CVerifyAmmterView database support
CRecordset* CVerifyAmmterView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CVerifyAmmterView message handlers
BEGIN_EVENTSINK_MAP(CVerifyAmmterView, CRecordView)
//{{AFX_EVENTSINK_MAP(CVerifyAmmterView)
ON_EVENT(CVerifyAmmterView, IDC_MSCOMM1, 1 /* OnComm */, OnComm, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CVerifyAmmterView::OnComm()
{
// TODO: Add your control notification handler code here
DWORD aa;
VARIANT v_inp;
COleSafeArray sa_inp;
//AfxMessageBox("hello");
long len,k;
BYTE rxdata[32];
CString str,str1;
double pp,tt;
if(m_ctrlcomm.GetCommEvent() == 2){
v_inp = m_ctrlcomm.GetInput();
sa_inp = v_inp;
//AfxMessageBox("hello");
len = sa_inp.GetOneDimSize();
for(k=0;k<len;k++)
sa_inp.GetElement(&k,rxdata+k);
if(rxdata[0]==0xfe&&rxdata[1]==0xfe&&rxdata[2]==0x68&&rxdata[4]=='V'&&rxdata[9]==0x16)
{
aa=rxdata[6];
aa<<=8;
aa=aa|rxdata[7];
aa<<=8;
aa=aa|rxdata[8];
if(rxdata[3]==01){
sel4=rxdata[5]-1;
transfer1=aa;
pp=(double)transfer1/pow(2,13);
disp_voltage[sel4]=pp;
m_voltage.Format("%.2f",pp);
}
else if(rxdata[3]==02){
sel24=rxdata[5]-1;
transfer21=aa;
pp=(double)transfer21/pow(2,13);
disp_voltage2[sel24]=pp;
m_voltage2.Format("%.2f",pp);
}
else if(rxdata[3]==03){
sel34=rxdata[5]-1;
transfer31=aa;
pp=(double)transfer31/pow(2,13);
disp_voltage3[sel34]=pp;
m_voltage3.Format("%.2f",pp);
}
else if(rxdata[3]==04){
sel44=rxdata[5]-1;
transfer41=aa;
pp=(double)transfer41/pow(2,13);
disp_voltage4[sel44]=pp;
m_voltage4.Format("%.2f",pp);
}
CString tr;
tr.Format("%.2f",pp);
AfxMessageBox(tr);
UpdateData(FALSE);
}
else if(rxdata[0]==0xfe&&rxdata[1]==0xfe&&rxdata[2]==0x68&&rxdata[4]=='C'&&rxdata[9]==0x16){
aa=rxdata[6];
aa<<=8;
aa=aa|rxdata[7];
aa<<=8;
aa=aa|rxdata[8];
if(rxdata[3]==01){
sel3=rxdata[5]-1;
transfer2=aa;
tt=(double)transfer2/pow(2,13);
disp_current[sel3]=tt;
m_current.Format("%.2f",tt);
}
else if(rxdata[3]==02){
sel23=rxdata[5]-1;
transfer22=aa;
tt=(double)transfer22/pow(2,13);
disp_current2[sel23]=tt;
m_current2.Format("%.2f",tt);
}
else if(rxdata[3]==03){
sel33=rxdata[5]-1;
transfer32=aa;
tt=(double)transfer32/pow(2,13);
disp_current3[sel33]=tt;
m_current3.Format("%.2f",tt);
}
else if(rxdata[3]==04){
sel43=rxdata[5]-1;
transfer42=aa;
tt=(double)transfer42/pow(2,13);
disp_current4[sel43]=tt;
m_current4.Format("%.2f",tt);
}
// CString tr;
// tr.Format("%.2f",pp);
// AfxMessageBox(tr);
UpdateData(FALSE);
}
else {
AfxMessageBox("数据错误");
BYTE SendBuffer3[50];
BYTE cs=0;
SendBuffer3[0]=0xfe;
SendBuffer3[1]=0xfe;
SendBuffer3[2]=0x68;
SendBuffer3[3]='L';
SendBuffer3[4]='o';
SendBuffer3[5]='a';
SendBuffer3[6]='d';
SendBuffer3[7]='V';
SendBuffer3[9]=0x16;
for(int k=2;k<8;k++){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -