📄 sad8pcdlg.cpp
字号:
// SAD8PCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SAD8PC.h"
#include "SAD8PCDlg.h"
#include "datastruct.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern char *outsck_def[];
extern char *combps_set[];
extern char *com_mode[];
extern char *buchang_set[];
extern char *modaddr[];
extern char *comstr[];
extern char *rs485sendmode[];
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CSAD8PCDlg dialog
CSAD8PCDlg::CSAD8PCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSAD8PCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSAD8PCDlg)
m_csaddr = _T("");
m_cscombps = _T("");
m_cscomno = _T("1");
m_csoutsck = _T("");
m_csthermbuchang = _T("");
m_therm1 = _T("");
m_therm2 = _T("");
m_therm3 = _T("");
m_therm4 = _T("");
m_therm5 = _T("");
m_therm6 = _T("");
m_therm7 = _T("");
m_therm8 = _T("");
m_csrs485sendmode = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSAD8PCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSAD8PCDlg)
DDX_Control(pDX, IDC_RS485SENDMODE, m_cbrs485sendmode);
DDX_Control(pDX, IDC_THERMBUCHANG, m_cbthermbuchang);
DDX_Control(pDX, IDC_OUTSCK, m_cboutsck);
DDX_Control(pDX, IDC_COMNO, m_cbcomno);
DDX_Control(pDX, IDC_COMBPS, m_cbcombps);
DDX_Control(pDX, IDC_ADDR, m_cbaddr);
DDX_CBString(pDX, IDC_ADDR, m_csaddr);
DDX_CBString(pDX, IDC_COMBPS, m_cscombps);
DDX_CBString(pDX, IDC_COMNO, m_cscomno);
DDX_CBString(pDX, IDC_OUTSCK, m_csoutsck);
DDX_CBString(pDX, IDC_THERMBUCHANG, m_csthermbuchang);
DDX_Text(pDX, IDC_THERM1, m_therm1);
DDX_Text(pDX, IDC_THERM2, m_therm2);
DDX_Text(pDX, IDC_THERM3, m_therm3);
DDX_Text(pDX, IDC_THERM4, m_therm4);
DDX_Text(pDX, IDC_THERM5, m_therm5);
DDX_Text(pDX, IDC_THERM6, m_therm6);
DDX_Text(pDX, IDC_THERM7, m_therm7);
DDX_Text(pDX, IDC_THERM8, m_therm8);
DDX_CBString(pDX, IDC_RS485SENDMODE, m_csrs485sendmode);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSAD8PCDlg, CDialog)
//{{AFX_MSG_MAP(CSAD8PCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_READBUF, OnReadbuf)
ON_BN_CLICKED(IDC_LOADDEFAULT, OnLoaddefault)
ON_BN_CLICKED(IDC_READTHERM, OnReadtherm)
ON_BN_CLICKED(IDC_WRITEBUF, OnWritebuf)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSAD8PCDlg message handlers
BOOL CSAD8PCDlg::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
{
int i;
i = iComboaddstr(&m_cboutsck, outsck_def, "NULL");
i = iComboaddstr(&m_cbcombps, combps_set, "NULL");
i = iComboaddstr(&m_cbthermbuchang, buchang_set, "NULL");
i = iComboaddstr(&m_cbcomno, comstr, "NULL");
i = iComboaddstr(&m_cbaddr, modaddr, "NULL");
i = iComboaddstr(&m_cbrs485sendmode, rs485sendmode, "NULL");
OnLoaddefault() ;
//i = iComboaddstr(&m_cmbModebus, com_mode, "NULL");
// i = iComboaddstr(&m_cmbCheckmode, modaddr, "NULL");
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CSAD8PCDlg::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 CSAD8PCDlg::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 CSAD8PCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSAD8PCDlg::OnReadbuf()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
sad8com.comno = getcomno();
if (FALSE == sad8com.iRead_Sad8())
{
AfxMessageBox(sad8com.errnostring);
return ;
}
else
{
buf2combo();
AfxMessageBox("读取数据成功");
}
}
void CSAD8PCDlg::OnLoaddefault()
{
// TODO: Add your control notification handler code here
m_csoutsck = _T(*(outsck_def + 5));
m_cscombps= _T(*(combps_set + 2));
m_csaddr = _T("1");
m_csthermbuchang ="-10";
m_csrs485sendmode =_T(*rs485sendmode);
UpdateData(FALSE);
}
BOOL CSAD8PCDlg::combo2readbuf(char *sad8buf_read)
{
extern char cDefault_char[];
extern int cnEeprom_Len;
int i;
extern char *outsck_def[];
extern char *combps_set[];
sad8com.thermstr2hex((unsigned char *) (char *) LPCTSTR(m_csthermbuchang),
strlen((char *) LPCTSTR(m_csthermbuchang)),
(byte *) (sad8buf_read + 21));
i = iCombotextnum(outsck_def, (char *) LPCTSTR(m_csoutsck), "NULL");
if (i < 0)
return FALSE;
sad8buf_read[2] = i;
i = iCombotextnum(combps_set, (char *) LPCTSTR(m_cscombps), "NULL");
if (i < 0)
return FALSE;
sad8buf_read[7] = i;
i = iCombotextnum(rs485sendmode, (char *) LPCTSTR(m_csrs485sendmode), "NULL");
if (i < 0)
return FALSE;
sad8buf_read[22] = i;
//sad8buf_read[6] = atoi(m_WCheckMode);
return TRUE;
}
BOOL CSAD8PCDlg::buf2thermedit(char *s)
{
char *p = s;
unsigned char stemp2[8];
char stemp[8][8];
unsigned short int i,j;
for (j = 0; j < 8; j++, p += 4)
{
str2BCD((unsigned char *) p, 4, stemp2, sizeof(stemp2));
i = stemp2[0] * 256 + stemp2[1];
if (0xffff == i)
sprintf(stemp[j], "%s", "断偶");
else
sprintf(stemp[j], "%d", i / 4);
}
m_therm1 = stemp[0];
m_therm2 = stemp[1];
m_therm3 = stemp[2];
m_therm4 = stemp[3];
m_therm5 = stemp[4];
m_therm6 = stemp[5];
m_therm7 = stemp[6];
m_therm8 = stemp[7];
return TRUE;
}
void CSAD8PCDlg::OnReadtherm()
{
UpdateData(TRUE);
sad8com.comno = getcomno();
BOOL result = sad8com.readtherm();
if (FALSE == result)
{
AfxMessageBox(sad8com.errnostring);
return;
}
buf2thermedit(sad8com.sad8_thermbuf + 1);
UpdateData(FALSE);
}
int CSAD8PCDlg::getcomno(void)
{
UpdateData(TRUE);
return (atoi((char *) LPCTSTR(m_cscomno)));
}
void CSAD8PCDlg::OnWritebuf()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
sad8com.comno = getcomno();
combo2readbuf(sad8com.sad8read_buf);
if ( TRUE == sad8com.iWrite_Sad8())
AfxMessageBox("写入数据成功");
else
AfxMessageBox(sad8com.errnostring);
return;
}
void CSAD8PCDlg::buf2combo()
{
extern char configupdate_set[];
extern int configlen;
extern char *outsck_def[];
extern char *combps_set[];
extern char *com_mode[];
extern char *buchang_set[];
extern char *modaddr[];
char *p = configupdate_set;
byte stemp[16];
UpdateData(TRUE);
sad8com.sad8read_buf[22] = ( sad8com.sad8read_buf[22]>=1 )?1:0;
m_csrs485sendmode = *( rs485sendmode + sad8com.sad8read_buf[22]);
m_csoutsck = *(outsck_def + sad8com.sad8read_buf[2]);
m_cscombps = *(combps_set + sad8com.sad8read_buf[7]);
sprintf((char *) stemp, "%d", sad8com.sad8read_buf[6]);
m_csaddr = stemp ;
sad8com.thermhex2str(sad8com.sad8read_buf[21], stemp, sizeof(stemp));
m_csthermbuchang = stemp;
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -