|
// MultiTerminal2Doc.h: CMTerm1Doc 类的接口
|
//
|
|
|
#pragma once
|
//#include "HvSerialPort.h"
|
#include "AnsiParser.h"
|
#include "DataParser1.h"
|
#include "KDefine.h"
|
//#include "KLink.h"
|
#include "KMachine.h"
|
|
#include "../KLink1/KLink.h"
|
|
#pragma comment(lib,"KLink1.lib")
|
|
class CMTerm1Doc : public CDocument
|
{
|
protected: // 仅从序列化创建
|
CMTerm1Doc() noexcept;
|
DECLARE_DYNCREATE(CMTerm1Doc)
|
|
// 特性
|
public:
|
//通讯参数。
|
CAnsiParser MyAnsiParser1;
|
CDataParser1 MyDataParser1;
|
// KLink MyKLink1;
|
// CSerialCom MySerialCom1;
|
// HvSerialPort myHvSerialPort1;
|
KMachine myKMachine1;
|
KLink1 MyKLink1;
|
|
union {
|
unsigned char KBDD[2048];
|
unsigned short KBDT[1024];
|
unsigned char KBDB[2048];
|
};
|
|
union {
|
unsigned char KWLD[2048];
|
unsigned short KWLT[1024];
|
unsigned char KWLB[2048];
|
};
|
|
|
bool m_bCommParamSet = false;
|
int nComPort;
|
int nBaud;
|
CStringA ComSettings;
|
bool m_bOnline = false;
|
bool m_bSimulate = false;
|
bool m_bPlcRunning = false;
|
|
double StartTime;
|
//系统配置文件
|
|
//数据存储区
|
int m_nNum=15;
|
CString m_Str;
|
CString m_sMachineType = _T("KL20N16D");;
|
|
//程序存储
|
CString ProgTxt;
|
|
|
struct stTypeNameDef
|
{
|
int nType;
|
CStringA TypeTxt;
|
};
|
static stTypeNameDef CoilTypeNameDef[];
|
static int nCoilTypeDefCount;
|
|
static stTypeNameDef DataTypeNameDef[];
|
static int nDataTypeDefCount;
|
|
stKMem KMem;
|
|
enum enParamTypes
|
{
|
KLParamCoil,
|
KLParamWord,
|
KLParamNum,
|
|
};
|
struct stOpDef
|
{
|
int nOpType1;
|
CStringA OpTxt;
|
int nParamCount;
|
int nParamType;
|
CStringA ShowTxt;
|
};
|
static stOpDef OpDef[];
|
|
static int nOpDefCount;
|
struct stParam
|
{
|
CStringA sParamStr;
|
int nParamType;
|
int nParamAddr;
|
};
|
|
struct stProg
|
{
|
int nOpType1;
|
int nBinStep;
|
int nParamCount;
|
stParam Params[3];
|
int PairTo;
|
};
|
|
|
struct stCoilAnno
|
{
|
unsigned short nType;
|
unsigned short nAddr;
|
CString sCoilName;
|
CString sAnno;
|
};
|
stCoilAnno mCoilAnnos[10000]=
|
{
|
};
|
|
int nCoilAnnoCount = 0;
|
|
|
|
enum enSection {
|
SectionNone = 0,
|
SectionSysCfg = 1,
|
SectionProg = 2,
|
SectionAnno = 3,
|
SectionCoilList = 4,
|
SectionDataList = 5,
|
};
|
|
struct stSectionDef
|
{
|
int nSectionType;
|
CStringA SectionName;
|
};
|
stSectionDef SectionDef[5]=
|
{
|
{SectionSysCfg,"SYSCFG"},
|
{SectionProg,"PROG"},
|
{SectionAnno,"COMMENT"},
|
{SectionCoilList,"MONCOILLIST"},
|
{SectionDataList,"MONDATALIST"},
|
};
|
int nSectionDefCount = sizeof(SectionDef) / sizeof(stSectionDef);
|
int TxtToSection(CStringA txt);
|
int GetSectionTxt(int nSectionType, CStringA & txt);
|
int ScanSections();
|
|
struct stSection{
|
int nSectionType;
|
int nSectionLineNo;
|
int nLines;
|
};
|
stSection Sections[100] = { 0 };
|
int nSectionCount;
|
|
int GetSectionPos(int nSectionType, int * nSectionLine, int * nSectionLines);
|
|
// 操作
|
public:
|
int TxtToOp(CStringA optxt, int* ParamCount, int* ParamType);
|
int OpToTxt(int nOp, CStringA & OpTxt);
|
int OpToShowTxt(int nOp, CStringA & OpShowTxt);
|
|
int TxtToCoilType(CStringA Typetxt, int* nCoilType, int* CoilAddr);
|
int CoilTypeToTxt(int nType, CStringA & typeTxt);
|
|
int TxtToDataType(CStringA Typetxt, int * nDataType, int* nDataAddr);
|
int DataTypeToTxt(int nType, CStringA & typeTxt);
|
|
int TransLinesToProg(const CStringArray & txtLines, int StartLine = 0, int ProgLines = -1);
|
|
int TransFileToProg(CStringA ProgTxt);
|
int TransToTxt(CStringA &ProgTxt);
|
|
int TransTxtToProg(CStringA ProgTxtA);
|
int ReadAnnoFromTxt(CStringA AnnoTxtA);
|
|
int TransProgToBin();
|
int TransBinToProg();
|
|
|
int LoadFromFile(CString sFilePathName);
|
int SaveToFile(CString sFilePathName);
|
|
stProg Progs[2048] = { 0 };
|
int ProgTrace[2048] = { 0 };
|
int m_nProgSteps = 0;
|
stBinProg1 BinProgs[2000];
|
int nBinProgSteps = 0;
|
|
|
int nScanCount = 0;
|
int GetAnno(unsigned short nType, unsigned short nAddr, CString & sAnno);
|
int SetAnno(CString sCoilName, CString sAnno);
|
int SetAnno(unsigned short nType, unsigned short nAddr, CString sCoilName, CString sAnno);
|
|
// 重写
|
public:
|
virtual BOOL OnNewDocument();
|
virtual void Serialize(CArchive& ar);
|
#ifdef SHARED_HANDLERS
|
virtual void InitializeSearchContent();
|
virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds);
|
#endif // SHARED_HANDLERS
|
|
// 实现
|
public:
|
virtual ~CMTerm1Doc();
|
#ifdef _DEBUG
|
virtual void AssertValid() const;
|
virtual void Dump(CDumpContext& dc) const;
|
#endif
|
|
enum UpdataHint {
|
UpdateAll=0,
|
UpdateProg=1,
|
UpdateStat=2,
|
};
|
protected:
|
|
// 生成的消息映射函数
|
protected:
|
DECLARE_MESSAGE_MAP()
|
|
#ifdef SHARED_HANDLERS
|
// 用于为搜索处理程序设置搜索内容的 Helper 函数
|
void SetSearchContent(const CString& value);
|
#endif // SHARED_HANDLERS
|
public:
|
int SetCommParam();
|
int Connect();
|
int DisConnect();
|
int SendPacket(void * pBuf, int Len);
|
int RecvPacket(void * pBuf, int Len);
|
|
CView * CMTerm1Doc::FindView(CRuntimeClass * pClass);
|
|
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
|
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
|
virtual void OnCloseDocument();
|
|
afx_msg void OnUploadFromPlc();
|
afx_msg void OnOnline();
|
afx_msg void OnUpdateOnline(CCmdUI *pCmdUI);
|
afx_msg void OnOffline();
|
afx_msg void OnUpdateOffline(CCmdUI *pCmdUI);
|
afx_msg void OnPlcRun();
|
afx_msg void OnUpdatePlcRun(CCmdUI *pCmdUI);
|
afx_msg void OnDownloadToPlc();
|
afx_msg void OnUpdateDownloadToPlc(CCmdUI *pCmdUI);
|
afx_msg void OnComunicationSet();
|
afx_msg void OnPlcSysregSet();
|
|
afx_msg void OnMenuViewLds();
|
afx_msg void OnMenuViewBld();
|
afx_msg void OnMenuViewBnl();
|
afx_msg void OnMenuShowConsole();
|
|
afx_msg void OnMenuCommTest();
|
|
int GetCoilValue(int nCoilType, int nCoilAddr);
|
int SetCoilValue(int nCoilType, int nCoilAddr, int nCoilValue);
|
|
int GetVarData(int nDataType, int nDataAddr);
|
int SetVarData(int nDataType, int nDataAddr, int nDataValue);
|
|
|
void OnTimer(UINT_PTR nIDEvent);
|
|
int StartPLC();
|
int StopPLC();
|
|
|
afx_msg void OnSimulate();
|
afx_msg void OnUpdateSimulate(CCmdUI *pCmdUI);
|
int DownloadToPLC();
|
|
int AddMonitorCoil(int nCoilType, int nCoilAddr, int nCount);
|
int AddMonitorData(int nDataType, int nDataAddr, int nDataCount);
|
int ClearMonitor();
|
int DoPLCMonitor();
|
afx_msg void OnMenuStatusShow();
|
afx_msg void OnMenuFactCfg();
|
afx_msg void OnMenuDatetimeSet();
|
afx_msg void OnMenuEventLog();
|
};
|