📄 setsystem.cpp
字号:
// SetSystem.cpp : implementation file
//
#include "stdafx.h"
#include "SHT11Transmit.h"
#include "SetSystem.h"
#include "SHT11TransmitDlg.h"
#include "PCOMM.H"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// SetSystem property page
IMPLEMENT_DYNCREATE(SetSystem, CPropertyPage)
SetSystem::SetSystem() : CPropertyPage(SetSystem::IDD)
{
//{{AFX_DATA_INIT(SetSystem)
m_Zero_temperature = 0.0f;
m_Zero_humidity = 0.0;
m_Mini_temperature = 0.0;
m_Max_temperature = 0.0f;
m_Mini_humidity = 0.0;
m_Max_humidity = 0.0;
//}}AFX_DATA_INIT
}
SetSystem::~SetSystem()
{
}
void SetSystem::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(SetSystem)
DDX_Control(pDX, IDC_COMBO2, m_CurrentTypeRH);
DDX_Control(pDX, IDC_COMBO1, m_CurrentTypeTC);
DDX_Text(pDX, IDC_EDIT3, m_Zero_temperature);
DDX_Text(pDX, IDC_EDIT4, m_Zero_humidity);
DDX_Text(pDX, IDC_EDIT5, m_Mini_temperature);
DDV_MinMaxFloat(pDX, m_Mini_temperature, -40.f, 120.f);
DDX_Text(pDX, IDC_EDIT7, m_Max_temperature);
DDV_MinMaxFloat(pDX, m_Max_temperature, -40.f, 120.f);
DDX_Text(pDX, IDC_EDIT6, m_Mini_humidity);
DDV_MinMaxFloat(pDX, m_Mini_humidity, 0.f, 100.f);
DDX_Text(pDX, IDC_EDIT8, m_Max_humidity);
DDV_MinMaxFloat(pDX, m_Max_humidity, 0.f, 100.f);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(SetSystem, CPropertyPage)
//{{AFX_MSG_MAP(SetSystem)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON3, OnStorData)
ON_BN_CLICKED(IDC_BUTTON4, OnReadStorData)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// SetSystem message handlers
BOOL SetSystem::OnInitDialog()
{
CPropertyPage::OnInitDialog();
m_CurrentTypeTC.AddString(_T("4~20mA"));
m_CurrentTypeTC.AddString(_T("20~4mA"));
m_CurrentTypeTC.SetCurSel(0);
m_CurrentTypeRH.AddString(_T("4~20mA"));
m_CurrentTypeRH.AddString(_T("20~4mA"));
m_CurrentTypeRH.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void SetSystem::OnButton1()
{
// TODO: Add your control notification handler code here
port = SetCommData.port;
//if(port != SIO_OK)
if(SetCommData.ret_open != SIO_OK)
{
AfxMessageBox("串口没有打开,请打开串口");
return;
}
else
{
sio_flush(SetCommData.port,2); //清空输入输出缓冲区
SetCommData.TxBuff[0] = (char)0xFF;
SetCommData.TxBuff[1] = (char)0x03;
SetCommData.TxBuff[2] = (char)0x02;
SetCommData.TxBuff[3] = (char)0x55;
SetCommData.TxBuff[4] = (char)0x05;
SetCommData.TxBuff[5] = (char)0x04;
SetCommData.TxBuff[6] = (char)0xFE;
SetCommData.TxBuff[7] = (char)0xFD;
sio_write(SetCommData.port,SetCommData.TxBuff,8); //把输出缓冲区中的数据发送出去
}
SetTimer(3,100,NULL);
}
void SetSystem::OnButton2()
{
// TODO: Add your control notification handler code here
int TCType,RHType;
float SendTCType,SendRHType;
UpdateData();
TCType = m_CurrentTypeTC.GetCurSel();
RHType = m_CurrentTypeRH.GetCurSel();
if(TCType == 0)
{
SendTCType = 4.0f;
}
else
{
SendTCType = 20.0f;
}
if(RHType == 0)
{
SendRHType = 4.0f;
}
else
{
SendRHType = 20.0f;
}
// port = SetCommData.ret_open;
if(SetCommData.ret_open != SIO_OK)
{
AfxMessageBox("串口没有打开,请打开串口");
return;
}
else
{
sio_flush(SetCommData.port,2); //清空输入输出缓冲区
char TX_check;
int Num,i;
Num = 0;
SetCommData.TxBuff[Num++] = (char)0xFF;
SetCommData.TxBuff[Num++] = (char)0x03;
SetCommData.TxBuff[Num++] = (char)0x02;
SetCommData.TxBuff[Num++] = (char)0xAA;
SetCommData.TxBuff[Num++] = (char)0x01;
//对输入的数据进行判断
if((m_Max_temperature > m_Mini_temperature) && (m_Max_temperature <= 120.0) && (m_Mini_temperature >= -40.0))
{
TX0.fl = m_Mini_temperature;
SendFloatV(Num);
TX0.fl = m_Max_temperature;
Num +=4;
SendFloatV(Num);
}
else
{
AfxMessageBox("输入的温度数据不正确,请重新输入");
return;
}
if((m_Max_humidity > m_Mini_humidity) && (m_Max_humidity <= 100.0) && (m_Mini_humidity >= 0.0))
{
TX0.fl = m_Mini_humidity;
Num +=4;
SendFloatV(Num);
TX0.fl = m_Max_humidity;
Num +=4;
SendFloatV(Num);
}
else
{
AfxMessageBox("输入的湿度数据不正确,请重新输入");
return;
}
if((m_Zero_temperature > -40.0) && (m_Zero_temperature <= 120.0) && (m_Zero_humidity >= 0.0)&& (m_Zero_humidity <= 100.0))
{
TX0.fl = m_Zero_temperature;
Num +=4;
SendFloatV(Num);
TX0.fl = m_Zero_humidity;
Num +=4;
SendFloatV(Num);
}
else
{
AfxMessageBox("输入的温湿度零点数据不正确,请重新输入");
return;
}
TX0.fl = SendTCType;
Num +=4;
SendFloatV(Num);
TX0.fl = SendRHType;
Num +=4;
SendFloatV(Num);
Num +=4;
TX_check = 0x00;
for(i = 1; i < Num; i++)
{
TX_check ^= SetCommData.TxBuff[i];
}
SetCommData.TxBuff[Num++] = (TX_check >>4) & 0x0F;
SetCommData.TxBuff[Num++] = TX_check & 0x0F;
SetCommData.TxBuff[Num++] = (char)0xFE;
SetCommData.TxBuff[Num++] = (char)0xFD;
sio_write(SetCommData.port,SetCommData.TxBuff,Num); //把输出缓冲区中的数据发送出去
}
}
void SetSystem::OnTimer(UINT nIDEvent)
{
if(DisPlaySysTemFlag == 1)
{
DisPlaySysTemFlag = 0;
CString str;
str.Empty();
str.Format("%8.3f",envionment_variables.Mini_temperature);
SetDlgItemText(IDC_EDIT5,str);
str.Empty();
str.Format("%8.3f",envionment_variables.Max_temperature);
SetDlgItemText(IDC_EDIT7,str);
str.Empty();
str.Format("%8.3f",envionment_variables.Mini_humidity);
SetDlgItemText(IDC_EDIT6,str);
str.Empty();
str.Format("%8.3f",envionment_variables.Max_humidity);
SetDlgItemText(IDC_EDIT8,str);
str.Empty();
str.Format("%8.3f",envionment_variables.Zero_temperature);
SetDlgItemText(IDC_EDIT3,str);
str.Empty();
str.Format("%8.3f",envionment_variables.Zero_humidity);
SetDlgItemText(IDC_EDIT4,str);
if(envionment_variables.TC_CurrentType == 4.0f)
{
m_CurrentTypeTC.SetCurSel(0);
}
else
{
m_CurrentTypeTC.SetCurSel(1);
}
if(envionment_variables.RH_CurrentType == 4.0f)
{
m_CurrentTypeRH.SetCurSel(0);
}
else
{
m_CurrentTypeRH.SetCurSel(1);
}
KillTimer(3);
}
CPropertyPage::OnTimer(nIDEvent);
}
void SetSystem::OnStorData()
{
// TODO: Add your control notification handler code here
int TCType,RHType;
float SendTCType,SendRHType;
UpdateData();
TCType = m_CurrentTypeTC.GetCurSel();
RHType = m_CurrentTypeRH.GetCurSel();
if(TCType == 0)
{
SendTCType = 4.0f;
}
else
{
SendTCType = 20.0f;
}
if(RHType == 0)
{
SendRHType = 4.0f;
}
else
{
SendRHType = 20.0f;
}
// port = SetCommData.ret_open;
if(SetCommData.ret_open != SIO_OK)
{
AfxMessageBox("串口没有打开,请打开串口");
return;
}
else
{
sio_flush(SetCommData.port,2); //清空输入输出缓冲区
char TX_check;
int Num,i;
Num = 0;
SetCommData.TxBuff[Num++] = (char)0xFF;
SetCommData.TxBuff[Num++] = (char)0x03;
SetCommData.TxBuff[Num++] = (char)0x03;
SetCommData.TxBuff[Num++] = (char)0xAA;
SetCommData.TxBuff[Num++] = (char)0x01;
TX0.fl = m_Mini_temperature;
SendFloatV(Num);
TX0.fl = m_Max_temperature;
Num +=4;
SendFloatV(Num);
TX0.fl = m_Mini_humidity;
Num +=4;
SendFloatV(Num);
TX0.fl = m_Max_humidity;
Num +=4;
SendFloatV(Num);
TX0.fl = m_Zero_temperature;
Num +=4;
SendFloatV(Num);
TX0.fl = m_Zero_humidity;
Num +=4;
SendFloatV(Num);
TX0.fl = SendTCType;
Num +=4;
SendFloatV(Num);
TX0.fl = SendRHType;
Num +=4;
SendFloatV(Num);
Num +=4;
TX_check = 0x00;
for(i = 1; i < Num; i++)
{
TX_check ^= SetCommData.TxBuff[i];
}
SetCommData.TxBuff[Num++] = (TX_check >>4) & 0x0F;
SetCommData.TxBuff[Num++] = TX_check & 0x0F;
SetCommData.TxBuff[Num++] = (char)0xFE;
SetCommData.TxBuff[Num++] = (char)0xFD;
sio_write(SetCommData.port,SetCommData.TxBuff,Num); //把输出缓冲区中的数据发送出去
}
}
void SetSystem::OnReadStorData()
{
port = SetCommData.port;
//if(port != SIO_OK)
if(SetCommData.ret_open != SIO_OK)
{
AfxMessageBox("串口没有打开,请打开串口");
return;
}
else
{
sio_flush(SetCommData.port,2); //清空输入输出缓冲区
SetCommData.TxBuff[0] = (char)0xFF;
SetCommData.TxBuff[1] = (char)0x03;
SetCommData.TxBuff[2] = (char)0x03;
SetCommData.TxBuff[3] = (char)0x55;
SetCommData.TxBuff[4] = (char)0x05;
SetCommData.TxBuff[5] = (char)0x05;
SetCommData.TxBuff[6] = (char)0xFE;
SetCommData.TxBuff[7] = (char)0xFD;
sio_write(SetCommData.port,SetCommData.TxBuff,8); //把输出缓冲区中的数据发送出去
}
SetTimer(3,100,NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -