From 61deef5cdf96cbfdd6ad45be49e80d597c00ca65 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期二, 24 十二月 2024 08:37:21 +0800 Subject: [PATCH] 2024-12-24 --- MTerm2/MTerm2CommDevView.cpp | 226 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 186 insertions(+), 40 deletions(-) diff --git a/MTerm2/MTerm2CommDevView.cpp b/MTerm2/MTerm2CommDevView.cpp index d146392..00eb853 100644 --- a/MTerm2/MTerm2CommDevView.cpp +++ b/MTerm2/MTerm2CommDevView.cpp @@ -9,6 +9,7 @@ #include "framework.h" #include "MTerm2.h" #include "MTerm2Doc.h" +#include "ChildFrm.h" #include "MTerm2CommDevView.h" @@ -16,23 +17,23 @@ #include <SetupAPI.h> #include "../MyLib/Functions.hpp" #include "../MyLib/UI_Func/UI_Func.hpp" -#include "CAnsiParser.h" -#include "CDataParser1.h" +#include "AnsiParser.h" +#include "DataParser1.h" #include "KLink.h" //#include "../MyLib/SerialCom/SerialCom.hpp" #include <Dbt.h> -#include "CDialogCommSet1.h" -#include "CDialogSysRegSet.h" -#include "CDialogStatusShow.h" -#include "CDialogInfoDisplay.h" +#include "DialogCommSet1.h" +#include "DialogSysRegSet.h" +#include "DialogStatusShow.h" +#include "DialogInfoDisplay.h" -#include "CDialogCoilMon.h" -#include "CDialogDataMon.h" +#include "DialogCoilMon.h" +#include "DialogDataMon.h" -#include "CDialogProgress.h" -#include "CDialogEventLog.h" -#include "CDialogDateTime.h" -#include "CDialogForceIO.h" +#include "DialogProgress.h" +#include "DialogEventLog.h" +#include "DialogDateTime.h" +#include "DialogForceIO.h" #include "HvSerialPort.h" #ifdef _DEBUG @@ -137,8 +138,11 @@ // ON_BN_CLICKED(IDC_BUTTON_CLEAR_STAT, &CMTerm2CommDevView::OnBnClickedButtonClearStat) // ON_BN_CLICKED(IDC_BUTTON_READ, &CMTerm2CommDevView::OnBnClickedButtonRead) // ON_BN_CLICKED(IDC_BUTTON11, &CMTerm2CommDevView::OnBnClickedButton11) -// ON_BN_CLICKED(IDC_BUTTON12, &CMTerm2CommDevView::OnBnClickedButton12) -// ON_BN_CLICKED(IDC_BUTTON13, &CMTerm2CommDevView::OnBnClickedButton13) + ON_BN_CLICKED(IDC_BUTTON12, &CMTerm2CommDevView::OnBnClickedButton12) + ON_BN_CLICKED(IDC_BUTTON13, &CMTerm2CommDevView::OnBnClickedButton13) + ON_BN_CLICKED(IDC_BUTTON31, &CMTerm2CommDevView::OnBnClickedButton31) + ON_BN_CLICKED(IDC_BUTTON2, &CMTerm2CommDevView::OnBnClickedButton2) + ON_BN_CLICKED(IDC_BUTTON3, &CMTerm2CommDevView::OnBnClickedButton3) END_MESSAGE_MAP() @@ -165,7 +169,8 @@ { CFormView::OnInitialUpdate(); // TODO: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫� - +// ResizeParentToFit(); +// ((CChildFrame *)GetParentFrame())->RecalcLayout(); m_bResourceOpened = 0; LoadResourceList(); @@ -237,7 +242,7 @@ // InitCamera(); // InitPlcComm(); // InitAnalyzer(); - SetTimer(1, 50, NULL); //plc + SetTimer(1, 20, NULL); //plc SetTimer(3, 300, NULL); //Analyzer SetTimer(4, 1000, NULL); //Speed; m_static_connect.SetCtlColor(RGB(255, 0, 0)); @@ -270,7 +275,8 @@ // s1.AppendFormat(_T("Total S %8d \r\nTotal R %8d \r\n"), MySerialCom1.TotalSendBytes, MySerialCom1.TotalRecvBytes); s1 += intToString(pDoc->myHvSerialPort1.TotalRecvBytes) + _T("\r\n"); // stepCount++; - static double LastCalTime = GetTimemS(); + + static double LastCalTime = 0; double thisTime = GetTimemS(); if (thisTime - LastCalTime > 500) { @@ -352,6 +358,20 @@ } s2.Append(_T("\r\n")); } + s2.Append(_T("\r\n")); + + for (int i = 8; i < (nCount + 15) / 16; i++) + { + s2.AppendFormat(_T("%3X: "), i * 16); + for (int j = 0; j < 16; j++) + { + s2.AppendFormat(_T("%02X"), pDoc->MyKLink1.MEM.SDB[i * 16 + j]); + if (j == 7) { s2.Append(_T(" ")); } + else { s2.Append(_T(" ")); } + } + s2.Append(_T("\r\n")); + } + // s2.AppendFormat(_T("%d\r\n"), pDoc->MyKLink1.MEM.SDD[5]); nCount = 32; @@ -365,9 +385,9 @@ s1.Empty(); s1.Format(_T("涓绘満\r\n")); - s1.AppendFormat(_T("璺崇嚎 %02X %s 褰撳墠 %02X\r\n"), pDoc->MyKLink1.MEM.SDD[0], intToBinString(pDoc->MyKLink1.MEM.SDD[0]), pDoc->MyKLink1.MEM.SDD[1]); + s1.AppendFormat(_T("00 璺崇嚎 %02X %s 褰撳墠 %02X\r\n"), pDoc->MyKLink1.MEM.SDD[0], intToBinString(pDoc->MyKLink1.MEM.SDD[0]), pDoc->MyKLink1.MEM.SDD[1]); // s1.AppendFormat(_T("褰撳墠璺崇嚎 %02X %s\r\n"), pDoc->MyKLink1.MEM.SDD[1], intToBinString(pDoc->MyKLink1.MEM.SDD[1])); - s1.AppendFormat(_T("Tick璁℃暟 %u \r\n"), pDoc->MyKLink1.MEM.SDD[2]); + s1.AppendFormat(_T("02 Tick璁℃暟 %u \r\n"), pDoc->MyKLink1.MEM.SDD[2]); s1.AppendFormat(_T("03 nRunCount %u \r\n"), pDoc->MyKLink1.MEM.SDD[3]); s1.AppendFormat(_T("04 RunStat %d \r\n"), pDoc->MyKLink1.MEM.SDD[4]); s1.AppendFormat(_T("05 ErrStat %d \r\n"), pDoc->MyKLink1.MEM.SDD[5]); @@ -404,7 +424,7 @@ s3 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S")); s1.Append(s3 + _T("\r\n")); - s1.AppendFormat(_T("12 LastScanTime uS %d \r\n"), pDoc->MyKLink1.MEM.SDD[12]); + s1.AppendFormat(_T("12 LastScanTime uS %u \r\n"), pDoc->MyKLink1.MEM.SDD[12]); s1.AppendFormat(_T("13 ScanTime uS %d \r\n"), pDoc->MyKLink1.MEM.SDD[13]); s1.AppendFormat(_T("14 MinScanTime uS %d \r\n"), pDoc->MyKLink1.MEM.SDD[14]); s1.AppendFormat(_T("15 %d \r\n"), pDoc->MyKLink1.MEM.SDD[15]); @@ -417,17 +437,19 @@ s1.AppendFormat(_T("22 %d \r\n"), pDoc->MyKLink1.MEM.SDD[22]); s1.AppendFormat(_T("23 %d \r\n"), pDoc->MyKLink1.MEM.SDD[23]); - float Vref = 1.215f; - float V33 = Vref * 4096 / pDoc->MyKLink1.MEM.SDT[55]; + float Vref = 1.2f; + float Vcor = (float)pDoc->MyKLink1.MEM.SDT[53] / pDoc->MyKLink1.MEM.SDT[55]; + float V33 = 3.3f * Vcor; - s1.AppendFormat(_T("24 %d %.3f \r\n"), pDoc->MyKLink1.MEM.SDT[48], pDoc->MyKLink1.MEM.SDT[48] * V33 / 4096 * 11); + s1.AppendFormat(_T("24 24V鐢靛帇 %d %.2f V \r\n"), pDoc->MyKLink1.MEM.SDT[48], pDoc->MyKLink1.MEM.SDT[48] * V33 / 4096 * 11); s1.AppendFormat(_T("25 %d \r\n"), pDoc->MyKLink1.MEM.SDT[49]); - s1.AppendFormat(_T("26 %d %.3f \r\n"), pDoc->MyKLink1.MEM.SDT[50], pDoc->MyKLink1.MEM.SDT[50] * V33 / 4096 * 2); + s1.AppendFormat(_T("26 5V 鐢靛帇 %d %.3f V \r\n"), pDoc->MyKLink1.MEM.SDT[50], pDoc->MyKLink1.MEM.SDT[50] * V33 / 4096 * 2); s1.AppendFormat(_T("27 %d \r\n"), pDoc->MyKLink1.MEM.SDT[51]); s1.AppendFormat(_T("28 %d \r\n"), pDoc->MyKLink1.MEM.SDT[52]); s1.AppendFormat(_T("29 %d \r\n"), pDoc->MyKLink1.MEM.SDT[53]); - s1.AppendFormat(_T("30 %d \r\n"), pDoc->MyKLink1.MEM.SDT[54]); - s1.AppendFormat(_T("31 %d %.3f \r\n"), pDoc->MyKLink1.MEM.SDT[55], V33); + float temp = (1430 - pDoc->MyKLink1.MEM.SDT[54]* 0.806f ) / 4.3f + 25; + s1.AppendFormat(_T("30 鑺墖娓╁害 %d %.1f 鈩� \r\n"), pDoc->MyKLink1.MEM.SDT[54],temp); + s1.AppendFormat(_T("31 1.2V鍙傝�� %d 3.3V鐢靛帇 %.3f V \r\n"), pDoc->MyKLink1.MEM.SDT[55], V33); @@ -542,6 +564,7 @@ //DrawPic1(); // MyLogger1.UpdateLogDisplay(0); UpdateDataDisplay(); + UpdateLEDDisplay(); } else if (nIDEvent == 3) { @@ -967,7 +990,7 @@ { DataType = pDoc->MyKLink1.KLDataTypeWX; DCount = 16; - res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, DAddr, &pDoc->MyKLink1.MEM.WXB[DAddr]); + res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &pDoc->MyKLink1.MEM.WXB[DAddr]); nCount = DCount; if (res == pDoc->MyKLink1.KL_OK) { @@ -985,11 +1008,11 @@ ///* //WY - if (nStep == 1) + if (nStep == 0) { DataType = pDoc->MyKLink1.KLDataTypeWY; DCount = 16; - res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, DAddr, &pDoc->MyKLink1.MEM.WYB[DAddr]); + res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &pDoc->MyKLink1.MEM.WYB[DAddr]); nCount = DCount; if (res == pDoc->MyKLink1.KL_OK) { @@ -1005,11 +1028,11 @@ } ///* //WR - if (nStep==2) + if (nStep==0) { DataType = pDoc->MyKLink1.KLDataTypeWR; DCount = 32; - res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, DAddr, &pDoc->MyKLink1.MEM.WRB[DAddr]); + res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &pDoc->MyKLink1.MEM.WRB[DAddr]); nCount = DCount; if (res == pDoc->MyKLink1.KL_OK) { @@ -1024,11 +1047,11 @@ } //*/ //DT - if (nStep == 3) + if (nStep == 1) { DataType = pDoc->MyKLink1.KLDataTypeDT; DCount = 96; - res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, DAddr, &pDoc->MyKLink1.MEM.DTB[DAddr]); + res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &pDoc->MyKLink1.MEM.DTB[DAddr]); nCount = DCount; if (res == pDoc->MyKLink1.KL_OK) { @@ -1044,13 +1067,13 @@ } int ByteAddr = 0; //SDT - if (nStep >= 4 && nStep <= 7) + if (nStep >= 2 && nStep <= 4) { - int nBlock = nStep - 4; + int nBlock = nStep - 2; DataType = pDoc->MyKLink1.KLDataTypeSDT; ByteAddr = nBlock * 128; DCount = 128; - res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, ByteAddr, &pDoc->MyKLink1.MEM.SDB[ByteAddr]); + res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &pDoc->MyKLink1.MEM.SDB[ByteAddr]); nCount = DCount; if (res == pDoc->MyKLink1.KL_OK) { @@ -1067,15 +1090,17 @@ nStep++; // if (nStep == 2) { nStep = 3; } - if (nStep > 7) { nStep = 0; } + if (nStep > 4) { nStep = 0; } + MonitorSuccessCount += nThisSuccessCount; + MonitorFailCount += nThisFailCount; if (nThisFailCount == 0) { - MonitorSuccessCount++; + } else { - MonitorFailCount++; + } } return 0; @@ -1591,7 +1616,7 @@ // s3.Format("%d %d ",recv2length,wCount2);AppendText(s3); s1.Format(_T("R %d(Try %d %d)=%d->"), dNumtoRead, nTryCount, nTryCount2, wCount2); - for (DWORD i = 0; i < 8 && i < wCount2; i++) + for (DWORD i = 0; i < 16 && i < wCount2; i++) { s1.AppendFormat(_T("%02X "), recv1[i]); } @@ -2094,5 +2119,126 @@ int r = pDoc->myHvSerialPort1.Close(); s1.Format(_T("%d %s"), r, pDoc->myHvSerialPort1.m_strResult); SysLog(s1); + + double REPO_RATE(0.0); + REPO_RATE = _tstof(_T("")); + s1.Format(_T("RAPO_RATE = %f \n"), REPO_RATE); + SysLog(s1); + + } +enum enStat +{ + normal=0, + setchn=1, + setvalue=2, + setonoff=3, + +}; +int nStat = 0; +int ntimecount = 0; +#define MaxTimeOut 50 + +int nCurChn = 0; +int nValue[4] = { 100,200,300,400 }; +int LedOn[4] = { 0 }; +int flickTimer = 0; +int CMTerm2CommDevView::UpdateLEDDisplay() +{ + // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. + flickTimer++; + int bHide = 0; + if ((flickTimer & 0x7) > 3) { bHide = 1; } + + CString s1; + s1 = _T("0000"); + + s1.Format(_T("%d%03d"), nCurChn, nValue[nCurChn]); + if (nStat == setchn && bHide) + { + s1.Format(_T(" %03d"), nValue[nCurChn]); + } + if (nStat == setvalue && bHide) + { + s1.Format(_T("%d "),nCurChn); + } + if (nStat == setonoff && bHide) + { + s1.Format(_T(" "), nCurChn); + } + + SetDlgItemText(IDC_EDIT31, s1); + + s1.Format(_T("%d %d %d %d"), LedOn[0], LedOn[1], LedOn[2], LedOn[3]); + SetDlgItemText(IDC_EDIT32, s1); + + ntimecount++; + if (ntimecount >= MaxTimeOut) { nStat = normal; } + return 0; +} + +void CMTerm2CommDevView::OnBnClickedButton31() +{ + // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜 + ntimecount = 0; + if (nStat == setchn) + { + nCurChn++; + if (nCurChn >= 4) { nCurChn = 0; } + } + if (nStat == setvalue) + { + nValue[nCurChn] ++; + if (nValue[nCurChn] > 999) { nValue[nCurChn] = 999; } + } + if (nStat == setonoff) + { + LedOn[nCurChn] =1; + } +} + + +void CMTerm2CommDevView::OnBnClickedButton2() +{ + // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜 + ntimecount = 0; + if (nStat == setchn) + { + nCurChn--; + if (nCurChn <0) { nCurChn = 3; } + } + if (nStat == setvalue) + { + nValue[nCurChn] --; + if (nValue[nCurChn] <= 0) { nValue[nCurChn] = 0; } + } + if (nStat == setonoff) + { + LedOn[nCurChn] = 0; + } +} + + +void CMTerm2CommDevView::OnBnClickedButton3() +{ + // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜 + ntimecount = 0; + if (nStat == normal) + { + nStat = setchn; + } else if (nStat == setchn) + { + nStat = setvalue; + } else if (nStat == setvalue) + { + nStat = setonoff; + } + else if (nStat == setonoff) + { + nStat = setchn; + } + +} + + -- Gitblit v1.9.1