[11] | 1 | // ModbucfgView.cpp : implementation of the CModbucfgView class
|
---|
| 2 | //
|
---|
| 3 |
|
---|
| 4 | #include "stdafx.h"
|
---|
| 5 | #include "Modbucfg.h"
|
---|
| 6 |
|
---|
| 7 | #include "ModbucfgDoc.h"
|
---|
| 8 | #include "ModbucfgView.h"
|
---|
| 9 | #include ".\modbucfgview.h"
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | #ifdef _DEBUG
|
---|
| 13 | #define new DEBUG_NEW
|
---|
| 14 | #undef THIS_FILE
|
---|
| 15 | static char THIS_FILE[] = __FILE__;
|
---|
| 16 | #endif
|
---|
| 17 |
|
---|
| 18 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 19 | // CModbucfgView
|
---|
| 20 |
|
---|
| 21 | IMPLEMENT_DYNCREATE(CModbucfgView, CFormView)
|
---|
| 22 |
|
---|
| 23 | BEGIN_MESSAGE_MAP(CModbucfgView, CFormView)
|
---|
| 24 | //{{AFX_MSG_MAP(CModbucfgView)
|
---|
| 25 | ON_BN_CLICKED(IDC_CHK_Enable_Poll, OnchkEnablePoll)
|
---|
| 26 | ON_EN_CHANGE(IDC_EDIT_INTERVAL, OnChangeEditInterval)
|
---|
| 27 | ON_BN_CLICKED(IDC_CMD_WRITE, OnCmdWrite)
|
---|
| 28 | //}}AFX_MSG_MAP
|
---|
| 29 | ON_CBN_SELCHANGE(IDC_CBO_READ_FUNCTION, OnCbnSelchangeCboReadFunction)
|
---|
| 30 | ON_CBN_SELCHANGE(IDC_CBO_WRITE_FUNCTION, OnCbnSelchangeCboWriteFunction)
|
---|
| 31 | ON_COMMAND(ID_APP_MEM_MAP, OnAppMemMap)
|
---|
| 32 | ON_EN_CHANGE(IDC_EDIT_QUANT, OnEnChangeEditQuant)
|
---|
| 33 | ON_EN_CHANGE(IDC_EDIT_ADDR, OnEnChangeEditAddr)
|
---|
| 34 | ON_EN_CHANGE(IDC_EDIT_QUANT_2, OnEnChangeEditQuant2)
|
---|
| 35 | ON_LBN_SELCHANGE(IDC_LIST5, OnLbnSelchangeList5)
|
---|
| 36 | ON_LBN_SELCHANGE(IDC_LST_VALUES, OnLbnSelchangeLstValues)
|
---|
| 37 | ON_EN_CHANGE(IDC_EDIT_ADDR_WRI, OnEnChangeEditAddrWri)
|
---|
| 38 | ON_EN_CHANGE(IDC_EDIT_VALUE, OnEnChangeEditValue)
|
---|
| 39 | ON_WM_VSCROLL()
|
---|
| 40 | ON_BN_CLICKED(IDC_CMD_READ, OnCmdRead)
|
---|
| 41 | ON_EN_CHANGE(IDC_EDIT16, OnEnChangeEdit16)
|
---|
| 42 | ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
|
---|
| 43 | ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
|
---|
| 44 | END_MESSAGE_MAP()
|
---|
| 45 |
|
---|
| 46 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 47 | // CModbucfgView construction/destruction
|
---|
| 48 |
|
---|
| 49 | CModbucfgView::CModbucfgView()
|
---|
| 50 | : CFormView(CModbucfgView::IDD)
|
---|
| 51 | /* , m_edtQuant2(false)
|
---|
| 52 | , m_edtQuant2(_T(""))*/
|
---|
| 53 | , m_spinIndex(0)
|
---|
| 54 | {
|
---|
| 55 | //{{AFX_DATA_INIT(CModbucfgView)
|
---|
| 56 | //}}AFX_DATA_INIT
|
---|
| 57 | // TODO: add construction code here
|
---|
| 58 |
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | CModbucfgView::~CModbucfgView()
|
---|
| 62 | {
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void CModbucfgView::DoDataExchange(CDataExchange* pDX)
|
---|
| 66 | {
|
---|
| 67 | CFormView::DoDataExchange(pDX);
|
---|
| 68 | //{{AFX_DATA_MAP(CModbucfgView)
|
---|
| 69 | DDX_Control(pDX, IDC_CBO_DATA_TYPE, m_cboDataType);
|
---|
| 70 | DDX_Control(pDX, IDC_EDIT_INTERVAL, m_edtInterval);
|
---|
| 71 | DDX_Control(pDX, IDC_CHK_Enable_Poll, m_butPollEnable);
|
---|
| 72 | DDX_Control(pDX, IDC_STAT_STATUS, m_statStatus);
|
---|
| 73 | DDX_Control(pDX, IDC_STAT_ERROR, m_staError);
|
---|
| 74 | DDX_Control(pDX, IDC_LST_VALUES, m_lstValues);
|
---|
| 75 | DDX_Control(pDX, IDC_CBO_WRITE_FUNCTION, m_cboWriteFunctions);
|
---|
| 76 | DDX_Control(pDX, IDC_CBO_READ_FUNCTION, m_cboReadFunctions);
|
---|
| 77 | DDX_Control(pDX, IDC_CBO_CONNECTION, m_cboConnections);
|
---|
| 78 | DDX_Control(pDX, IDC_EDIT_VALUE, m_edtValue);
|
---|
| 79 | DDX_Control(pDX, IDC_EDIT_QUANT, m_edtQuant);
|
---|
| 80 | DDX_Control(pDX, IDC_EDIT_DEVICE, m_edtDevice);
|
---|
| 81 | DDX_Control(pDX, IDC_EDIT_ADDR_WRI, m_edtWriteAddr);
|
---|
| 82 | DDX_Control(pDX, IDC_EDIT_ADDR, m_edtReadAddr);
|
---|
| 83 | DDX_Control(pDX, IDC_CMD_WRITE, m_cmdWrite);
|
---|
| 84 | //}}AFX_DATA_MAP
|
---|
| 85 | DDX_Control(pDX, IDC_EDIT_QUANT_2, m_edtQuant2);
|
---|
| 86 | // DDX_Control(pDX, IDC_LIST5, m_list5Values);
|
---|
| 87 | DDX_Control(pDX, IDC_EDIT6, m_edtIndex);
|
---|
| 88 | DDX_Text(pDX, IDC_EDIT6, m_spinIndex);
|
---|
| 89 | DDX_Control(pDX, IDC_EDIT3, m_readEil);
|
---|
| 90 | DDX_Control(pDX, IDC_EDIT5, m_readSVd);
|
---|
| 91 | DDX_Control(pDX, IDC_EDIT7, m_readSVfin);
|
---|
| 92 | DDX_Control(pDX, IDC_EDIT8, m_readSV1);
|
---|
| 93 | DDX_Control(pDX, IDC_EDIT9, m_readSV2);
|
---|
| 94 | DDX_Control(pDX, IDC_EDIT10, m_readdtp);
|
---|
| 95 | DDX_Control(pDX, IDC_EDIT11, m_readdt);
|
---|
| 96 | DDX_Control(pDX, IDC_EDIT12, m_readdP);
|
---|
| 97 | DDX_Control(pDX, IDC_EDIT13, m_readdPsecu);
|
---|
| 98 | DDX_Control(pDX, IDC_EDIT14, m_readSVil);
|
---|
| 99 | DDX_Control(pDX, IDC_EDIT15, m_readSleil);
|
---|
| 100 | DDX_Control(pDX, IDC_EDIT16, m_readSTc);
|
---|
| 101 | DDX_Control(pDX, IDC_EDIT17, m_readNbal_max);
|
---|
| 102 | DDX_Control(pDX, IDC_EDIT18, m_readFr);
|
---|
| 103 | DDX_Control(pDX, IDC_EDIT19, m_readN_cur);
|
---|
| 104 | DDX_Control(pDX, IDC_CMD_READ, m_cmdRead);
|
---|
| 105 | DDX_Control(pDX, IDC_EDIT4, m_readNil);
|
---|
| 106 | DDX_Control(pDX, IDC_EDIT20, m_readNil_stat);
|
---|
| 107 | DDX_Control(pDX, IDC_EDIT21, m_readP_last);
|
---|
| 108 | DDX_Control(pDX, IDC_EDIT22, m_readN_last);
|
---|
| 109 | DDX_Control(pDX, IDC_EDIT23, m_readdPil);
|
---|
| 110 | DDX_Control(pDX, IDC_EDIT24, m_readV_cur);
|
---|
| 111 | DDX_Control(pDX, IDC_EDIT25, m_readPic);
|
---|
| 112 | DDX_Control(pDX, IDC_EDIT26, m_readTimer);
|
---|
| 113 | DDX_Control(pDX, IDC_EDIT27, m_readNbal);
|
---|
| 114 | DDX_Control(pDX, IDC_EDIT28, m_readP_cde);
|
---|
| 115 | DDX_Control(pDX, IDC_EDIT29, m_readPp);
|
---|
| 116 | DDX_Control(pDX, IDC_EDIT30, m_readStat_C_1);
|
---|
| 117 | DDX_Control(pDX, IDC_EDIT31, m_readStat_C_2);
|
---|
| 118 | DDX_Control(pDX, IDC_EDIT32, m_readStat_C_3);
|
---|
| 119 | DDX_Control(pDX, IDC_EDIT33, m_readStat_C_4);
|
---|
| 120 | DDX_Control(pDX, IDC_EDIT34, m_readStat_C_5);
|
---|
| 121 | DDX_Control(pDX, IDC_EDIT35, m_readStat_C_6);
|
---|
| 122 | DDX_Control(pDX, IDC_EDIT36, m_readStat_C_7);
|
---|
| 123 | DDX_Control(pDX, IDC_EDIT37, m_readStat_C_8);
|
---|
| 124 | DDX_Control(pDX, IDC_EDIT38, m_readNum_C1a);
|
---|
| 125 | DDX_Control(pDX, IDC_EDIT39, m_readNum_C1b);
|
---|
| 126 | DDX_Control(pDX, IDC_EDIT40, m_readNum_C2a);
|
---|
| 127 | DDX_Control(pDX, IDC_EDIT41, m_readNum_C2b);
|
---|
| 128 | DDX_Control(pDX, IDC_EDIT42, m_readNum_C3a);
|
---|
| 129 | DDX_Control(pDX, IDC_EDIT43, m_readNum_C3b);
|
---|
| 130 | DDX_Control(pDX, IDC_EDIT44, m_readNum_C4a);
|
---|
| 131 | DDX_Control(pDX, IDC_EDIT45, m_readNum_C4b);
|
---|
| 132 | DDX_Control(pDX, IDC_EDIT54, m_readN_Seqcond);
|
---|
| 133 | DDX_Control(pDX, IDC_EDIT57, m_readMAP);
|
---|
| 134 | DDX_Control(pDX, IDC_EDIT46, m_readTemp_cond_1);
|
---|
| 135 | DDX_Control(pDX, IDC_EDIT47, m_readTemp_cond_2);
|
---|
| 136 | DDX_Control(pDX, IDC_EDIT48, m_readTemp_cond_3);
|
---|
| 137 | DDX_Control(pDX, IDC_EDIT49, m_readTemp_cond_4);
|
---|
| 138 | DDX_Control(pDX, IDC_EDIT50, m_readTemp_cond_5);
|
---|
| 139 | DDX_Control(pDX, IDC_EDIT51, m_readTemp_cond_6);
|
---|
| 140 | DDX_Control(pDX, IDC_EDIT52, m_readTemp_cond_7);
|
---|
| 141 | DDX_Control(pDX, IDC_EDIT53, m_readTemp_cond_8);
|
---|
| 142 | DDX_Control(pDX, IDC_EDIT58, m_readStat_C_9);
|
---|
| 143 | DDX_Control(pDX, IDC_EDIT59, m_readStat_C_10);
|
---|
| 144 | DDX_Control(pDX, IDC_EDIT60, m_readStat_C_11);
|
---|
| 145 | DDX_Control(pDX, IDC_EDIT61, m_readStat_C_12);
|
---|
| 146 | DDX_Control(pDX, IDC_EDIT62, m_readTemp_cond_9);
|
---|
| 147 | DDX_Control(pDX, IDC_EDIT63, m_readTemp_cond_10);
|
---|
| 148 | DDX_Control(pDX, IDC_EDIT64, m_readTemp_cond_11);
|
---|
| 149 | DDX_Control(pDX, IDC_EDIT65, m_readTemp_cond_12);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | BOOL CModbucfgView::PreCreateWindow(CREATESTRUCT& cs)
|
---|
| 153 | {
|
---|
| 154 | // TODO: Modify the Window class or styles here by modifying
|
---|
| 155 | // the CREATESTRUCT cs
|
---|
| 156 |
|
---|
| 157 | return CFormView::PreCreateWindow(cs);
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 161 | // CModbucfgView diagnostics
|
---|
| 162 |
|
---|
| 163 | #ifdef _DEBUG
|
---|
| 164 | void CModbucfgView::AssertValid() const
|
---|
| 165 | {
|
---|
| 166 | CFormView::AssertValid();
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | void CModbucfgView::Dump(CDumpContext& dc) const
|
---|
| 170 | {
|
---|
| 171 | CFormView::Dump(dc);
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | CModbucfgDoc* CModbucfgView::GetDocument() // non-debug version is inline
|
---|
| 175 | {
|
---|
| 176 | ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CModbucfgDoc)));
|
---|
| 177 | return (CModbucfgDoc*)m_pDocument;
|
---|
| 178 | }
|
---|
| 179 | #endif //_DEBUG
|
---|
| 180 |
|
---|
| 181 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 182 | // CModbucfgView message handlers
|
---|
| 183 |
|
---|
| 184 | void CModbucfgView::OnInitialUpdate()
|
---|
| 185 | {
|
---|
| 186 | CFormView::OnInitialUpdate();
|
---|
| 187 |
|
---|
| 188 | // TODO: Add your specialized code here and/or call the base class
|
---|
| 189 | LoadControls();
|
---|
| 190 |
|
---|
| 191 | //Dans le cas d'une CFormView, les ascenseurs apparaissent automatiquement dès que
|
---|
| 192 | //la surface cliente de la fenêtre devient trop petite par rapport à la surface réelle.
|
---|
| 193 | //pour ne pas avoir à gérer les ascenseurs, je les supprime: une CFormView hérite de la classe CSCrollView
|
---|
| 194 | //qui dispose de la fonction SetScaleToFitSize pour adapter la surface de la fenêtre à la taille fenêtrée
|
---|
| 195 | CRect Rect;
|
---|
| 196 | GetParentFrame()->GetWindowRect(&Rect);
|
---|
| 197 | SIZE size;
|
---|
| 198 | size.cx=Rect.Width();
|
---|
| 199 | size.cy=Rect.Height();
|
---|
| 200 | SetScaleToFitSize(size);
|
---|
| 201 |
|
---|
| 202 | //controle spin
|
---|
| 203 | CSpinButtonCtrl* pSpin=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2);
|
---|
| 204 | pSpin->SetRange(0,100);//plage du control : 0-100
|
---|
| 205 | pSpin->SetPos((int)m_spinIndex * 1);//valeur initiale 1
|
---|
| 206 |
|
---|
| 207 | //tableaux pour les write multiple
|
---|
| 208 | m_bValueMultiple.SetSize(100);
|
---|
| 209 | m_sValueMultiple.SetSize(100);
|
---|
| 210 | m_wValueMultiple.SetSize(100);
|
---|
| 211 | m_fValueMultiple.SetSize(100);
|
---|
| 212 | m_dValueMultiple.SetSize(100);
|
---|
| 213 |
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | void CModbucfgView::LoadControls()
|
---|
| 217 | {
|
---|
| 218 | CString str;
|
---|
| 219 | CString sKey;
|
---|
| 220 | CConnection* pConnection;
|
---|
| 221 | POSITION pos;
|
---|
| 222 |
|
---|
| 223 | //Read functions
|
---|
| 224 | m_cboReadFunctions.AddString(CString("LoopbackTest"));
|
---|
| 225 | m_cboReadFunctions.AddString(CString("Holding Registers"));
|
---|
| 226 | m_cboReadFunctions.AddString(CString("Input Registers"));
|
---|
| 227 | m_cboReadFunctions.AddString(CString("Coil Status"));
|
---|
| 228 | m_cboReadFunctions.AddString(CString("Discrete Inputs"));
|
---|
| 229 | m_cboReadFunctions.SetCurSel(1);
|
---|
| 230 |
|
---|
| 231 | //Write Functions
|
---|
| 232 | m_cboWriteFunctions.AddString(CString("Single Register"));
|
---|
| 233 | m_cboWriteFunctions.AddString(CString("Single Coil"));
|
---|
| 234 | m_cboWriteFunctions.AddString(CString("Multiple Registers"));
|
---|
| 235 | m_cboWriteFunctions.AddString(CString("Multiple Coils"));
|
---|
| 236 | m_cboWriteFunctions.SetCurSel(0);
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | pos = gConnections.GetStartPosition();
|
---|
| 240 |
|
---|
| 241 | m_cboConnections.ResetContent();
|
---|
| 242 |
|
---|
| 243 | while (NULL!=pos) {
|
---|
| 244 | gConnections.GetNextAssoc(pos,sKey,pConnection);
|
---|
| 245 | m_cboConnections.AddString(sKey);
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | m_cboConnections.SetCurSel(0);
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 | //Default Values
|
---|
| 252 | str=_T("1");
|
---|
| 253 | m_edtDevice.SetWindowText(str);
|
---|
| 254 |
|
---|
| 255 | str=_T("0");
|
---|
| 256 | m_edtValue.SetWindowText(str);
|
---|
| 257 | m_edtWriteAddr.SetWindowText(str);
|
---|
| 258 | m_edtReadAddr.SetWindowText(str);
|
---|
| 259 |
|
---|
| 260 | str=_T("10");
|
---|
| 261 | m_edtQuant.SetWindowText(str);
|
---|
| 262 |
|
---|
| 263 | str=_T("1000");
|
---|
| 264 | m_edtInterval.SetWindowText(str);
|
---|
| 265 |
|
---|
| 266 | str=_T("10");
|
---|
| 267 | m_edtQuant2.SetWindowText(str);
|
---|
| 268 |
|
---|
| 269 | //Data Type
|
---|
| 270 | m_cboDataType.AddString(CString("char"));
|
---|
| 271 | m_cboDataType.AddString(CString("signed - 16"));
|
---|
| 272 | m_cboDataType.AddString(CString("unsigned - 16"));
|
---|
| 273 | m_cboDataType.AddString(CString("float - 32"));
|
---|
| 274 | m_cboDataType.AddString(CString("float - 32 reverse"));
|
---|
| 275 | m_cboDataType.AddString(CString("double - 64"));
|
---|
| 276 | m_cboDataType.AddString(CString("double - 64 reverse"));
|
---|
| 277 | m_cboDataType.SetCurSel(1);
|
---|
| 278 |
|
---|
| 279 | //associe la variable m_readVacuum à la ressource IDC_LIST2
|
---|
| 280 | m_readVacuum = (CListCtrl*)GetDlgItem (IDC_LIST2);
|
---|
| 281 | //
|
---|
| 282 | m_readVacuum->SetExtendedStyle(LVS_REPORT | LVS_EX_FULLROWSELECT);
|
---|
| 283 | //ajout des titres
|
---|
| 284 | m_readVacuum->InsertColumn(0,_T("Name"),LVCFMT_CENTER,50);
|
---|
| 285 | m_readVacuum->InsertColumn(1,_T("value(mbar)"),LVCFMT_CENTER,100);
|
---|
| 286 | m_readVacuum->SetBkColor(RGB(202,202,255));
|
---|
| 287 | //nb de lignes
|
---|
| 288 | // m_readVacuum->SetItemCount(12);
|
---|
| 289 | //init tableau
|
---|
| 290 | for (int i=0;i < 12;i++)
|
---|
| 291 | {
|
---|
| 292 | str.Format(TEXT("V%d"), i+1);
|
---|
| 293 | // Insert the item, select every other item.
|
---|
| 294 | m_readVacuum->InsertItem(LVIF_TEXT|LVIF_STATE, i, str,
|
---|
| 295 | (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,0, 0);
|
---|
| 296 | m_readVacuum->SetItemText(i,1,"0");
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | //associe la variable m_readCondParam à la ressource IDC_LIST3
|
---|
| 300 | m_readCondParam = (CListCtrl*)GetDlgItem (IDC_LIST3);
|
---|
| 301 | //
|
---|
| 302 | m_readCondParam->SetExtendedStyle(LVS_REPORT | LVS_EX_FULLROWSELECT);
|
---|
| 303 | //ajout des titres
|
---|
| 304 | m_readCondParam->InsertColumn(0,_T("step number"),LVCFMT_CENTER,40);
|
---|
| 305 | m_readCondParam->InsertColumn(1,_T("Pi_min"),LVCFMT_CENTER,50);
|
---|
| 306 | m_readCondParam->InsertColumn(1,_T("Pi_max"),LVCFMT_CENTER,50);
|
---|
| 307 | m_readCondParam->InsertColumn(1,_T("Tn_max"),LVCFMT_CENTER,50);
|
---|
| 308 | m_readCondParam->InsertColumn(1,_T("Tp_max"),LVCFMT_CENTER,50);
|
---|
| 309 | m_readCondParam->InsertColumn(1,_T("Ln(us)"),LVCFMT_CENTER,50);
|
---|
| 310 | //init tableau
|
---|
| 311 | for (int i=0;i < 12;i++)
|
---|
| 312 | {
|
---|
| 313 | str.Format(TEXT("%d"), i+1);
|
---|
| 314 | // Insert the item, select every other item.
|
---|
| 315 | m_readCondParam->InsertItem(LVIF_TEXT|LVIF_STATE, i, str,
|
---|
| 316 | (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,0, 0);
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | void CModbucfgView::StartWork()
|
---|
| 321 | {
|
---|
| 322 | SCODE sc = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);
|
---|
| 323 | //SCODE sc = ::CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);
|
---|
| 324 |
|
---|
| 325 | if (FAILED(sc))
|
---|
| 326 | {
|
---|
| 327 | // warn about non-NULL success codes
|
---|
| 328 | TRACE1("Warning: OleInitialize returned scode = %x",sc);
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | m_dwCount=0;
|
---|
| 332 | m_dwSum=0;
|
---|
| 333 | m_dwErrors=0;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | void CModbucfgView::DoWork()
|
---|
| 337 | {
|
---|
| 338 | ldiv_t div_result;
|
---|
| 339 | float fUpdateSpeed;
|
---|
| 340 | DWORD dwTime;
|
---|
| 341 | CString str;
|
---|
| 342 | WORD nError;
|
---|
| 343 | static int iFunction=0;
|
---|
| 344 |
|
---|
| 345 | int iNumLoops=10;
|
---|
| 346 |
|
---|
| 347 |
|
---|
| 348 | fUpdateSpeed=0.0;
|
---|
| 349 |
|
---|
| 350 | if ((m_cboReadFunctions.GetCurSel()>=LOOP_BACK_TEST)&&
|
---|
| 351 | (m_cboReadFunctions.GetCurSel()<=READ_INPUT_STATUS)){
|
---|
| 352 |
|
---|
| 353 | m_dwCount++;
|
---|
| 354 | // nError=ExecuteReadFunction(m_cboReadFunctions.GetCurSel(),dwTime,str);
|
---|
| 355 | nError=ExecuteReadFunction(iFunction++,dwTime,str);
|
---|
| 356 | if (iFunction==6)iFunction=0;
|
---|
| 357 | m_dwSum +=dwTime;
|
---|
| 358 |
|
---|
| 359 | div_result = ldiv(m_dwCount,iNumLoops);
|
---|
| 360 |
|
---|
| 361 | if (CModbus::ERR_OK!=nError){
|
---|
| 362 | m_dwErrors++;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | if (0==div_result.rem){
|
---|
| 366 | fUpdateSpeed=(float)(iNumLoops*1000)/(float)m_dwSum;
|
---|
| 367 | m_dwSum=0;
|
---|
| 368 | }
|
---|
| 369 | else {
|
---|
| 370 | fUpdateSpeed=(float)(1*1000)/(float)dwTime;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | m_staError.SetWindowText(str);
|
---|
| 374 | str.Format("%d Errors=%d %4.2f(Up./s) ",m_dwCount,m_dwErrors,fUpdateSpeed);
|
---|
| 375 | m_statStatus.SetWindowText(str);
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 |
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | void CModbucfgView::EndWork()
|
---|
| 382 | {
|
---|
| 383 | ::CoUninitialize();
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 | void CModbucfgView::OnchkEnablePoll()
|
---|
| 387 | {
|
---|
| 388 | CString sText;
|
---|
| 389 | DWORD dwInterval=0;
|
---|
| 390 |
|
---|
| 391 | m_edtInterval.GetWindowText(sText);
|
---|
| 392 | dwInterval=DWORD(atol(sText));
|
---|
| 393 |
|
---|
| 394 | // if (dwInterval>10000) {
|
---|
| 395 | if ((dwInterval>10000) || (dwInterval<200)) {
|
---|
| 396 | AfxMessageBox("Max. is 10000 ms and Min. is 200 ms");
|
---|
| 397 | dwInterval=10000;
|
---|
| 398 | sText.Format("%d",dwInterval);
|
---|
| 399 | m_edtInterval.SetWindowText(sText);
|
---|
| 400 | return;
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | if (0!=m_butPollEnable.GetCheck()) {
|
---|
| 404 | if (!IsBusy()) {
|
---|
| 405 | CreateThread(0,0,NULL,dwInterval);
|
---|
| 406 | }
|
---|
| 407 | m_butPollEnable.SetCheck(1);
|
---|
| 408 | }
|
---|
| 409 | else {
|
---|
| 410 | Stop();
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 |
|
---|
| 415 | WORD CModbucfgView::ExecuteReadFunction(int iFunction,DWORD& dwTime, CString& rErrorMessage)
|
---|
| 416 | {
|
---|
| 417 | CModbus* pModbus;
|
---|
| 418 | CShortArray aValues;
|
---|
| 419 | CByteArray abCoilValues;
|
---|
| 420 |
|
---|
| 421 | CFloatArray afValues;
|
---|
| 422 | CDblArray adValues;
|
---|
| 423 |
|
---|
| 424 | CString str;
|
---|
| 425 | CString sAux;
|
---|
| 426 | WORD nError;
|
---|
| 427 | int i;
|
---|
| 428 | BOOL bRegisters;
|
---|
| 429 | DWORD dwStart;
|
---|
| 430 | CString sKey;
|
---|
| 431 | CConnection* pConnection =NULL;
|
---|
| 432 | BYTE byDevice;
|
---|
| 433 | WORD wQuant;
|
---|
| 434 | WORD wAddr;
|
---|
| 435 | int nIndex;
|
---|
| 436 | int nPreviusCount;
|
---|
| 437 | int iDataType;
|
---|
| 438 |
|
---|
| 439 | CListCtrl* vacuum = (CListCtrl*)GetDlgItem (IDC_LIST2);
|
---|
| 440 | CListCtrl* parameters = (CListCtrl*)GetDlgItem (IDC_LIST3);
|
---|
| 441 |
|
---|
| 442 | i=m_cboConnections.GetCurSel();
|
---|
| 443 | if (i<0) {
|
---|
| 444 | return 0;
|
---|
| 445 | }
|
---|
| 446 | else {
|
---|
| 447 | m_cboConnections.GetLBText(i,sKey);
|
---|
| 448 |
|
---|
| 449 | if (gConnections.Lookup(sKey,pConnection)) {
|
---|
| 450 |
|
---|
| 451 | pModbus=pConnection->m_pModbus;
|
---|
| 452 | }
|
---|
| 453 | else {
|
---|
| 454 | ASSERT(FALSE);
|
---|
| 455 | return 0;
|
---|
| 456 | }
|
---|
| 457 | }
|
---|
| 458 |
|
---|
| 459 | m_edtDevice.GetWindowText(str);
|
---|
| 460 | byDevice=BYTE(atoi(str));
|
---|
| 461 |
|
---|
| 462 | switch (iFunction)
|
---|
| 463 | {
|
---|
| 464 | case 0:
|
---|
| 465 | //coils : case READ_OUTPUT_STATUS
|
---|
| 466 | wQuant=13;
|
---|
| 467 | abCoilValues.SetSize(wQuant);
|
---|
| 468 | wAddr=3000;
|
---|
| 469 | nError=pModbus->ReadOutputStatus(byDevice,wAddr,wQuant, abCoilValues);
|
---|
| 470 |
|
---|
| 471 | str.Format("%d",abCoilValues[0]);
|
---|
| 472 | m_readEil.SetWindowText(str);
|
---|
| 473 | str.Format("%d",abCoilValues[1]);
|
---|
| 474 | m_readStat_C_1.SetWindowText(str);
|
---|
| 475 | str.Format("%d",abCoilValues[2]);
|
---|
| 476 | m_readStat_C_2.SetWindowText(str);
|
---|
| 477 | str.Format("%d",abCoilValues[3]);
|
---|
| 478 | m_readStat_C_3.SetWindowText(str);
|
---|
| 479 | str.Format("%d",abCoilValues[4]);
|
---|
| 480 | m_readStat_C_4.SetWindowText(str);
|
---|
| 481 | str.Format("%d",abCoilValues[5]);
|
---|
| 482 | m_readStat_C_5.SetWindowText(str);
|
---|
| 483 | str.Format("%d",abCoilValues[6]);
|
---|
| 484 | m_readStat_C_6.SetWindowText(str);
|
---|
| 485 | str.Format("%d",abCoilValues[7]);
|
---|
| 486 | m_readStat_C_7.SetWindowText(str);
|
---|
| 487 | str.Format("%d",abCoilValues[8]);
|
---|
| 488 | m_readStat_C_8.SetWindowText(str);
|
---|
| 489 | str.Format("%d",abCoilValues[9]);
|
---|
| 490 | m_readStat_C_9.SetWindowText(str);
|
---|
| 491 | str.Format("%d",abCoilValues[10]);
|
---|
| 492 | m_readStat_C_10.SetWindowText(str);
|
---|
| 493 | str.Format("%d",abCoilValues[11]);
|
---|
| 494 | m_readStat_C_11.SetWindowText(str);
|
---|
| 495 | str.Format("%d",abCoilValues[12]);
|
---|
| 496 | m_readStat_C_12.SetWindowText(str);
|
---|
| 497 | break;
|
---|
| 498 |
|
---|
| 499 | case 1:
|
---|
| 500 | //holdings : case READ_OUTPUT_REGISTERS:
|
---|
| 501 | // iDataType = DATA_UNSIGNED_16;
|
---|
| 502 | wQuant=125;
|
---|
| 503 | aValues.SetSize(wQuant);
|
---|
| 504 | wAddr=2000;
|
---|
| 505 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, aValues);
|
---|
| 506 |
|
---|
| 507 | str.Format("%d",aValues[0]);
|
---|
| 508 | m_readSVd.SetWindowText(str);
|
---|
| 509 | str.Format("%d",aValues[1]);
|
---|
| 510 | m_readSVfin.SetWindowText(str);
|
---|
| 511 | str.Format("%d",aValues[2]);
|
---|
| 512 | m_readSV1.SetWindowText(str);
|
---|
| 513 | str.Format("%d",aValues[3]);
|
---|
| 514 | m_readSV2.SetWindowText(str);
|
---|
| 515 | str.Format("%d",aValues[4]);
|
---|
| 516 | m_readdtp.SetWindowText(str);
|
---|
| 517 | str.Format("%d",aValues[5]);
|
---|
| 518 | m_readdt.SetWindowText(str);
|
---|
| 519 | str.Format("%d",aValues[20]);
|
---|
| 520 | m_readSVil.SetWindowText(str);
|
---|
| 521 | str.Format("%d",aValues[25]);
|
---|
| 522 | m_readNbal_max.SetWindowText(str);
|
---|
| 523 | str.Format("%d",aValues[26]);
|
---|
| 524 | m_readFr.SetWindowText(str);
|
---|
| 525 | str.Format("%d",aValues[27]);
|
---|
| 526 | m_readN_cur.SetWindowText(str);
|
---|
| 527 | str.Format("%d",aValues[30]);
|
---|
| 528 | m_readNil.SetWindowText(str);
|
---|
| 529 | str.Format("%d",aValues[31]);
|
---|
| 530 | m_readNil_stat.SetWindowText(str);
|
---|
| 531 | str.Format("%d",aValues[34]);
|
---|
| 532 | m_readN_last.SetWindowText(str);
|
---|
| 533 | str.Format("%d",aValues[37]);
|
---|
| 534 | m_readV_cur.SetWindowText(str);
|
---|
| 535 | str.Format("%d",(aValues[40]<<16)+aValues[41]);//2 mots de 16 bits
|
---|
| 536 | m_readTimer.SetWindowText(str);
|
---|
| 537 | str.Format("%d",aValues[42]);
|
---|
| 538 | m_readNbal.SetWindowText(str);
|
---|
| 539 | str.Format("%d",aValues[47]);
|
---|
| 540 | m_readN_Seqcond.SetWindowText(str);
|
---|
| 541 | str.Format("%d",aValues[48]);
|
---|
| 542 | m_readMAP.SetWindowText(str);
|
---|
| 543 | str.Format("%d",aValues[50]);
|
---|
| 544 | m_readNum_C1a.SetWindowText(str);
|
---|
| 545 | str.Format("%d",aValues[51]);
|
---|
| 546 | m_readNum_C1b.SetWindowText(str);
|
---|
| 547 | str.Format("%d",aValues[52]);
|
---|
| 548 | m_readNum_C2a.SetWindowText(str);
|
---|
| 549 | str.Format("%d",aValues[53]);
|
---|
| 550 | m_readNum_C2b.SetWindowText(str);
|
---|
| 551 | str.Format("%d",aValues[54]);
|
---|
| 552 | m_readNum_C3a.SetWindowText(str);
|
---|
| 553 | str.Format("%d",aValues[55]);
|
---|
| 554 | m_readNum_C3b.SetWindowText(str);
|
---|
| 555 | str.Format("%d",aValues[56]);
|
---|
| 556 | m_readNum_C4a.SetWindowText(str);
|
---|
| 557 | str.Format("%d",aValues[57]);
|
---|
| 558 | m_readNum_C4b.SetWindowText(str);
|
---|
| 559 | str.Format("%d",(aValues[58]<<16)+aValues[59]);//2 mots de 16 bits
|
---|
| 560 | m_readTemp_cond_1.SetWindowText(str);
|
---|
| 561 | str.Format("%d",(aValues[60]<<16)+aValues[61]);//2 mots de 16 bits
|
---|
| 562 | m_readTemp_cond_2.SetWindowText(str);
|
---|
| 563 | str.Format("%d",(aValues[62]<<16)+aValues[63]);//2 mots de 16 bits
|
---|
| 564 | m_readTemp_cond_3.SetWindowText(str);
|
---|
| 565 | str.Format("%d",(aValues[64]<<16)+aValues[65]);//2 mots de 16 bits
|
---|
| 566 | m_readTemp_cond_4.SetWindowText(str);
|
---|
| 567 | str.Format("%d",(aValues[66]<<16)+aValues[67]);//2 mots de 16 bits
|
---|
| 568 | m_readTemp_cond_5.SetWindowText(str);
|
---|
| 569 | str.Format("%d",(aValues[68]<<16)+aValues[69]);//2 mots de 16 bits
|
---|
| 570 | m_readTemp_cond_6.SetWindowText(str);
|
---|
| 571 | str.Format("%d",(aValues[70]<<16)+aValues[71]);//2 mots de 16 bits
|
---|
| 572 | m_readTemp_cond_7.SetWindowText(str);
|
---|
| 573 | str.Format("%d",(aValues[72]<<16)+aValues[73]);//2 mots de 16 bits
|
---|
| 574 | m_readTemp_cond_8.SetWindowText(str);
|
---|
| 575 | str.Format("%d",(aValues[74]<<16)+aValues[75]);//2 mots de 16 bits
|
---|
| 576 | m_readTemp_cond_9.SetWindowText(str);
|
---|
| 577 | str.Format("%d",(aValues[76]<<16)+aValues[77]);//2 mots de 16 bits
|
---|
| 578 | m_readTemp_cond_10.SetWindowText(str);
|
---|
| 579 | str.Format("%d",(aValues[78]<<16)+aValues[79]);//2 mots de 16 bits
|
---|
| 580 | m_readTemp_cond_11.SetWindowText(str);
|
---|
| 581 | str.Format("%d",(aValues[80]<<16)+aValues[81]);//2 mots de 16 bits
|
---|
| 582 | m_readTemp_cond_12.SetWindowText(str);
|
---|
| 583 | break;
|
---|
| 584 |
|
---|
| 585 | case 2:
|
---|
| 586 | //holdings : case READ_OUTPUT_REGISTERS:
|
---|
| 587 | // iDataType = DATA_FLOAT;
|
---|
| 588 | wQuant=17;
|
---|
| 589 | afValues.SetSize(wQuant);
|
---|
| 590 | wAddr=2006;
|
---|
| 591 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, afValues);
|
---|
| 592 |
|
---|
| 593 | str.Format("%g",afValues[0]);
|
---|
| 594 | m_readdP.SetWindowText(str);
|
---|
| 595 | str.Format("%g",afValues[1]);
|
---|
| 596 | m_readdPsecu.SetWindowText(str);
|
---|
| 597 | str.Format("%g",afValues[13]);
|
---|
| 598 | m_readP_last.SetWindowText(str);
|
---|
| 599 | str.Format("%g",afValues[16]);
|
---|
| 600 | m_readPic.SetWindowText(str);
|
---|
| 601 | break;
|
---|
| 602 |
|
---|
| 603 | case 3:
|
---|
| 604 | //holdings : case READ_OUTPUT_REGISTERS:
|
---|
| 605 | // iDataType = DATA_FLOAT;
|
---|
| 606 | wQuant=24;
|
---|
| 607 | afValues.SetSize(wQuant);
|
---|
| 608 | wAddr=2021;
|
---|
| 609 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, afValues);
|
---|
| 610 |
|
---|
| 611 | str.Format("%g",afValues[0]);
|
---|
| 612 | m_readSleil.SetWindowText(str);
|
---|
| 613 | str.Format("%g",afValues[1]);
|
---|
| 614 | m_readSTc.SetWindowText(str);
|
---|
| 615 | str.Format("%g",afValues[7]);
|
---|
| 616 | m_readdPil.SetWindowText(str);
|
---|
| 617 | str.Format("%g",afValues[11]);
|
---|
| 618 | m_readP_cde.SetWindowText(str);
|
---|
| 619 | str.Format("%g",afValues[12]);
|
---|
| 620 | m_readPp.SetWindowText(str);
|
---|
| 621 | break;
|
---|
| 622 |
|
---|
| 623 | case 4:
|
---|
| 624 | //holdings : case READ_OUTPUT_REGISTERS:
|
---|
| 625 | // iDataType = DATA_FLOAT;
|
---|
| 626 | wQuant=24;
|
---|
| 627 | afValues.SetSize(wQuant);
|
---|
| 628 | wAddr=/*2108*/2116;
|
---|
| 629 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, afValues);
|
---|
| 630 |
|
---|
| 631 | //Pi_max
|
---|
| 632 | for (int i=0;i < 12;i++)
|
---|
| 633 | {
|
---|
| 634 | str.Format("%g",afValues[i]);
|
---|
| 635 | parameters->SetItemText(i,4,str);
|
---|
| 636 | }
|
---|
| 637 | //Pi_min
|
---|
| 638 | for (int i=12;i < 24;i++)
|
---|
| 639 | {
|
---|
| 640 | str.Format("%g",afValues[i]);
|
---|
| 641 | parameters->SetItemText(i-12,5,str);
|
---|
| 642 | }
|
---|
| 643 | break;
|
---|
| 644 |
|
---|
| 645 | case 5:
|
---|
| 646 | //holdings : case READ_OUTPUT_REGISTERS:
|
---|
| 647 | // iDataType = DATA_UNSIGNED_16;
|
---|
| 648 | wQuant=125;
|
---|
| 649 | aValues.SetSize(wQuant);
|
---|
| 650 | wAddr=2080;
|
---|
| 651 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, aValues);
|
---|
| 652 | //Ln
|
---|
| 653 | for (int i=0;i < 12;i++)
|
---|
| 654 | {
|
---|
| 655 | str.Format("%d",aValues[i]);
|
---|
| 656 | parameters->SetItemText(i,1,str);
|
---|
| 657 | }
|
---|
| 658 | //Tn_max
|
---|
| 659 | for (int i=12;i < 24;i++)
|
---|
| 660 | {
|
---|
| 661 | str.Format("%d",aValues[i]);
|
---|
| 662 | parameters->SetItemText(i-12,3,str);
|
---|
| 663 | }
|
---|
| 664 | //Tp_max : 12 mots de 16 bits ????
|
---|
| 665 | for (int i=24;i < 36;i++)
|
---|
| 666 | {
|
---|
| 667 | str.Format("%d",aValues[i]);
|
---|
| 668 | parameters->SetItemText(i-24,2,str);
|
---|
| 669 | }
|
---|
| 670 | //vacuum
|
---|
| 671 | for (int i=90;i < 102;i++)
|
---|
| 672 | {
|
---|
| 673 | str.Format("%d",aValues[i]);
|
---|
| 674 | vacuum->SetItemText(i-90,1,str);
|
---|
| 675 | }
|
---|
| 676 | break;
|
---|
| 677 | }
|
---|
| 678 |
|
---|
| 679 | rErrorMessage=pModbus->ErrorMessage(nError);
|
---|
| 680 | return nError;
|
---|
| 681 | }
|
---|
| 682 |
|
---|
| 683 | void CModbucfgView::OnChangeEditInterval()
|
---|
| 684 | {
|
---|
| 685 |
|
---|
| 686 | CString sText;
|
---|
| 687 | DWORD dwInterval=0;
|
---|
| 688 |
|
---|
| 689 | m_edtInterval.GetWindowText(sText);
|
---|
| 690 | dwInterval=DWORD(atol(sText));
|
---|
| 691 |
|
---|
| 692 | // if (dwInterval>10000) {
|
---|
| 693 | // AfxMessageBox("Max. Interval is 10000 ms");
|
---|
| 694 | if ((dwInterval>10000) || (dwInterval<200)) {
|
---|
| 695 | AfxMessageBox("Max. is 10000 ms and Min. is 200 ms");
|
---|
| 696 | dwInterval=10000;
|
---|
| 697 | sText.Format("%d",dwInterval);
|
---|
| 698 | m_edtInterval.SetWindowText(sText);
|
---|
| 699 | return;
|
---|
| 700 | }
|
---|
| 701 |
|
---|
| 702 | SetCycleTime(int(dwInterval));
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 | void CModbucfgView::OnCmdWrite()
|
---|
| 706 | {
|
---|
| 707 | BYTE byDevice=0;
|
---|
| 708 | WORD wValue=0;
|
---|
| 709 | WORD wAddr=0;
|
---|
| 710 | CModbus* pModbus=GetConnection();
|
---|
| 711 | WORD nError=CModbus::ERR_OK;
|
---|
| 712 | CString strValue;
|
---|
| 713 | CString sVal;
|
---|
| 714 | CWaitCursor WaitCursor;
|
---|
| 715 | double dValue=0.0;
|
---|
| 716 |
|
---|
| 717 | WORD wQuant, wIndex;
|
---|
| 718 |
|
---|
| 719 | if (NULL==pModbus) {
|
---|
| 720 | return;
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | m_edtValue.GetWindowText(strValue);
|
---|
| 724 | sVal= strValue;
|
---|
| 725 | wValue = (WORD)atoi(strValue);
|
---|
| 726 |
|
---|
| 727 | m_edtDevice.GetWindowText(strValue);
|
---|
| 728 | byDevice = (BYTE)atoi(strValue);
|
---|
| 729 |
|
---|
| 730 | m_edtWriteAddr.GetWindowText(strValue);
|
---|
| 731 | wAddr = (WORD)atoi(strValue);
|
---|
| 732 |
|
---|
| 733 | m_edtQuant2.GetWindowText(strValue);
|
---|
| 734 | wQuant=(BYTE)(atoi(strValue));
|
---|
| 735 |
|
---|
| 736 | m_edtIndex.GetWindowText(strValue);
|
---|
| 737 | wIndex=(BYTE)(atoi(strValue));
|
---|
| 738 |
|
---|
| 739 | switch (m_cboWriteFunctions.GetCurSel()) {
|
---|
| 740 |
|
---|
| 741 | case PRESET_SINGLE_REGISTER:
|
---|
| 742 |
|
---|
| 743 | switch(m_cboDataType.GetCurSel()) {
|
---|
| 744 |
|
---|
| 745 | case DATA_CHAR:
|
---|
| 746 | sVal.TrimLeft();
|
---|
| 747 | if (sVal.GetLength()>0) {
|
---|
| 748 | nError=pModbus->PresetSingleRegister(byDevice,wAddr,WORD(sVal[0]));
|
---|
| 749 | }
|
---|
| 750 | break;
|
---|
| 751 | case DATA_SIGNED_16:
|
---|
| 752 | case DATA_UNSIGNED_16:
|
---|
| 753 | if (sVal.GetLength()>0) {
|
---|
| 754 | nError=pModbus->PresetSingleRegister(byDevice,wAddr,WORD(atoi(sVal)));
|
---|
| 755 | }
|
---|
| 756 | break;
|
---|
| 757 | case DATA_FLOAT:
|
---|
| 758 | nError=pModbus->PresetSingleRegister(byDevice,wAddr,float(atof(sVal)));
|
---|
| 759 | break;
|
---|
| 760 | case DATA_FLOAT_REVERSE:
|
---|
| 761 | nError=pModbus->PresetSingleRegister(byDevice,wAddr,float(atof(sVal)),CModbus::REAL_REVERSE);
|
---|
| 762 | break;
|
---|
| 763 | case DATA_DOUBLE:
|
---|
| 764 | nError=pModbus->PresetSingleRegister(byDevice,wAddr,double(atof(sVal)));
|
---|
| 765 |
|
---|
| 766 | break;
|
---|
| 767 | case DATA_DOUBLE_REVERSE:
|
---|
| 768 | nError=pModbus->PresetSingleRegister(byDevice,wAddr,double(atof(sVal)),CModbus::REAL_REVERSE);
|
---|
| 769 | break;
|
---|
| 770 | }
|
---|
| 771 | if(nError!=CModbus::ERR_OK){
|
---|
| 772 | WaitCursor.Restore();
|
---|
| 773 | AfxMessageBox(pModbus->ErrorMessage(nError));
|
---|
| 774 | }
|
---|
| 775 | break;
|
---|
| 776 |
|
---|
| 777 | case FORCE_SINGLE_COIL:
|
---|
| 778 | nError=pModbus->ForceSingleCoil(byDevice,wAddr,(BOOL)wValue);
|
---|
| 779 | if(nError!=CModbus::ERR_OK){
|
---|
| 780 | WaitCursor.Restore();
|
---|
| 781 | AfxMessageBox(pModbus->ErrorMessage(nError));
|
---|
| 782 | }
|
---|
| 783 | break;
|
---|
| 784 |
|
---|
| 785 | case WRITE_MULTIPLE_REGISTERS:
|
---|
| 786 | {
|
---|
| 787 | //controle spin
|
---|
| 788 | CSpinButtonCtrl* pSpin=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2);
|
---|
| 789 |
|
---|
| 790 | switch(m_cboDataType.GetCurSel()) {
|
---|
| 791 | case DATA_CHAR:
|
---|
| 792 | sVal.TrimLeft();
|
---|
| 793 | if (sVal.GetLength()>0) {
|
---|
| 794 | m_sValueMultiple.SetAt(wIndex,wValue);
|
---|
| 795 | nError=pModbus->PresetMultipleRegisters(byDevice,wAddr,wQuant,m_sValueMultiple);
|
---|
| 796 | }
|
---|
| 797 | break;
|
---|
| 798 | case DATA_SIGNED_16:
|
---|
| 799 | case DATA_UNSIGNED_16:
|
---|
| 800 | if (sVal.GetLength()>0) {
|
---|
| 801 | m_wValueMultiple.SetAt(wIndex,wValue);
|
---|
| 802 | nError=pModbus->PresetMultipleRegisters(byDevice,wAddr,wQuant,m_wValueMultiple);
|
---|
| 803 | }
|
---|
| 804 | break;
|
---|
| 805 | case DATA_FLOAT:
|
---|
| 806 | m_fValueMultiple.SetAt(wIndex,wValue);
|
---|
| 807 | nError=pModbus->PresetMultipleRegisters(byDevice,wAddr,wQuant,m_fValueMultiple);
|
---|
| 808 | break;
|
---|
| 809 | case DATA_FLOAT_REVERSE:
|
---|
| 810 | m_fValueMultiple.SetAt(wIndex,wValue);
|
---|
| 811 | nError=pModbus->PresetMultipleRegisters(byDevice,wAddr,wQuant,m_fValueMultiple,CModbus::REAL_REVERSE);
|
---|
| 812 | break;
|
---|
| 813 | case DATA_DOUBLE:
|
---|
| 814 | m_dValueMultiple.SetAt(wIndex,wValue);
|
---|
| 815 | nError=pModbus->PresetMultipleRegisters(byDevice,wAddr,wQuant,m_dValueMultiple);
|
---|
| 816 | break;
|
---|
| 817 | case DATA_DOUBLE_REVERSE:
|
---|
| 818 | m_dValueMultiple.SetAt(wIndex,wValue);
|
---|
| 819 | nError=pModbus->PresetMultipleRegisters(byDevice,wAddr,wQuant,m_dValueMultiple,CModbus::REAL_REVERSE);
|
---|
| 820 | break;
|
---|
| 821 | }
|
---|
| 822 | if(nError!=CModbus::ERR_OK){
|
---|
| 823 | WaitCursor.Restore();
|
---|
| 824 | AfxMessageBox(pModbus->ErrorMessage(nError));
|
---|
| 825 | }
|
---|
| 826 | }
|
---|
| 827 | break;
|
---|
| 828 |
|
---|
| 829 | case WRITE_MULTIPLE_COILS:
|
---|
| 830 | {
|
---|
| 831 | //controle spin
|
---|
| 832 | CSpinButtonCtrl* pSpin=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2);
|
---|
| 833 | // pSpin->SetRange(0,100);//plage du control : 0-100
|
---|
| 834 |
|
---|
| 835 | m_bValueMultiple.SetAt(wIndex,((wValue!=0)?1:0));
|
---|
| 836 |
|
---|
| 837 | nError=pModbus->ForceMultipleCoils(byDevice,wAddr,wQuant,m_bValueMultiple);
|
---|
| 838 | if(nError!=CModbus::ERR_OK){
|
---|
| 839 | WaitCursor.Restore();
|
---|
| 840 | AfxMessageBox(pModbus->ErrorMessage(nError));
|
---|
| 841 | }
|
---|
| 842 | }
|
---|
| 843 | break;
|
---|
| 844 |
|
---|
| 845 | }
|
---|
| 846 |
|
---|
| 847 | }
|
---|
| 848 |
|
---|
| 849 | CModbus* CModbucfgView::GetConnection()
|
---|
| 850 | {
|
---|
| 851 |
|
---|
| 852 | int i;
|
---|
| 853 | CModbus* pModbus=NULL;
|
---|
| 854 | CConnection* pConnection=NULL;
|
---|
| 855 | CString sKey;
|
---|
| 856 |
|
---|
| 857 | i=m_cboConnections.GetCurSel();
|
---|
| 858 |
|
---|
| 859 | if (i<0) {
|
---|
| 860 | ASSERT(FALSE);
|
---|
| 861 | pModbus=NULL;
|
---|
| 862 | }
|
---|
| 863 | else {
|
---|
| 864 | m_cboConnections.GetLBText(i,sKey);
|
---|
| 865 |
|
---|
| 866 | if (gConnections.Lookup(sKey,pConnection)) {
|
---|
| 867 |
|
---|
| 868 | pModbus=pConnection->m_pModbus;
|
---|
| 869 | }
|
---|
| 870 | else {
|
---|
| 871 | ASSERT(FALSE);
|
---|
| 872 | pModbus=NULL;
|
---|
| 873 | }
|
---|
| 874 | }
|
---|
| 875 |
|
---|
| 876 | return pModbus;
|
---|
| 877 | }
|
---|
| 878 |
|
---|
| 879 | void CModbucfgView::OnCbnSelchangeCboReadFunction()
|
---|
| 880 | {
|
---|
| 881 | // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 882 | }
|
---|
| 883 |
|
---|
| 884 | void CModbucfgView::OnCbnSelchangeCboWriteFunction()
|
---|
| 885 | {
|
---|
| 886 | // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 887 | }
|
---|
| 888 |
|
---|
| 889 |
|
---|
| 890 | void CModbucfgView::OnAppMemMap()
|
---|
| 891 | {
|
---|
| 892 | // TODO : ajoutez ici le code de votre gestionnaire de commande
|
---|
| 893 | AfxMessageBox(_T("modbus memory map : \n\n -holding registers adr:0x2000 qty:300\n-coils adr:0x3000 qty:100\n-discrete inputs adr:0x1000 qty:4\n-input registers adr:0x4000 qty:4"));
|
---|
| 894 | }
|
---|
| 895 |
|
---|
| 896 | void CModbucfgView::OnEnChangeEditQuant()
|
---|
| 897 | {
|
---|
| 898 | // TODO : S'il s'agit d'un contrôle RICHEDIT, le contrôle
|
---|
| 899 | // n'enverra la notification que si vous substituez la fonction __super::OnInitDialog()
|
---|
| 900 | // et l'appel CRichEditCtrl().SetEventMask()
|
---|
| 901 | // par l'indicateur ENM_CHANGE assorti de l'opérateur OR dans le masque.
|
---|
| 902 |
|
---|
| 903 | // TODO : Ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 904 | }
|
---|
| 905 |
|
---|
| 906 | void CModbucfgView::OnEnChangeEditAddr()
|
---|
| 907 | {
|
---|
| 908 | // TODO : S'il s'agit d'un contrôle RICHEDIT, le contrôle
|
---|
| 909 | // n'enverra la notification que si vous substituez la fonction __super::OnInitDialog()
|
---|
| 910 | // et l'appel CRichEditCtrl().SetEventMask()
|
---|
| 911 | // par l'indicateur ENM_CHANGE assorti de l'opérateur OR dans le masque.
|
---|
| 912 |
|
---|
| 913 | // TODO : Ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 914 | }
|
---|
| 915 |
|
---|
| 916 | void CModbucfgView::OnEnChangeEditQuant2()
|
---|
| 917 | {
|
---|
| 918 | // TODO : S'il s'agit d'un contrôle RICHEDIT, le contrôle
|
---|
| 919 | // n'enverra la notification que si vous substituez la fonction __super::OnInitDialog()
|
---|
| 920 | // et l'appel CRichEditCtrl().SetEventMask()
|
---|
| 921 | // par l'indicateur ENM_CHANGE assorti de l'opérateur OR dans le masque.
|
---|
| 922 |
|
---|
| 923 | // TODO : Ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 924 | }
|
---|
| 925 |
|
---|
| 926 | void CModbucfgView::OnLbnSelchangeList5()
|
---|
| 927 | {
|
---|
| 928 | // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 929 | }
|
---|
| 930 |
|
---|
| 931 | void CModbucfgView::OnLbnSelchangeLstValues()
|
---|
| 932 | {
|
---|
| 933 | // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 934 | }
|
---|
| 935 |
|
---|
| 936 | void CModbucfgView::OnEnChangeEditAddrWri()
|
---|
| 937 | {
|
---|
| 938 | // TODO : S'il s'agit d'un contrôle RICHEDIT, le contrôle
|
---|
| 939 | // n'enverra la notification que si vous substituez la fonction __super::OnInitDialog()
|
---|
| 940 | // et l'appel CRichEditCtrl().SetEventMask()
|
---|
| 941 | // par l'indicateur ENM_CHANGE assorti de l'opérateur OR dans le masque.
|
---|
| 942 |
|
---|
| 943 | // TODO : Ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 944 | }
|
---|
| 945 |
|
---|
| 946 | void CModbucfgView::OnEnChangeEditValue()
|
---|
| 947 | {
|
---|
| 948 | // TODO : S'il s'agit d'un contrôle RICHEDIT, le contrôle
|
---|
| 949 | // n'enverra la notification que si vous substituez la fonction __super::OnInitDialog()
|
---|
| 950 | // et l'appel CRichEditCtrl().SetEventMask()
|
---|
| 951 | // par l'indicateur ENM_CHANGE assorti de l'opérateur OR dans le masque.
|
---|
| 952 |
|
---|
| 953 | // TODO : Ajoutez ici le code de votre gestionnaire de notification de contrôle
|
---|
| 954 | }
|
---|
| 955 |
|
---|
| 956 |
|
---|
| 957 |
|
---|
| 958 | void CModbucfgView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
|
---|
| 959 | {
|
---|
| 960 | // TODO : ajoutez ici le code de votre gestionnaire de messages et/ou les paramètres par défaut des appels
|
---|
| 961 |
|
---|
| 962 | if (nSBCode == SB_ENDSCROLL)
|
---|
| 963 | {
|
---|
| 964 | return ;//rejeter les messages non validess
|
---|
| 965 | }
|
---|
| 966 | //treiter uniquement les messagse de défilement de IDC_SPIN2)
|
---|
| 967 | if (pScrollBar->GetDlgCtrlID()==IDC_SPIN2)
|
---|
| 968 | {
|
---|
| 969 | CString strValue;
|
---|
| 970 | strValue.Format("%d",(int)nPos);
|
---|
| 971 | ((CSpinButtonCtrl*)pScrollBar)->GetBuddy()->SetWindowText(strValue);
|
---|
| 972 | }
|
---|
| 973 |
|
---|
| 974 | __super::OnVScroll(nSBCode, nPos, pScrollBar);
|
---|
| 975 | }
|
---|
| 976 |
|
---|
| 977 |
|
---|
| 978 | void CModbucfgView::OnCmdRead()
|
---|
| 979 | {
|
---|
| 980 | ldiv_t div_result;
|
---|
| 981 | float fUpdateSpeed;
|
---|
| 982 | DWORD dwTime;
|
---|
| 983 | CString str;
|
---|
| 984 | WORD nError;
|
---|
| 985 |
|
---|
| 986 | int iNumLoops=10;
|
---|
| 987 |
|
---|
| 988 |
|
---|
| 989 | fUpdateSpeed=0.0;
|
---|
| 990 |
|
---|
| 991 | if ((m_cboReadFunctions.GetCurSel()>=LOOP_BACK_TEST)&&
|
---|
| 992 | (m_cboReadFunctions.GetCurSel()<=READ_INPUT_STATUS)){
|
---|
| 993 |
|
---|
| 994 | m_dwCount++;
|
---|
| 995 | nError=ExecuteCmdReadFunction(m_cboReadFunctions.GetCurSel(),dwTime,str);
|
---|
| 996 | m_dwSum +=dwTime;
|
---|
| 997 |
|
---|
| 998 | div_result = ldiv(m_dwCount,iNumLoops);
|
---|
| 999 |
|
---|
| 1000 | if (CModbus::ERR_OK!=nError){
|
---|
| 1001 | m_dwErrors++;
|
---|
| 1002 | }
|
---|
| 1003 |
|
---|
| 1004 | if (0==div_result.rem){
|
---|
| 1005 | fUpdateSpeed=(float)(iNumLoops*1000)/(float)m_dwSum;
|
---|
| 1006 | m_dwSum=0;
|
---|
| 1007 | }
|
---|
| 1008 | else {
|
---|
| 1009 | fUpdateSpeed=(float)(1*1000)/(float)dwTime;
|
---|
| 1010 | }
|
---|
| 1011 |
|
---|
| 1012 | m_staError.SetWindowText(str);
|
---|
| 1013 | str.Format("%d Errors=%d %4.2f(Up./s) ",m_dwCount,m_dwErrors,fUpdateSpeed);
|
---|
| 1014 | m_statStatus.SetWindowText(str);
|
---|
| 1015 | }
|
---|
| 1016 |
|
---|
| 1017 | }
|
---|
| 1018 |
|
---|
| 1019 | WORD CModbucfgView::ExecuteCmdReadFunction(int iFunction,DWORD& dwTime, CString& rErrorMessage)
|
---|
| 1020 | {
|
---|
| 1021 | CModbus* pModbus;
|
---|
| 1022 | CShortArray aValues;
|
---|
| 1023 | CByteArray abCoilValues;
|
---|
| 1024 |
|
---|
| 1025 | CFloatArray afValues;
|
---|
| 1026 | CDblArray adValues;
|
---|
| 1027 |
|
---|
| 1028 | CString str;
|
---|
| 1029 | CString sAux;
|
---|
| 1030 | WORD nError;
|
---|
| 1031 | int i;
|
---|
| 1032 | BOOL bRegisters;
|
---|
| 1033 | DWORD dwStart;
|
---|
| 1034 | CString sKey;
|
---|
| 1035 | CConnection* pConnection =NULL;
|
---|
| 1036 | BYTE byDevice;
|
---|
| 1037 | WORD wQuant;
|
---|
| 1038 | WORD wAddr;
|
---|
| 1039 | int nIndex;
|
---|
| 1040 | int nPreviusCount;
|
---|
| 1041 | int iDataType;
|
---|
| 1042 |
|
---|
| 1043 | i=m_cboConnections.GetCurSel();
|
---|
| 1044 |
|
---|
| 1045 | iDataType= m_cboDataType.GetCurSel();
|
---|
| 1046 |
|
---|
| 1047 | if (i<0) {
|
---|
| 1048 | return 0;
|
---|
| 1049 | }
|
---|
| 1050 | else {
|
---|
| 1051 | m_cboConnections.GetLBText(i,sKey);
|
---|
| 1052 |
|
---|
| 1053 | if (gConnections.Lookup(sKey,pConnection)) {
|
---|
| 1054 |
|
---|
| 1055 | pModbus=pConnection->m_pModbus;
|
---|
| 1056 | }
|
---|
| 1057 | else {
|
---|
| 1058 | ASSERT(FALSE);
|
---|
| 1059 | return 0;
|
---|
| 1060 | }
|
---|
| 1061 | }
|
---|
| 1062 |
|
---|
| 1063 | m_edtDevice.GetWindowText(str);
|
---|
| 1064 |
|
---|
| 1065 | byDevice=BYTE(atoi(str));
|
---|
| 1066 |
|
---|
| 1067 | m_edtQuant.GetWindowText(str);
|
---|
| 1068 | wQuant=BYTE(atoi(str));
|
---|
| 1069 |
|
---|
| 1070 | m_edtReadAddr.GetWindowText(str);
|
---|
| 1071 | wAddr=WORD(atoi(str));
|
---|
| 1072 |
|
---|
| 1073 | switch (iFunction) {
|
---|
| 1074 |
|
---|
| 1075 | case LOOP_BACK_TEST:
|
---|
| 1076 | dwStart=::timeGetTime();
|
---|
| 1077 | nError=pModbus->LoopbackTest(byDevice);
|
---|
| 1078 | dwTime=::timeGetTime()-dwStart;
|
---|
| 1079 | str="";
|
---|
| 1080 | bRegisters=FALSE;
|
---|
| 1081 | break;
|
---|
| 1082 |
|
---|
| 1083 | case READ_OUTPUT_REGISTERS:
|
---|
| 1084 | dwStart=::timeGetTime();
|
---|
| 1085 | switch (iDataType) {
|
---|
| 1086 | case DATA_CHAR:
|
---|
| 1087 | case DATA_SIGNED_16:
|
---|
| 1088 | case DATA_UNSIGNED_16:
|
---|
| 1089 | aValues.SetSize(wQuant);
|
---|
| 1090 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, aValues);
|
---|
| 1091 | break;
|
---|
| 1092 | case DATA_FLOAT:
|
---|
| 1093 | afValues.SetSize(wQuant);
|
---|
| 1094 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, afValues);
|
---|
| 1095 | break;
|
---|
| 1096 | case DATA_FLOAT_REVERSE:
|
---|
| 1097 | afValues.SetSize(wQuant);
|
---|
| 1098 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, afValues,CModbus::REAL_REVERSE);
|
---|
| 1099 | break;
|
---|
| 1100 | case DATA_DOUBLE:
|
---|
| 1101 | adValues.SetSize(wQuant);
|
---|
| 1102 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, adValues);
|
---|
| 1103 | break;
|
---|
| 1104 | case DATA_DOUBLE_REVERSE:
|
---|
| 1105 | adValues.SetSize(wQuant);
|
---|
| 1106 | nError=pModbus->ReadOutputRegisters(byDevice,wAddr,wQuant, adValues,CModbus::REAL_REVERSE);
|
---|
| 1107 | break;
|
---|
| 1108 | }
|
---|
| 1109 | dwTime=::timeGetTime()-dwStart;
|
---|
| 1110 | bRegisters=TRUE;
|
---|
| 1111 | break;
|
---|
| 1112 |
|
---|
| 1113 | case READ_INPUT_REGISTERS:
|
---|
| 1114 | dwStart=::timeGetTime();
|
---|
| 1115 | switch (iDataType) {
|
---|
| 1116 | case DATA_CHAR:
|
---|
| 1117 | case DATA_SIGNED_16:
|
---|
| 1118 | case DATA_UNSIGNED_16:
|
---|
| 1119 | aValues.SetSize(wQuant);
|
---|
| 1120 | nError=pModbus->ReadInputRegisters(byDevice,wAddr,wQuant, aValues);
|
---|
| 1121 | break;
|
---|
| 1122 | case DATA_FLOAT:
|
---|
| 1123 | afValues.SetSize(wQuant);
|
---|
| 1124 | nError=pModbus->ReadInputRegisters(byDevice,wAddr,wQuant, afValues);
|
---|
| 1125 | break;
|
---|
| 1126 | case DATA_FLOAT_REVERSE:
|
---|
| 1127 | afValues.SetSize(wQuant);
|
---|
| 1128 | nError=pModbus->ReadInputRegisters(byDevice,wAddr,wQuant, afValues,CModbus::REAL_REVERSE);
|
---|
| 1129 | break;
|
---|
| 1130 | case DATA_DOUBLE:
|
---|
| 1131 | adValues.SetSize(wQuant);
|
---|
| 1132 | nError=pModbus->ReadInputRegisters(byDevice,wAddr,wQuant, adValues);
|
---|
| 1133 | break;
|
---|
| 1134 | case DATA_DOUBLE_REVERSE:
|
---|
| 1135 | adValues.SetSize(wQuant);
|
---|
| 1136 | nError=pModbus->ReadInputRegisters(byDevice,wAddr,wQuant, adValues,CModbus::REAL_REVERSE);
|
---|
| 1137 | break;
|
---|
| 1138 | }
|
---|
| 1139 | dwTime=::timeGetTime()-dwStart;
|
---|
| 1140 | bRegisters=TRUE;
|
---|
| 1141 | break;
|
---|
| 1142 |
|
---|
| 1143 | case READ_OUTPUT_STATUS:
|
---|
| 1144 | dwStart=::timeGetTime();
|
---|
| 1145 | abCoilValues.SetSize(wQuant);
|
---|
| 1146 | nError=pModbus->ReadOutputStatus(byDevice,wAddr,wQuant, abCoilValues);
|
---|
| 1147 | dwTime=::timeGetTime()-dwStart;
|
---|
| 1148 | bRegisters=FALSE;
|
---|
| 1149 | break;
|
---|
| 1150 |
|
---|
| 1151 | case READ_INPUT_STATUS:
|
---|
| 1152 | dwStart=::timeGetTime();
|
---|
| 1153 | abCoilValues.SetSize(wQuant);
|
---|
| 1154 | nError=pModbus->ReadInputStatus(byDevice,wAddr,wQuant, abCoilValues);
|
---|
| 1155 | dwTime=::timeGetTime()-dwStart;
|
---|
| 1156 | bRegisters=FALSE;
|
---|
| 1157 | break;
|
---|
| 1158 | }
|
---|
| 1159 |
|
---|
| 1160 | nIndex=m_lstValues.GetCurSel();
|
---|
| 1161 | nPreviusCount=m_lstValues.GetCount();
|
---|
| 1162 |
|
---|
| 1163 | m_lstValues.SetRedraw(FALSE);
|
---|
| 1164 |
|
---|
| 1165 | if (bRegisters) {
|
---|
| 1166 | for(i=0;i<wQuant;++i) {
|
---|
| 1167 | switch (iDataType) {
|
---|
| 1168 | case DATA_CHAR:
|
---|
| 1169 | sAux.Format("[%u]=%c 0x%x",wAddr+i,(char)aValues[i],(WORD)aValues[i]);
|
---|
| 1170 | break;
|
---|
| 1171 | case DATA_SIGNED_16:
|
---|
| 1172 | sAux.Format("[%u]=%d 0x%x",wAddr+i,aValues[i],(WORD)aValues[i]);
|
---|
| 1173 | break;
|
---|
| 1174 | case DATA_UNSIGNED_16:
|
---|
| 1175 | sAux.Format("[%u]=%d 0x%x",wAddr+i,(WORD)aValues[i],(WORD)aValues[i]);
|
---|
| 1176 | break;
|
---|
| 1177 | case DATA_FLOAT:
|
---|
| 1178 | case DATA_FLOAT_REVERSE:
|
---|
| 1179 | sAux.Format("[%u]=%g ",wAddr+2*i,afValues[i]);
|
---|
| 1180 | break;
|
---|
| 1181 | case DATA_DOUBLE:
|
---|
| 1182 | case DATA_DOUBLE_REVERSE:
|
---|
| 1183 | sAux.Format("[%u]=%g ",wAddr+4*i,adValues[i]);
|
---|
| 1184 | break;
|
---|
| 1185 | }
|
---|
| 1186 | //sAux.Format("[%u]=%d %d 0x%x ",wAddr+i,aValues[i],(WORD)aValues[i],(WORD)aValues[i]);
|
---|
| 1187 | m_lstValues.DeleteString(i);
|
---|
| 1188 | m_lstValues.InsertString(i,sAux);
|
---|
| 1189 | }
|
---|
| 1190 | }
|
---|
| 1191 | else {
|
---|
| 1192 | for(i=0;i<abCoilValues.GetSize();++i) {
|
---|
| 1193 | sAux.Format("[%u]=%d ",wAddr+i,abCoilValues[i]);
|
---|
| 1194 | m_lstValues.DeleteString(i);
|
---|
| 1195 | m_lstValues.InsertString(i,sAux);
|
---|
| 1196 | }
|
---|
| 1197 | }
|
---|
| 1198 |
|
---|
| 1199 | if (nPreviusCount>wQuant) {
|
---|
| 1200 | for (i=wQuant;i<nPreviusCount;i++){
|
---|
| 1201 | m_lstValues.DeleteString(wQuant);
|
---|
| 1202 | }
|
---|
| 1203 | }
|
---|
| 1204 |
|
---|
| 1205 | if ((nIndex>0)&&(nIndex<m_lstValues.GetCount())) {
|
---|
| 1206 | m_lstValues.SetCurSel(nIndex);
|
---|
| 1207 | }
|
---|
| 1208 |
|
---|
| 1209 | m_lstValues.SetRedraw(TRUE);
|
---|
| 1210 | m_lstValues.Invalidate(FALSE);
|
---|
| 1211 |
|
---|
| 1212 | rErrorMessage=pModbus->ErrorMessage(nError);
|
---|
| 1213 | return nError;
|
---|
| 1214 | }
|
---|
| 1215 |
|
---|
| 1216 | void CModbucfgView::OnEnChangeEdit16()
|
---|
| 1217 | {
|
---|
| 1218 | BYTE byDevice=0;
|
---|
| 1219 | WORD wAddr=2023;
|
---|
| 1220 | CModbus* pModbus=GetConnection();
|
---|
| 1221 | WORD nError=CModbus::ERR_OK;
|
---|
| 1222 | CString str, sVal;
|
---|
| 1223 | CWaitCursor WaitCursor;
|
---|
| 1224 |
|
---|
| 1225 | if (pModbus==NULL)
|
---|
| 1226 | return;
|
---|
| 1227 |
|
---|
| 1228 | m_edtDevice.GetWindowText(str);
|
---|
| 1229 | byDevice = (BYTE)atoi(str);
|
---|
| 1230 |
|
---|
| 1231 | GetDlgItem(IDC_EDIT16)->GetWindowText(sVal);
|
---|
| 1232 | AfxMessageBox("CModbucfgView::OnEnChangeEdit16()");
|
---|
| 1233 | //case DATA_FLOAT:
|
---|
| 1234 | nError=pModbus->PresetSingleRegister(byDevice,wAddr,float(atof(sVal)));
|
---|
| 1235 | if(nError!=CModbus::ERR_OK){
|
---|
| 1236 | WaitCursor.Restore();
|
---|
| 1237 | AfxMessageBox(pModbus->ErrorMessage(nError));
|
---|
| 1238 | }
|
---|
| 1239 | }
|
---|
| 1240 |
|
---|
| 1241 | void CModbucfgView::OnBnClickedButton1()
|
---|
| 1242 | {
|
---|
| 1243 | CString OpenFilter;
|
---|
| 1244 | OpenFilter = "Text File (*.txt)|*.txt||";
|
---|
| 1245 |
|
---|
| 1246 | //créer l'instance avec le constructeur
|
---|
| 1247 | CFileDialog FileOpenDialog(
|
---|
| 1248 | TRUE,//ouverture de la boite de dialogue
|
---|
| 1249 | NULL,
|
---|
| 1250 | NULL,
|
---|
| 1251 | OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,
|
---|
| 1252 | OpenFilter, // filtre
|
---|
| 1253 | AfxGetMainWnd()); // la fenetre parent
|
---|
| 1254 |
|
---|
| 1255 | if(FileOpenDialog.DoModal()==IDOK)//affichage
|
---|
| 1256 | {// ouverture de fichier avec la structure suivante :
|
---|
| 1257 | //SVil Sleil STc Nbal_max Fr N_cur N_Seqcond Num_C(8x)
|
---|
| 1258 | unsigned int wTmpBuf;
|
---|
| 1259 | float fTmpBuf;
|
---|
| 1260 | CWordArray writeParamInit_120;
|
---|
| 1261 | CFloatArray writeParamInit_121;
|
---|
| 1262 | writeParamInit_120.SetSize(100);//pr les adresses modbus
|
---|
| 1263 | writeParamInit_121.SetSize(100);
|
---|
| 1264 | CString str;
|
---|
| 1265 | FILE* pFile = fopen (FileOpenDialog.GetPathName(), "r");
|
---|
| 1266 | if(pFile == NULL)
|
---|
| 1267 | return;
|
---|
| 1268 | /* ptr au debut du fichier*/
|
---|
| 1269 | fseek( pFile, 0L, SEEK_SET );
|
---|
| 1270 | /* lecture a artir du fichier*/
|
---|
| 1271 | fscanf(pFile,"%d ",&wTmpBuf);
|
---|
| 1272 | writeParamInit_120.SetAtGrow(0,wTmpBuf);//SVil
|
---|
| 1273 | fscanf(pFile,"%f ",&fTmpBuf);
|
---|
| 1274 | writeParamInit_121.SetAtGrow(0,fTmpBuf);//Sleil
|
---|
| 1275 | fscanf(pFile,"%f ",&fTmpBuf);
|
---|
| 1276 | writeParamInit_121.SetAtGrow(1,fTmpBuf);//STc
|
---|
| 1277 | for (int i=3;i<14;i++){//nb de mots ds le fichier
|
---|
| 1278 | fscanf(pFile,"%d ",&wTmpBuf);
|
---|
| 1279 | if (i<5)
|
---|
| 1280 | writeParamInit_120.SetAtGrow(i+2,wTmpBuf);//Nbal_max/Fr
|
---|
| 1281 | else if (i==5)
|
---|
| 1282 | writeParamInit_120.SetAtGrow(i+22,wTmpBuf);//NSeq_cond
|
---|
| 1283 | else if (i>5)
|
---|
| 1284 | writeParamInit_120.SetAtGrow(i+24,wTmpBuf);//8xNum_C
|
---|
| 1285 | }
|
---|
| 1286 | fclose(pFile);
|
---|
| 1287 |
|
---|
| 1288 | str.Format("SVil=%d, Sleil=%f NSeqcond=%d",writeParamInit_120[0],writeParamInit_121[0],writeParamInit_120[27]);
|
---|
| 1289 | AfxMessageBox(str);
|
---|
| 1290 |
|
---|
| 1291 | //copie des buffers
|
---|
| 1292 | m_wValueMultiple.Copy( writeParamInit_120 );
|
---|
| 1293 | m_fValueMultiple.Copy( writeParamInit_121 );
|
---|
| 1294 | }
|
---|
| 1295 | }
|
---|
| 1296 |
|
---|
| 1297 | void CModbucfgView::OnBnClickedButton2()
|
---|
| 1298 | {
|
---|
| 1299 | BYTE byDevice=0;
|
---|
| 1300 | WORD wAddr=0;
|
---|
| 1301 | CString strValue;
|
---|
| 1302 | CWaitCursor WaitCursor;
|
---|
| 1303 |
|
---|
| 1304 | WORD wQuant;
|
---|
| 1305 |
|
---|
| 1306 | m_edtDevice.GetWindowText(strValue);
|
---|
| 1307 | byDevice = (BYTE)atoi(strValue);
|
---|
| 1308 |
|
---|
| 1309 | // case DATA_UNSIGNED_16:
|
---|
| 1310 | CModbus* pModbus=GetConnection();
|
---|
| 1311 | WORD nError=CModbus::ERR_OK;
|
---|
| 1312 | if (NULL==pModbus) {
|
---|
| 1313 | return;
|
---|
| 1314 | }
|
---|
| 1315 | wAddr = 2020;
|
---|
| 1316 | wQuant=38;
|
---|
| 1317 | nError=pModbus->PresetMultipleRegisters(byDevice,wAddr,wQuant,m_wValueMultiple);
|
---|
| 1318 |
|
---|
| 1319 | // case DATA_FLOAT:
|
---|
| 1320 | pModbus=GetConnection();
|
---|
| 1321 | if (NULL==pModbus) {
|
---|
| 1322 | return;
|
---|
| 1323 | }
|
---|
| 1324 | wAddr = 2021;
|
---|
| 1325 | wQuant=2;
|
---|
| 1326 | nError=pModbus->PresetMultipleRegisters(byDevice,wAddr,wQuant,m_fValueMultiple);
|
---|
| 1327 |
|
---|
| 1328 | if(nError!=CModbus::ERR_OK){
|
---|
| 1329 | WaitCursor.Restore();
|
---|
| 1330 | AfxMessageBox(pModbus->ErrorMessage(nError));
|
---|
| 1331 | }
|
---|
| 1332 | }
|
---|