Header
Product Comparison: USB I2C | USB SPI | USB GPIO
  • My Account
  • Shopping Cart
  • Products
  • My Account
  • About
  • Products
  • PC-I2C/SPI/GPIO Adapters
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

D:/_sources/u2c_12/ControlPanel/I2cReadBar.cpp

Go to the documentation of this file.
00001 // Copyright (C)2006 Diolan ( http://www.diolan.com )
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU General Public License for more details.
00011 
00012 
00013 #include "stdafx.h"
00014 #include "controlpanel.h"
00015 #include "I2cReadBar.h"
00016 
00017 #ifdef _DEBUG
00018 #define new DEBUG_NEW
00019 #undef THIS_FILE
00020 static char THIS_FILE[] = __FILE__;
00021 #endif
00022 
00024 // CI2cReadBar dialog
00025 
00026 
00027 CI2cReadBar::CI2cReadBar()
00028         : CDialogBar(), m_bEnableControls(false)
00029 {
00030         //{{AFX_DATA_INIT(CI2cReadBar)
00031         m_strMemAddr = _T("");
00032         m_nMemAddrLen = -1;
00033         m_strSlaveAddr = _T("");
00034         m_Length = 0;
00035         //}}AFX_DATA_INIT
00036 }
00037 
00038 
00039 void CI2cReadBar::DoDataExchange(CDataExchange* pDX)
00040 {
00041         //{{AFX_DATA_MAP(CI2cReadBar)
00042         DDX_Control(pDX, IDC_READ_SLAVE_ADDR, m_ctrlSlaveAddr);
00043         DDX_Control(pDX, IDC_READ_MEM_ADDR, m_ctrlMemAddr);
00044         DDX_Text(pDX, IDC_READ_MEM_ADDR, m_strMemAddr);
00045         DDX_CBIndex(pDX, IDC_READ_MEM_ADDR_LEN, m_nMemAddrLen);
00046         DDX_CBString(pDX, IDC_READ_SLAVE_ADDR, m_strSlaveAddr);
00047         DDX_Text(pDX, IDC_READ_LENGTH, m_Length);
00048         //}}AFX_DATA_MAP
00049 }
00050 
00051 
00052 BEGIN_MESSAGE_MAP(CI2cReadBar, CDialogBar)
00053         //{{AFX_MSG_MAP(CI2cReadBar)
00054                 // NOTE: the ClassWizard will add message map macros here
00055         //}}AFX_MSG_MAP
00056         ON_UPDATE_COMMAND_UI(IDC_I2C_READ, OnUpdateI2cRead)
00057 END_MESSAGE_MAP()
00058 
00060 // CI2cReadBar message handlers
00061 BOOL CI2cReadBar::Create(CWnd* pParentWnd)
00062 {
00063         if (!CDialogBar::Create(pParentWnd, IDD, CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY |
00064                 CBRS_GRIPPER, IDD))
00065         {
00066                 TRACE("CDialogBar::Create failed in CI2cReadBar::Create");
00067                 return FALSE;
00068         }
00069         SetWindowText("I2cRead Bar");
00070         m_nMemAddrLen = 0;
00071         UpdateData(FALSE);
00072         return TRUE;
00073 
00074 }
00075 
00076 void CI2cReadBar::SaveCurrentValuesInHistory()
00077 {
00078         UpdateData(TRUE);
00079         int CurIndex;
00080         if (CB_ERR != (CurIndex = m_ctrlMemAddr.FindStringExact(-1, m_strMemAddr)))
00081                 m_ctrlMemAddr.DeleteString(CurIndex);
00082         m_ctrlMemAddr.InsertString(0, m_strMemAddr);
00083 
00084         if (CB_ERR == m_ctrlSlaveAddr.FindStringExact(-1, m_strSlaveAddr))
00085                 m_ctrlSlaveAddr.AddString(m_strSlaveAddr);
00086         UpdateData(FALSE);
00087 
00088 }
00089 
00090 void CI2cReadBar::FillSlaveList(PU2C_SLAVE_ADDR_LIST pSlaveList)
00091 {
00092         m_ctrlSlaveAddr.ResetContent();
00093 
00094         for (int i = 0; i < pSlaveList->nDeviceNumber; i++)
00095         {
00096                 BYTE nCurAddr = pSlaveList->List[i];
00097                 CString curAddr;
00098                 curAddr.Format("%02X", nCurAddr);
00099                 m_ctrlSlaveAddr.AddString(curAddr);
00100         }
00101 }
00102 
00103 
00104 BOOL CI2cReadBar::InitTransaction(PU2C_TRANSACTION pTransaction)
00105 {
00106         UpdateData(TRUE);
00107         char *endp;
00108         // initialization of the slave device address
00109         m_strSlaveAddr.TrimLeft();
00110         int SlaveAddr = strtol(m_strSlaveAddr, &endp, 16);
00111         if ((*endp) || m_strSlaveAddr.IsEmpty() || (SlaveAddr < 0) || (SlaveAddr > 0xFF))
00112         {
00113                 MessageBox("Bad value has been used as slave address.\nPlease provide value in range from 0 to FF");
00114                 GetDlgItem(IDC_READ_SLAVE_ADDR)->SetFocus();
00115                 return FALSE;
00116         }
00117         pTransaction->nSlaveDeviceAddress = (BYTE)SlaveAddr; 
00118         pTransaction->nMemoryAddressLength = (BYTE)m_nMemAddrLen;
00119         if (pTransaction->nMemoryAddressLength != 0)
00120         {
00121                 // initialization of the memory address
00122                 m_strMemAddr.TrimLeft();
00123                 pTransaction->nMemoryAddress = strtoul(m_strMemAddr, &endp, 16);
00124                 if ((*endp) || m_strMemAddr.IsEmpty() 
00125                         || ((pTransaction->nMemoryAddress > 0xFF) && (pTransaction->nMemoryAddressLength == 1))
00126                         || ((pTransaction->nMemoryAddress > 0xFFFF) && (pTransaction->nMemoryAddressLength == 2))
00127                         )
00128                 {
00129                         switch (pTransaction->nMemoryAddressLength)
00130                         {
00131                         case 1:
00132                                 MessageBox("Bad value has been used as memory address.\nPlease provide value in range from 0 to FF");
00133                                 break;
00134                         case 2:
00135                                 MessageBox("Bad value has been used as memory address.\nPlease provide value in range from 0 to FFFF");
00136                                 break;
00137                         case 4:
00138                                 MessageBox("Bad value has been used as memory address.\nPlease provide value in range from 0 to FFFFFFFF");
00139                                 break;
00140                         default:
00141                                 ASSERT(FALSE);
00142                                 break;
00143                         }
00144                         GetDlgItem(IDC_READ_MEM_ADDR)->SetFocus();
00145                         return FALSE;
00146                 }
00147         }
00148 
00149         if ((m_Length < 1) || (m_Length > 256))
00150         {
00151                 MessageBox("Bad value has been used as length.\nPlease provid value in range from 1 to 256");
00152                 GetDlgItem(IDC_READ_LENGTH)->SetFocus();
00153                 return FALSE;
00154         }
00155         pTransaction->nBufferLength = (USHORT)m_Length;
00156         SaveCurrentValuesInHistory();
00157 
00158         return TRUE;
00159 
00160 }
00161 
00162 void CI2cReadBar::EnableControls(bool bEnable)
00163 {
00164         m_bEnableControls = bEnable;
00165         if(bEnable)
00166         {
00167                 GetDlgItem(IDC_READ_SLAVE_ADDR)->EnableWindow(TRUE);
00168                 GetDlgItem(IDC_READ_MEM_ADDR_LEN)->EnableWindow(TRUE);
00169                 GetDlgItem(IDC_READ_MEM_ADDR)->EnableWindow(TRUE);
00170                 GetDlgItem(IDC_READ_LENGTH)->EnableWindow(TRUE);
00171         }
00172         else
00173         {
00174                 GetDlgItem(IDC_READ_SLAVE_ADDR)->EnableWindow(FALSE);
00175                 GetDlgItem(IDC_READ_MEM_ADDR_LEN)->EnableWindow(FALSE);
00176                 GetDlgItem(IDC_READ_MEM_ADDR)->EnableWindow(FALSE);
00177                 GetDlgItem(IDC_READ_LENGTH)->EnableWindow(FALSE);
00178         }
00179 }
00180 
00181 void CI2cReadBar::OnUpdateI2cRead (CCmdUI* pCmdUI)
00182 {
00183         if(m_bEnableControls)
00184                 pCmdUI->Enable(TRUE);
00185         else
00186                 pCmdUI->Enable(FALSE);
00187 }
00188 
  • Products
  • PC-I2C/SPI/GPIO Adapters
  • Comparison
  • PC-I2C/SPI/GPIO Adapter DLN-1
  • USB-I2C/SPI/GPIO Adapter DLN-2
  • Multiprotocol Master DLN-4M
  • Multiprotocol Slave DLN-4S
  • Downloads
  • Software
  • Documentation
  • SW Tools & Examples
  • Development Boards
  • Open Source Projects
  • Discontinued Products
  • API Documentation
  • Downloads
  • SW Tools and Examples
footer top footer bottom
© Copyright Diolan 2006-2012