📄 ds2wdlg.cpp
字号:
// DS2WDlg.cpp : implementation file
//
//***************************************************************************
//---------------------------------------------------------------------------
// Copyright (C) 2002 Dallas Semiconductor Corporation, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Dallas Semiconductor
// shall not be used except as stated in the Dallas Semiconductor
// Branding Policy.
#include "stdafx.h"
#include "DS2W.h"
#include "DS2WDlg.h"
#include "DSPIC.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CdsPic Pic;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CDS2WDlg dialog
CDS2WDlg::CDS2WDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDS2WDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDS2WDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDS2WDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDS2WDlg)
DDX_Control(pDX, IDC_EDIT_WBYTE2, m_EDIT_WBYTE2);
DDX_Control(pDX, IDC_EDIT_WBYTE1, m_EDIT_WBYTE1);
DDX_Control(pDX, IDC_EDIT_STATUS, m_EDIT_STATUS);
DDX_Control(pDX, IDC_EDIT_RNACK, m_EDIT_RNACK);
DDX_Control(pDX, IDC_EDIT_RACK_BYTES, m_EDIT_RACK_NUM);
DDX_Control(pDX, IDC_EDIT_RACK, m_EDIT_RACK);
DDX_Control(pDX, IDC_EDIT_ADDR, m_EDIT_ADDR);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDS2WDlg, CDialog)
//{{AFX_MSG_MAP(CDS2WDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_RBYTE_ACK, OnRbyteAck)
ON_BN_CLICKED(ID_RBYTE_NACK, OnRbyteNack)
ON_BN_CLICKED(ID_WADDR, OnWaddr)
ON_BN_CLICKED(ID_WBYTE1, OnWbyte1)
ON_BN_CLICKED(ID_WBYTE2, OnWbyte2)
ON_BN_CLICKED(ID_START, OnStart)
ON_BN_CLICKED(ID_STOP, OnStop)
ON_BN_CLICKED(ID_RADDR, OnRaddr)
ON_BN_CLICKED(ID_CANCEL, OnCancel)
ON_BN_CLICKED(IDC_FIND_ADDRESS, OnFindAddress)
ON_BN_CLICKED(IDC_RESET_BUS, OnResetBus)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDS2WDlg message handlers
BOOL CDS2WDlg::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
// INIT ALL EDIT BOXES
m_EDIT_ADDR.SetWindowText("");
m_EDIT_RACK.SetWindowText("");
m_EDIT_RACK_NUM.SetWindowText("01");
m_EDIT_RNACK.SetWindowText("");
m_EDIT_WBYTE1.SetWindowText("");
m_EDIT_WBYTE2.SetWindowText("");
if(!Pic.BoardPresent())
{
m_EDIT_STATUS.SetWindowText("Board Not Found");
MessageBox("DS2W Board Not Found");
}
else
m_EDIT_STATUS.SetWindowText("Welcome to DS2W, COM Port Initialized");
return TRUE; // return TRUE unless you set the focus to a control
}
void CDS2WDlg::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 CDS2WDlg::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 CDS2WDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDS2WDlg::OnRbyteAck()
{ // reads a byte(s) with Ack, # bytes edit used to determine # bytes to read
CWaitCursor wait; // Scope of Wait Cursor Entire Function
bool success = false, error = false;
UCHAR data[8] = "GHIJKLM";
UCHAR bytecount = 0;
int dc = 0;
char buf[80], temp[80];
m_EDIT_RACK_NUM.GetWindowText(buf,3);
for(int count=0; count <=80; count++)
{
if((buf[count]>=48) && (buf[count]<=57))
data[dc] = (buf[count] - 48)*16;
else if(buf[count]>=65 && buf[count]<=70)
data[dc] = (buf[count]-55)*16;
else if(buf[count]>=97 && buf[count]<=102)
data[dc] = (buf[count]-87)*16;
else if(buf[count] == 0)
{
bytecount = dc;
break;
}
else
{
error = true;
break;
}
count++;
if(buf[count]>=48 && buf[count]<=57)
data[dc] += (buf[count] - 48);
else if(buf[count]>=65 && buf[count]<=70)
data[dc] += (buf[count]-55);
else if(buf[count]>=97 && buf[count]<=102)
data[dc] += (buf[count]-87);
else
{
error = true;
break;
}
dc++;
}
if(error == true)
{
MessageBox("Number Of Bytes Invalid");
}
else
{
strcpy(buf, "");
if(data[0] > 8 || data[0] <1)
MessageBox("Valid Values For Byte Count Are 1 To 8", "Range Error");
else
{
for(count = 0; count < data[0]; count++)
{
success = Pic.ReadSlave2W(data[1], true);
if (success == false)
MessageBox("Data RX Failed", "COM Error");
else
{
_itoa(data[1],temp, 16);
if(temp[1] == 0)
{
temp[2] = 0;
temp[1] = temp[0];
temp[0] = '0';
}
strcat(buf, temp);
}
}
}
strcat(buf, "h");
m_EDIT_RACK.SetWindowText(buf);
m_EDIT_STATUS.SetWindowText("Read w/ACK");
}
}
void CDS2WDlg::OnRbyteNack()
{ // reads 1 byte with Nack
CWaitCursor wait; // Scope of Wait Cursor Entire Function
bool success = false;
UCHAR data;
char buf[80] = "";
success = Pic.ReadSlave2W(data, false);
if (success == false)
MessageBox("Data RX Failed", "COM Error");
else
{
_itoa(data, buf,16);
if(buf[1] == 0)
{
buf[2]=0;
buf[1]=buf[0];
buf[0]='0';
}
strcat(buf, "h");
m_EDIT_RNACK.SetWindowText(buf);
m_EDIT_STATUS.SetWindowText("Read w/NACK");
}
}
void CDS2WDlg::OnWaddr()
{ // Writes the address in WADDR edit box out to 2-wire bus
CWaitCursor wait; // Scope of Wait Cursor Entire Function
bool success = false, error = false;
UCHAR data[8] = "GHIJKLM";
UCHAR bytecount = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -