This commit is contained in:
Namhyeon Go 2016-08-02 00:36:22 +09:00
commit b15cd9a699
67 changed files with 3297 additions and 0 deletions

BIN
.vs/PLCSim2016/v14/.suo Normal file

Binary file not shown.

BIN
Debug/PLCSim2016.exe Normal file

Binary file not shown.

BIN
Debug/PLCSim2016.ilk Normal file

Binary file not shown.

BIN
Debug/PLCSim2016.pdb Normal file

Binary file not shown.

BIN
PLCSim2016.sdf Normal file

Binary file not shown.

28
PLCSim2016.sln Normal file
View File

@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PLCSim2016", "PLCSim2016\PLCSim2016.vcxproj", "{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}.Debug|x64.ActiveCfg = Debug|x64
{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}.Debug|x64.Build.0 = Debug|x64
{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}.Debug|x86.ActiveCfg = Debug|Win32
{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}.Debug|x86.Build.0 = Debug|Win32
{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}.Release|x64.ActiveCfg = Release|x64
{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}.Release|x64.Build.0 = Release|x64
{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}.Release|x86.ActiveCfg = Release|Win32
{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Binary file not shown.

Binary file not shown.

BIN
PLCSim2016/Debug/PLC.obj Normal file

Binary file not shown.

BIN
PLCSim2016/Debug/PLCDlg.obj Normal file

Binary file not shown.

View File

@ -0,0 +1,36 @@
 PLCSim2016Dlg.cpp
c:\program files (x86)\microsoft visual studio 14.0\vc\atlmfc\include\afx.h(38): warning C4996: 'MBCS_Support_Deprecated_In_MFC': MBCS support in MFC is deprecated and may be removed in a future version of MFC.
c:\program files (x86)\microsoft visual studio 14.0\vc\atlmfc\include\afx.h(33): note: 'MBCS_Support_Deprecated_In_MFC' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcsim2016dlg.cpp(26): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\stdio.h(1769): note: 'sprintf' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcsim2016dlg.cpp(27): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\stdio.h(205): note: 'fopen' 선언을 참조하십시오.
PLCDlg.cpp
c:\program files (x86)\microsoft visual studio 14.0\vc\atlmfc\include\afx.h(38): warning C4996: 'MBCS_Support_Deprecated_In_MFC': MBCS support in MFC is deprecated and may be removed in a future version of MFC.
c:\program files (x86)\microsoft visual studio 14.0\vc\atlmfc\include\afx.h(33): note: 'MBCS_Support_Deprecated_In_MFC' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcdlg.cpp(154): warning C4477: 'sprintf' : 서식 문자열 '%s'에 'char *' 형식의 인수가 필요하지만 variadic 인수 1의 형식이 'CString'입니다.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcdlg.cpp(154): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\stdio.h(1769): note: 'sprintf' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcdlg.cpp(155): warning C4477: 'sprintf' : 서식 문자열 '%s'에 'char *' 형식의 인수가 필요하지만 variadic 인수 1의 형식이 'CString'입니다.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcdlg.cpp(155): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\stdio.h(1769): note: 'sprintf' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcdlg.cpp(230): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\stdio.h(1769): note: 'sprintf' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcdlg.cpp(231): warning C4996: '_open': This function or variable may be unsafe. Consider using _sopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\corecrt_io.h(388): note: '_open' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\plcdlg.cpp(242): warning C4996: 'close': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _close. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\corecrt_io.h(457): note: 'close' 선언을 참조하십시오.
IO_SIMULATORDlg.cpp
c:\program files (x86)\microsoft visual studio 14.0\vc\atlmfc\include\afx.h(38): warning C4996: 'MBCS_Support_Deprecated_In_MFC': MBCS support in MFC is deprecated and may be removed in a future version of MFC.
c:\program files (x86)\microsoft visual studio 14.0\vc\atlmfc\include\afx.h(33): note: 'MBCS_Support_Deprecated_In_MFC' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\io_simulatordlg.cpp(46): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\stdio.h(1769): note: 'sprintf' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\io_simulatordlg.cpp(47): warning C4996: '_open': This function or variable may be unsafe. Consider using _sopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\corecrt_io.h(388): note: '_open' 선언을 참조하십시오.
c:\users\user\documents\visual studio 2015\projects\plcsim2016\plcsim2016\io_simulatordlg.cpp(54): warning C4996: 'close': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _close. See online help for details.
c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\corecrt_io.h(457): note: 'close' 선언을 참조하십시오.
코드를 생성하고 있습니다...
건너뛰고 있습니다... (관련된 변경 내용 없음)
cCore.cpp
PLCSim2016.cpp
PLCSim2016.vcxproj -> C:\Users\USER\Documents\Visual Studio 2015\Projects\PLCSim2016\Debug\PLCSim2016.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
Debug|Win32|C:\Users\USER\Documents\Visual Studio 2015\Projects\PLCSim2016\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
PLCSim2016/Debug/cCore.obj Normal file

Binary file not shown.

BIN
PLCSim2016/Debug/lib.obj Normal file

Binary file not shown.

BIN
PLCSim2016/Debug/stdafx.obj Normal file

Binary file not shown.

BIN
PLCSim2016/Debug/vc140.idb Normal file

Binary file not shown.

BIN
PLCSim2016/Debug/vc140.pdb Normal file

Binary file not shown.

BIN
PLCSim2016/IO_SIMULATOR.APS Normal file

Binary file not shown.

127
PLCSim2016/IO_SIMULATOR.cpp Normal file
View File

@ -0,0 +1,127 @@
// IO_SIMULATOR.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "IO_SIMULATOR.h"
#include "IO_SIMULATORDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CIO_SIMULATORDlg* pdlg;
#define OUTPUT_FILE "C:\\PLCSim2016\\output.txt"
int fnReadOutput(char* pBuffer){
FILE* pOutFile;
char sFileName[256];
sprintf(sFileName,"%s",OUTPUT_FILE);
pOutFile = fopen(OUTPUT_FILE,"r");
if(pOutFile != NULL){
fread(pBuffer,1,256,pOutFile);
fclose(pOutFile);
return 0;
}
return -1;
}
VOID CALLBACK MyTimerProcIO(HWND hwnd, UINT iMsg, UINT iTimerID, DWORD dwTime)
{
/* timeup do timer proc */
HWND hWnd;
char strBuf[20];
char sBuffer[256];
memset(sBuffer,0x00,256);
hWnd = GetDlgItem(pdlg->m_hWnd,IDC_STATUS);
GetWindowText(hWnd,strBuf,20);
switch(strBuf[0]){
case '-': SetWindowText(hWnd,"\\"); break;
case '\\': SetWindowText(hWnd,"|"); break;
case '|': SetWindowText(hWnd,"/"); break;
case '/': SetWindowText(hWnd,"-"); break;
default: SetWindowText(hWnd,"-"); break;
}
fnReadOutput(sBuffer);
/*§PŪ OUTPUT ÀÉ*/
for(int i = 0;i < 8;i++){
switch(i){
case 0:
if(sBuffer[i] == 0x31)
pdlg->m_Out0.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out0.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 1:
if(sBuffer[i] == 0x31)
pdlg->m_Out1.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out1.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 2:
if(sBuffer[i] == 0x31)
pdlg->m_Out2.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out2.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 3:
if(sBuffer[i] == 0x31)
pdlg->m_Out3.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out3.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 4:
if(sBuffer[i] == 0x31)
pdlg->m_Out4.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out4.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 5:
if(sBuffer[i] == 0x31)
pdlg->m_Out5.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out5.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 6:
if(sBuffer[i] == 0x31)
pdlg->m_Out6.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out6.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 7:
if(sBuffer[i] == 0x31)
pdlg->m_Out7.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out7.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
}
}
}
BOOL openSimulationModal() {
CIO_SIMULATORDlg dlg;
CIO_SIMULATORDlg* m_pMainWnd;
pdlg = &dlg;
m_pMainWnd = &dlg;
dlg.iTimerHandle = SetTimer(m_pMainWnd->m_hWnd,500,10,MyTimerProcIO);
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

49
PLCSim2016/IO_SIMULATOR.h Normal file
View File

@ -0,0 +1,49 @@
// IO_SIMULATOR.h : main header file for the IO_SIMULATOR application
//
#if !defined(AFX_IO_SIMULATOR_H__1DAAD9B0_F737_4148_8C8D_9FCEB6AB94BC__INCLUDED_)
#define AFX_IO_SIMULATOR_H__1DAAD9B0_F737_4148_8C8D_9FCEB6AB94BC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CIO_SIMULATORApp:
// See IO_SIMULATOR.cpp for the implementation of this class
//
class CIO_SIMULATORApp : public CWinApp
{
public:
CIO_SIMULATORApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CIO_SIMULATORApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CIO_SIMULATORApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_IO_SIMULATOR_H__1DAAD9B0_F737_4148_8C8D_9FCEB6AB94BC__INCLUDED_)

View File

@ -0,0 +1,359 @@
// IO_SIMULATORDlg.cpp : implementation file
//
#include "stdafx.h"
#include "IO_SIMULATOR.h"
#include "IO_SIMULATORDlg.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define INPUT_FILE "C:\\PLCSim2016\\input.txt"
///////////////////////////////////////////////////
BOOL fnSetInputBreakFlag = FALSE;
BOOL closeSimulationModal() {
CIO_SIMULATORDlg dlg;
CIO_SIMULATORDlg* m_pMainWnd;
m_pMainWnd = &dlg;
KillTimer(m_pMainWnd->m_hWnd, 500);
return FALSE;
}
/////////////////////////////////////////////////////
int fnSetInput(int iPos,int iStatus){
int iInputFile;
char sFileName[256];
char sBuffer[3];
sBuffer[0] = 0x30;
sBuffer[1] = 0x31;
sBuffer[2] = 0x00;
sprintf(sFileName,"%s",INPUT_FILE);
iInputFile = _open(sFileName, _O_RDWR , _S_IREAD | _S_IWRITE );
if(iInputFile != -1){
_lseek( iInputFile, iPos, SEEK_SET );
if(iStatus == 1)
_write( iInputFile, &sBuffer[1], 1);
else
_write( iInputFile, &sBuffer[0], 1);
close(iInputFile);
return 0;
}
return -1;
}
/////////////////////////////////////////////////////////////////////////////
// CIO_SIMULATORDlg dialog
CIO_SIMULATORDlg::CIO_SIMULATORDlg(CWnd* pParent /*=NULL*/)
: CDialog(CIO_SIMULATORDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CIO_SIMULATORDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
for (int i = 0; i < 8; i++) {
if (fnSetInputBreakFlag == TRUE) {
break; // Áß´ÜÇؾßÇÒ ½Ã ¸ØÃã
}
fnSetInput(i, 0);
}
}
CIO_SIMULATORDlg::~CIO_SIMULATORDlg() {
fnSetInputBreakFlag = TRUE;
closeSimulationModal();
}
void CIO_SIMULATORDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CIO_SIMULATORDlg)
DDX_Control(pDX, IDC_OUT7, m_Out7);
DDX_Control(pDX, IDC_OUT6, m_Out6);
DDX_Control(pDX, IDC_OUT5, m_Out5);
DDX_Control(pDX, IDC_OUT4, m_Out4);
DDX_Control(pDX, IDC_OUT3, m_Out3);
DDX_Control(pDX, IDC_OUT2, m_Out2);
DDX_Control(pDX, IDC_OUT1, m_Out1);
DDX_Control(pDX, IDC_OUT0, m_Out0);
DDX_Control(pDX, IDC_IN7, m_In7);
DDX_Control(pDX, IDC_IN6, m_In6);
DDX_Control(pDX, IDC_IN5, m_In5);
DDX_Control(pDX, IDC_IN4, m_In4);
DDX_Control(pDX, IDC_IN3, m_In3);
DDX_Control(pDX, IDC_IN2, m_In2);
DDX_Control(pDX, IDC_IN1, m_In1);
DDX_Control(pDX, IDC_IN0, m_In0);
DDX_Control(pDX, IDC_BUTTON8, m_Button8);
DDX_Control(pDX, IDC_BUTTON7, m_Button7);
DDX_Control(pDX, IDC_BUTTON6, m_Button6);
DDX_Control(pDX, IDC_BUTTON5, m_Button5);
DDX_Control(pDX, IDC_BUTTON4, m_Button4);
DDX_Control(pDX, IDC_BUTTON3, m_Button3);
DDX_Control(pDX, IDC_BUTTON2, m_Button2);
DDX_Control(pDX, IDC_BUTTON1, m_Button1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CIO_SIMULATORDlg, CDialog)
//{{AFX_MSG_MAP(CIO_SIMULATORDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIO_SIMULATORDlg message handlers
BOOL CIO_SIMULATORDlg::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
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CIO_SIMULATORDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
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 CIO_SIMULATORDlg::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 CIO_SIMULATORDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CIO_SIMULATORDlg::OnButton1()
{
char strBuffer[256];
m_Button1.GetWindowText(strBuffer,256);
CString str(strBuffer);
if(str == "On"){
str = "Off";
fnSetInput(0,1);
m_Button1.SetWindowText(str);
m_In0.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
}else{
fnSetInput(0,0);
str = "On";
m_Button1.SetWindowText(str);
m_In0.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
}
}
void CIO_SIMULATORDlg::OnButton2()
{
char strBuffer[256];
m_Button2.GetWindowText(strBuffer,256);
CString str(strBuffer);
if(str == "On"){
str = "Off";
fnSetInput(1,1);
m_Button2.SetWindowText(str);
m_In1.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
}else{
str = "On";
fnSetInput(1,0);
m_Button2.SetWindowText(str);
m_In1.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
}
}
void CIO_SIMULATORDlg::OnButton3()
{
char strBuffer[256];
m_Button3.GetWindowText(strBuffer,256);
CString str(strBuffer);
if(str == "On"){
str = "Off";
fnSetInput(2,1);
m_Button3.SetWindowText(str);
m_In2.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
}else{
str = "On";
fnSetInput(2,0);
m_Button3.SetWindowText(str);
m_In2.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
}
}
void CIO_SIMULATORDlg::OnButton4()
{
char strBuffer[256];
m_Button4.GetWindowText(strBuffer,256);
CString str(strBuffer);
if(str == "On"){
str = "Off";
fnSetInput(3,1);
m_Button4.SetWindowText(str);
m_In3.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
}else{
str = "On";
fnSetInput(3,0);
m_Button4.SetWindowText(str);
m_In3.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
}
}
void CIO_SIMULATORDlg::OnButton5()
{
char strBuffer[256];
m_Button5.GetWindowText(strBuffer,256);
CString str(strBuffer);
if(str == "On"){
str = "Off";
fnSetInput(4,1);
m_Button5.SetWindowText(str);
m_In4.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
}else{
str = "On";
fnSetInput(4,0);
m_Button5.SetWindowText(str);
m_In4.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
}
}
void CIO_SIMULATORDlg::OnButton6()
{
char strBuffer[256];
m_Button6.GetWindowText(strBuffer,256);
CString str(strBuffer);
if(str == "On"){
str = "Off";
fnSetInput(5,1);
m_Button6.SetWindowText(str);
m_In5.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
}else{
str = "On";
fnSetInput(5,0);
m_Button6.SetWindowText(str);
m_In5.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
}
}
void CIO_SIMULATORDlg::OnButton7()
{
char strBuffer[256];
m_Button7.GetWindowText(strBuffer,256);
CString str(strBuffer);
if(str == "On"){
str = "Off";
fnSetInput(6,1);
m_Button7.SetWindowText(str);
m_In6.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
}else{
str = "On";
fnSetInput(6,0);
m_Button7.SetWindowText(str);
m_In6.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
}
}
void CIO_SIMULATORDlg::OnButton8()
{
char strBuffer[256];
m_Button8.GetWindowText(strBuffer,256);
CString str(strBuffer);
if(str == "On"){
str = "Off";
fnSetInput(7,1);
m_Button8.SetWindowText(str);
m_In7.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
}else{
str = "On";
fnSetInput(7,0);
m_Button8.SetWindowText(str);
m_In7.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
}
}
void CIO_SIMULATORDlg::OnClose()
{
KillTimer(iTimerHandle);
CDialog::OnClose();
}

View File

@ -0,0 +1,82 @@
// IO_SIMULATORDlg.h : header file
//
#if !defined(AFX_IO_SIMULATORDLG_H__CB857783_7B69_4AA3_949F_6D9AD6AF8B50__INCLUDED_)
#define AFX_IO_SIMULATORDLG_H__CB857783_7B69_4AA3_949F_6D9AD6AF8B50__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CIO_SIMULATORDlg dialog
class CIO_SIMULATORDlg : public CDialog
{
// Construction
public:
CIO_SIMULATORDlg(CWnd* pParent = NULL); // standard constructor
~CIO_SIMULATORDlg(); // Destory
int iTimerHandle;
// Dialog Data
//{{AFX_DATA(CIO_SIMULATORDlg)
enum { IDD = IDD_IO_SIMULATOR_DIALOG };
CStatic m_Out7;
CStatic m_Out6;
CStatic m_Out5;
CStatic m_Out4;
CStatic m_Out3;
CStatic m_Out2;
CStatic m_Out1;
CStatic m_Out0;
CStatic m_In7;
CStatic m_In6;
CStatic m_In5;
CStatic m_In4;
CStatic m_In3;
CStatic m_In2;
CStatic m_In1;
CStatic m_In0;
CButton m_Button8;
CButton m_Button7;
CButton m_Button6;
CButton m_Button5;
CButton m_Button4;
CButton m_Button3;
CButton m_Button2;
CButton m_Button1;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CIO_SIMULATORDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CIO_SIMULATORDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButton1();
afx_msg void OnButton2();
afx_msg void OnButton3();
afx_msg void OnButton4();
afx_msg void OnButton5();
afx_msg void OnButton6();
afx_msg void OnButton7();
afx_msg void OnButton8();
afx_msg void OnClose();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_IO_SIMULATORDLG_H__CB857783_7B69_4AA3_949F_6D9AD6AF8B50__INCLUDED_)

BIN
PLCSim2016/PLC.APS Normal file

Binary file not shown.

74
PLCSim2016/PLC.cpp Normal file
View File

@ -0,0 +1,74 @@
// PLC.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "PLC.h"
#include "PLCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPLCApp
BEGIN_MESSAGE_MAP(CPLCApp, CWinApp)
//{{AFX_MSG_MAP(CPLCApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPLCApp construction
CPLCApp::CPLCApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CPLCApp object
CPLCApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CPLCApp initialization
BOOL CPLCApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CPLCDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

49
PLCSim2016/PLC.h Normal file
View File

@ -0,0 +1,49 @@
// PLC.h : main header file for the PLC application
//
#if !defined(AFX_PLC_H__6379F7BC_4946_4607_B5C9_F8AB3A407A3A__INCLUDED_)
#define AFX_PLC_H__6379F7BC_4946_4607_B5C9_F8AB3A407A3A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CPLCApp:
// See PLC.cpp for the implementation of this class
//
class CPLCApp : public CWinApp
{
public:
CPLCApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPLCApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CPLCApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_PLC_H__6379F7BC_4946_4607_B5C9_F8AB3A407A3A__INCLUDED_)

244
PLCSim2016/PLCDlg.cpp Normal file
View File

@ -0,0 +1,244 @@
// PLCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PLC.h"
#include "PLCDlg.h"
#include ".\\core\\cCore.h"
#include ".\\lib\\lib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPLCDlg dialog
CPLCDlg::CPLCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPLCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPLCDlg)
m_RunString = _T("");
m_EnableTrace = 1;
m_DspLadderFilePath = _T("");
m_DspLogPath = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
pPLC = NULL;
RESETALL();
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPLCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPLCDlg)
DDX_Control(pDX, IDC_RUNSTATE, m_RunState);
DDX_Control(pDX, IDC_STOP, m_STOP);
DDX_Control(pDX, IDC_RUN, m_RUN);
DDX_Text(pDX, IDC_STATUS, m_RunString);
// DDX_Radio(pDX, IDC_RADIO1, m_EnableTrace);
DDX_Text(pDX, IDC_EDIT1, m_DspLadderFilePath);
// DDX_Text(pDX, IDC_EDIT2, m_DspLogPath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPLCDlg, CDialog)
//{{AFX_MSG_MAP(CPLCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RUN, OnRun)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_SELLAD, OnSellad)
// ON_BN_CLICKED(IDC_SETLOG, OnSetlog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPLCDlg message handlers
BOOL CPLCDlg::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
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CPLCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
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 CPLCDlg::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 CPLCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPLCDlg::OnRun()
{
// TODO: Add your control notification handler code here
this->UpdateData(TRUE);
if(sLadderFilePath.GetLength() > 0){
m_DspLadderFilePath = sLadderFilePath;
if(m_EnableTrace == 0 && sLogPath.GetLength() == 0){
MessageBox("TRACE?", "OK?", MB_OK);
}
else{
m_DspLogPath = sLogPath;
pPLC = new cPLCCore();
pPLC->m_Hwnd = this->GetSafeHwnd();
if(m_EnableTrace == 0)
pPLC->bEnableTrace = TRUE;
sprintf(pPLC->sLadderFilePath,"%s",sLadderFilePath);
sprintf(pPLC->sLogPath,"%s",sLogPath);
pPLC->fRUN();
GetDlgItem(IDC_RUN)->EnableWindow(FALSE);
GetDlgItem(IDC_SELLAD)->EnableWindow(FALSE);
/*
GetDlgItem(IDC_SETLOG)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO1)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO2)->EnableWindow(FALSE);
*/
m_RunState.SetIcon(AfxGetApp()->LoadIcon(IDI_RUN));
}
}
else{
MessageBox("Ladder?!!","OK?",MB_OK);
}
}
void CPLCDlg::OnStop()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_RUN)->EnableWindow(TRUE);
GetDlgItem(IDC_SELLAD)->EnableWindow(TRUE);
/*
GetDlgItem(IDC_SETLOG)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO1)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO2)->EnableWindow(TRUE);
*/
if(pPLC != NULL){
pPLC->fSTOP();
delete pPLC;
m_RunState.SetIcon(AfxGetApp()->LoadIcon(IDI_STOP));
pPLC = NULL;
}
}
void CPLCDlg::OnSellad()
{
OPENFILENAME ofn;
char filename[MAX_PATH];
memset(&ofn, 0, sizeof(ofn));
filename[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = this->GetSafeHwnd();
ofn.lpstrFilter = "Ladder file\0*.lad\0";
ofn.lpstrFile = (LPSTR)filename;
ofn.nMaxFile = MAX_PATH;
if(GetOpenFileName(&ofn))
{
sLadderFilePath = filename;
m_DspLadderFilePath = sLadderFilePath;
this->UpdateData(FALSE);
}
}
void CPLCDlg::OnSetlog()
{
char filename[MAX_PATH];
filename[0] = 0;
if(GetPathDialog(this->GetSafeHwnd(),"OnSetlog?",filename))
{
sLogPath=filename;
m_DspLogPath = sLogPath;
this->UpdateData(FALSE);
}
}
void CPLCDlg::RESETALL()
{
int iOutputFile,iPos,iStatus;
char sFileName[256];
char sBuffer[3];
sBuffer[0] = 0x30;
sBuffer[1] = 0x31;
sBuffer[2] = 0x00;
sprintf(sFileName,"%s","output.txt");
iOutputFile = _open(sFileName,_O_RDWR , _S_IREAD | _S_IWRITE );
if(iOutputFile != -1){
for(int i = 0;i < MAX_NUM_OUTPUT;i++){
iPos = i;
_lseek( iOutputFile, iPos, SEEK_SET );
iStatus = 0;
if(iStatus == 1)
_write( iOutputFile, &sBuffer[1], 1);
else
_write( iOutputFile, &sBuffer[0], 1);
}
close(iOutputFile);
}
}

65
PLCSim2016/PLCDlg.h Normal file
View File

@ -0,0 +1,65 @@
// PLCDlg.h : header file
//
#include ".\\core\\cCore.h"
#if !defined(AFX_PLCDLG_H__AC844B41_7C71_4052_B7D5_9F86E36944CF__INCLUDED_)
#define AFX_PLCDLG_H__AC844B41_7C71_4052_B7D5_9F86E36944CF__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CPLCDlg dialog
class CPLCDlg : public CDialog
{
// Construction
public:
void RESETALL();
CPLCDlg(CWnd* pParent = NULL); // standard constructor
~CPLCDlg(){RESETALL();};
// Dialog Data
//{{AFX_DATA(CPLCDlg)
enum { IDD = IDD_PLC_DIALOG };
CStatic m_RunState;
CButton m_STOP;
CButton m_RUN;
CString m_RunString;
int m_EnableTrace;
CString sLadderFilePath;
CString sLogPath;
CString m_DspLadderFilePath;
CString m_DspLogPath;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPLCDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
cPLCCore* pPLC;
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CPLCDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnRun();
afx_msg void OnStop();
afx_msg void OnSellad();
afx_msg void OnSetlog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_PLCDLG_H__AC844B41_7C71_4052_B7D5_9F86E36944CF__INCLUDED_)

BIN
PLCSim2016/PLCSim2016.aps Normal file

Binary file not shown.

95
PLCSim2016/PLCSim2016.cpp Normal file
View File

@ -0,0 +1,95 @@
// PLCSim2016.cpp : 응용 프로그램에 대한 클래스 동작을 정의합니다.
//
#include "stdafx.h"
#include "PLCSim2016.h"
#include "PLCSim2016Dlg.h"
// CPLCSim2016App
BEGIN_MESSAGE_MAP(CPLCSim2016App, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CPLCSim2016App 생성
CPLCSim2016App::CPLCSim2016App()
{
// 다시 시작 관리자 지원
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
// TODO: 여기에 생성 코드를 추가합니다.
// InitInstance에 모든 중요한 초기화 작업을 배치합니다.
}
// 유일한 CPLCSim2016App 개체입니다.
CPLCSim2016App theApp;
// CPLCSim2016App 초기화
BOOL CPLCSim2016App::InitInstance()
{
// 응용 프로그램 매니페스트가 ComCtl32.dll 버전 6 이상을 사용하여 비주얼 스타일을
// 사용하도록 지정하는 경우, Windows XP 상에서 반드시 InitCommonControlsEx()가 필요합니다.
// InitCommonControlsEx()를 사용하지 않으면 창을 만들 수 없습니다.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// 응용 프로그램에서 사용할 모든 공용 컨트롤 클래스를 포함하도록
// 이 항목을 설정하십시오.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
// 대화 상자에 셸 트리 뷰 또는
// 셸 목록 뷰 컨트롤이 포함되어 있는 경우 셸 관리자를 만듭니다.
CShellManager *pShellManager = new CShellManager;
// MFC 컨트롤의 테마를 사용하기 위해 "Windows 원형" 비주얼 관리자 활성화
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
// 표준 초기화
// 이들 기능을 사용하지 않고 최종 실행 파일의 크기를 줄이려면
// 아래에서 필요 없는 특정 초기화
// 루틴을 제거해야 합니다.
// 해당 설정이 저장된 레지스트리 키를 변경하십시오.
// TODO: 이 문자열을 회사 또는 조직의 이름과 같은
// 적절한 내용으로 수정해야 합니다.
SetRegistryKey(_T("로컬 응용 프로그램 마법사에서 생성된 응용 프로그램"));
CPLCSim2016Dlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: 여기에 [확인]을 클릭하여 대화 상자가 없어질 때 처리할
// 코드를 배치합니다.
}
else if (nResponse == IDCANCEL)
{
// TODO: 여기에 [취소]를 클릭하여 대화 상자가 없어질 때 처리할
// 코드를 배치합니다.
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "경고: 대화 상자를 만들지 못했으므로 응용 프로그램이 예기치 않게 종료됩니다.\n");
TRACE(traceAppMsg, 0, "경고: 대화 상자에서 MFC 컨트롤을 사용하는 경우 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS를 수행할 수 없습니다.\n");
}
// 위에서 만든 셸 관리자를 삭제합니다.
if (pShellManager != NULL)
{
delete pShellManager;
}
// 대화 상자가 닫혔으므로 응용 프로그램의 메시지 펌프를 시작하지 않고 응용 프로그램을 끝낼 수 있도록 FALSE를
// 반환합니다.
return FALSE;
}

32
PLCSim2016/PLCSim2016.h Normal file
View File

@ -0,0 +1,32 @@
// PLCSim2016.h : PROJECT_NAME 응용 프로그램에 대한 주 헤더 파일입니다.
//
#pragma once
#ifndef __AFXWIN_H__
#error "PCH에 대해 이 파일을 포함하기 전에 'stdafx.h'를 포함합니다."
#endif
#include "resource.h" // 주 기호입니다.
// CPLCSim2016App:
// 이 클래스의 구현에 대해서는 PLCSim2016.cpp을 참조하십시오.
//
class CPLCSim2016App : public CWinApp
{
public:
CPLCSim2016App();
// 재정의입니다.
public:
virtual BOOL InitInstance();
// 구현입니다.
DECLARE_MESSAGE_MAP()
};
extern CPLCSim2016App theApp;

BIN
PLCSim2016/PLCSim2016.rc Normal file

Binary file not shown.

View File

@ -0,0 +1,236 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{889E8B9E-C480-45DF-B054-1AC3CEEB4F96}</ProjectGuid>
<RootNamespace>PLCSim2016</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0412</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0412</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0412</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0412</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="core\cCore.h" />
<ClInclude Include="IO_SIMULATOR.h" />
<ClInclude Include="IO_SIMULATORDlg.h" />
<ClInclude Include="lib\lib.h" />
<ClInclude Include="PLC.h" />
<ClInclude Include="PLCDlg.h" />
<ClInclude Include="PLCSim2016.h" />
<ClInclude Include="PLCSim2016Dlg.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="core\cCore.cpp" />
<ClCompile Include="IO_SIMULATORDlg.cpp" />
<ClCompile Include="lib\lib.cpp" />
<ClCompile Include="PLCDlg.cpp" />
<ClCompile Include="PLCSim2016.cpp" />
<ClCompile Include="PLCSim2016Dlg.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PLCSim2016.rc" />
</ItemGroup>
<ItemGroup>
<None Include="res\PLCSim2016.rc2" />
</ItemGroup>
<ItemGroup>
<Image Include="res\icon1.ico" />
<Image Include="res\icon2.ico" />
<Image Include="res\icon3.ico" />
<Image Include="res\PLC-system-overview.gif" />
<Image Include="res\PLCSim2016.ico" />
<Image Include="res\run1.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties RESOURCE_FILE="PLCSim2016.rc" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="소스 파일">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="헤더 파일">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="리소스 파일">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="PLCSim2016.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="PLCSim2016Dlg.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="IO_SIMULATORDlg.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="PLCDlg.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="core\cCore.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="lib\lib.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="IO_SIMULATOR.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="PLC.h">
<Filter>헤더 파일</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="PLCSim2016.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="PLCSim2016Dlg.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="IO_SIMULATORDlg.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="PLCDlg.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="core\cCore.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="lib\lib.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PLCSim2016.rc">
<Filter>리소스 파일</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="res\PLCSim2016.rc2">
<Filter>리소스 파일</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="res\PLCSim2016.ico">
<Filter>리소스 파일</Filter>
</Image>
<Image Include="res\icon1.ico">
<Filter>리소스 파일</Filter>
</Image>
<Image Include="res\icon2.ico">
<Filter>리소스 파일</Filter>
</Image>
<Image Include="res\run1.ico">
<Filter>리소스 파일</Filter>
</Image>
<Image Include="res\PLC-system-overview.gif">
<Filter>리소스 파일</Filter>
</Image>
<Image Include="res\icon3.ico">
<Filter>리소스 파일</Filter>
</Image>
</ItemGroup>
</Project>

View File

@ -0,0 +1,302 @@
// PLCSim2016Dlg.cpp : 구현 파일
//
#include "stdafx.h"
#include "PLCSim2016.h"
#include "PLCSim2016Dlg.h"
#include "afxdialogex.h"
#include "PLCDlg.h"
#include "IO_SIMULATORDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CIO_SIMULATORDlg* pdlg;
////////////////////////////////////////////////////////////////////
#define OUTPUT_FILE "C:\\PLCSim2016\\output.txt"
int fnReadOutput(char* pBuffer) {
FILE* pOutFile;
char sFileName[256];
sprintf(sFileName, "%s", OUTPUT_FILE);
pOutFile = fopen(OUTPUT_FILE, "r");
if (pOutFile != NULL) {
fread(pBuffer, 1, 256, pOutFile);
fclose(pOutFile);
return 0;
}
return -1;
}
VOID CALLBACK MyTimerProcIO(HWND hwnd, UINT iMsg, UINT iTimerID, DWORD dwTime)
{
/* timeup do timer proc */
HWND hWnd;
char strBuf[20];
char sBuffer[256];
memset(sBuffer, 0x00, 256);
hWnd = GetDlgItem(pdlg->m_hWnd, IDC_STATUS);
GetWindowText(hWnd, strBuf, 20);
switch (strBuf[0]) {
case '-': SetWindowText(hWnd, "\\"); break;
case '\\': SetWindowText(hWnd, "|"); break;
case '|': SetWindowText(hWnd, "/"); break;
case '/': SetWindowText(hWnd, "-"); break;
default: SetWindowText(hWnd, "-"); break;
}
fnReadOutput(sBuffer);
/* OUTPUT */
for (int i = 0; i < 8; i++) {
switch (i) {
case 0:
if (sBuffer[i] == 0x31)
pdlg->m_Out0.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out0.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 1:
if (sBuffer[i] == 0x31)
pdlg->m_Out1.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out1.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 2:
if (sBuffer[i] == 0x31)
pdlg->m_Out2.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out2.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 3:
if (sBuffer[i] == 0x31)
pdlg->m_Out3.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out3.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 4:
if (sBuffer[i] == 0x31)
pdlg->m_Out4.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out4.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 5:
if (sBuffer[i] == 0x31)
pdlg->m_Out5.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out5.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 6:
if (sBuffer[i] == 0x31)
pdlg->m_Out6.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out6.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
case 7:
if (sBuffer[i] == 0x31)
pdlg->m_Out7.SetIcon(AfxGetApp()->LoadIcon(IDI_ON));
else
pdlg->m_Out7.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
break;
}
}
}
BOOL openSimulationModal() {
CIO_SIMULATORDlg dlg;
CIO_SIMULATORDlg* m_pMainWnd;
pdlg = &dlg;
m_pMainWnd = &dlg;
dlg.iTimerHandle = SetTimer(m_pMainWnd->m_hWnd, 500, 10, MyTimerProcIO);
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
////////////////////////////////////////////////////////////////////
// 응용 프로그램 정보에 사용되는 CAboutDlg 대화 상자입니다.
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 대화 상자 데이터입니다.
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 지원입니다.
// 구현입니다.
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CPLCSim2016Dlg 대화 상자
CPLCSim2016Dlg::CPLCSim2016Dlg(CWnd* pParent /*=NULL*/)
: CDialogEx(IDD_PLCSIM2016_DIALOG, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPLCSim2016Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CPLCSim2016Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK, &CPLCSim2016Dlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON1, &CPLCSim2016Dlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CPLCSim2016Dlg::OnBnClickedButton2)
END_MESSAGE_MAP()
// CPLCSim2016Dlg 메시지 처리기
BOOL CPLCSim2016Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 시스템 메뉴에 "정보..." 메뉴 항목을 추가합니다.
// IDM_ABOUTBOX는 시스템 명령 범위에 있어야 합니다.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 이 대화 상자의 아이콘을 설정합니다. 응용 프로그램의 주 창이 대화 상자가 아닐 경우에는
// 프레임워크가 이 작업을 자동으로 수행합니다.
SetIcon(m_hIcon, TRUE); // 큰 아이콘을 설정합니다.
SetIcon(m_hIcon, FALSE); // 작은 아이콘을 설정합니다.
// TODO: 여기에 추가 초기화 작업을 추가합니다.
return TRUE; // 포커스를 컨트롤에 설정하지 않으면 TRUE를 반환합니다.
}
void CPLCSim2016Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면
// 아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 응용 프로그램의 경우에는
// 프레임워크에서 이 작업을 자동으로 수행합니다.
void CPLCSim2016Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트입니다.
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 클라이언트 사각형에서 아이콘을 가운데에 맞춥니다.
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;
// 아이콘을 그립니다.
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
// 사용자가 최소화된 창을 끄는 동안에 커서가 표시되도록 시스템에서
// 이 함수를 호출합니다.
HCURSOR CPLCSim2016Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CPLCSim2016Dlg::OnBnClickedOk()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
CDialogEx::OnOK();
}
void CPLCSim2016Dlg::OnBnClickedButton1()
{
CPLCDlg* dlg = new CPLCDlg();
dlg->Create(IDD_PLC_DIALOG, this);
dlg->ShowWindow(SW_NORMAL);
}
void CPLCSim2016Dlg::OnBnClickedButton2()
{
//CIO_SIMULATORDlg Dlg;
//Dlg.DoModal();
openSimulationModal();
}

View File

@ -0,0 +1,38 @@
// PLCSim2016Dlg.h : 헤더 파일
//
#pragma once
// CPLCSim2016Dlg 대화 상자
class CPLCSim2016Dlg : public CDialogEx
{
// 생성입니다.
public:
CPLCSim2016Dlg(CWnd* pParent = NULL); // 표준 생성자입니다.
// 대화 상자 데이터입니다.
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_PLCSIM2016_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 지원입니다.
// 구현입니다.
protected:
HICON m_hIcon;
// 생성된 메시지 맵 함수
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton2();
};

61
PLCSim2016/ReadMe.txt Normal file
View File

@ -0,0 +1,61 @@
================================================================================
MFC 라이브러리 : PLCSim2016 프로젝트 개요
===============================================================================
응용 프로그램 마법사에서 이 PLCSim2016 응용 프로그램을 만들었습니다. 이 응용 프로그램은 MFC의 기본 사용법을 보여 줄 뿐만 아니라 응용 프로그램을 작성하기 위한 기본 구조를 제공합니다.
PLCSim2016 응용 프로그램을 구성하는 각 파일에 대한
요약 설명이 포함되어 있습니다.
PLCSim2016.vcxproj
응용 프로그램 마법사를 사용하여 생성한 VC++ 프로젝트의 기본 프로젝트 파일입니다. 파일을 생성한 Visual C++ 버전에 대한 정보와 응용 프로그램 마법사를 사용하여 선택한 플랫폼, 구성 및 프로젝트 기능에 대한 정보가 포함되어 있습니다.
PLCSim2016.vcxproj.filters
응용 프로그램 마법사를 사용하여 생성된 VC++ 프로젝트의 필터 파일입니다. 이 파일에는 프로젝트의 파일과 필터 간의 연결 정보가 들어 있습니다. 이러한 연결은 특정 노드에서 유사한 확장명으로 그룹화된 파일을 표시하기 위해 IDE에서 사용됩니다. 예를 들어 ".cpp" 파일은 "소스 파일" 필터와 연결되어 있습니다.
PLCSim2016.h
해당 응용 프로그램의 기본 헤더 파일입니다.
여기에는 resource.h를 비롯한 다른 프로젝트별 헤더가 포함되어 있으며 CPLCSim2016App 응용 프로그램 클래스가 선언되어 있습니다.
PLCSim2016.cpp
이는 응용 프로그램 클래스 CPLCSim2016App가 포함된 기본 응용 프로그램 소스 파일입니다.
PLCSim2016.rc
프로그램에서 사용하는 모든 Microsoft Windows 리소스의 목록입니다. 여기에는 RES 하위 디렉터리에 저장된 아이콘, 비트맵 및 커서가 포함됩니다. 이 파일은 Microsoft Visual C++에서 직접 편집할 수 있습니다. 프로젝트 리소스는 1042에 있습니다.
res\PLCSim2016.ico
아이콘 파일이며, 응용 프로그램의 아이콘으로 사용됩니다. 이 아이콘은 기본 리소스 파일인 PLCSim2016.rc에 의해 포함됩니다.
res\PLCSim2016.rc2
이 파일에는 Microsoft Visual C++ 이외의 다른 도구에서 편집한 리소스가 포함되어 있습니다. 리소스 편집기로 편집할 수 없는 모든 리소스는 이 파일에 넣어야 합니다.
/////////////////////////////////////////////////////////////////////////////
응용 프로그램 마법사에서 대화 상자 클래스 하나를 만듭니다.
PLCSim2016Dlg.h, PLCSim2016Dlg.cpp - 대화 상자
이 파일에는 CPLCSim2016Dlg 클래스가 포함됩니다. 이 클래스는 응용 프로그램의 주 대화 상자에 대한 동작을 정의합니다. 이 대화 상자 템플릿은 PLCSim2016.rc에 있으며, Microsoft Visual C++에서 직접 편집할 수 있습니다.
/////////////////////////////////////////////////////////////////////////////
기타 표준 파일:
StdAfx.h, StdAfx.cpp
이 파일은 미리 컴파일된 헤더(PCH) 파일 PLCSim2016.pch와 미리 컴파일된 형식(PCT) 파일 StdAfx.obj를 빌드하는 데 사용됩니다.
Resource.h
새 리소스 ID를 정의하는 표준 헤더 파일입니다. Microsoft Visual C++에서 이 파일을 읽고 업데이트합니다.
PLCSim2016.manifest
응용 프로그램 매니페스트 파일은 Windows XP에서 특정 버전의 Side-by-Side 어셈블리에 대한 응용 프로그램 종속성을 설명하는 데 사용됩니다. 로더는 이 정보를 통해 어셈블리 캐시 또는 응용 프로그램의 private에서 적절한 어셈블리를 로드합니다. 응용 프로그램 매니페스트는 응용 프로그램 실행 파일과 같은 폴더에 설치된 외부 .manifest 파일 형태로서 재배포용으로 포함되거나, 리소스 형태로 된 실행 파일에 포함될 수 있습니다.
/////////////////////////////////////////////////////////////////////////////
기타 참고:
응용 프로그램 마법사에서 사용하는 "TODO:"는 사용자가 추가하거나 사용자 지정해야 하는 소스 코드 부분을 나타냅니다.
공유된 DLL에서 MFC를 사용하는 응용 프로그램의 경우 MFC DLL을 재배포할 필요가 없습니다. 응용 프로그램에서 운영 체제의 로캘과 다른 언어를 사용하는 경우 이에 해당하는 지역화된 리소스인 mfc110XXX.DLL도 재배포해야 합니다.
이러한 두 항목에 대한 자세한 내용은 MSDN 설명서에 있는 Visual C++ 응용 프로그램 재배포 섹션을 참조하십시오.
/////////////////////////////////////////////////////////////////////////////

BIN
PLCSim2016/Resource.h Normal file

Binary file not shown.

811
PLCSim2016/core/cCore.cpp Normal file
View File

@ -0,0 +1,811 @@
#include "cCore.h"
#include "..\\lib\\lib.h"
#include "..\Resource.h"
#include <memory.h>
//#define ENABLE_TRECE
cPLCCore* thePLCCore;
int iTimerCount;
cPLCCore::cPLCCore(){
pInPut = new stInPut[MAX_NUM_INPUT];
pOutPut = new stOutPut[MAX_NUM_OUTPUT];
pAUX = new stAUX[MAX_NUM_AUX];
pSTATUS = new stSTATUS[MAX_NUM_STATUS];
pTimer = new stTimer[MAX_NUM_TIMER];
pCounter = new stCounter[MAX_NUM_COUNTER];
pMEMBUF = new BYTE[MAX_PROG_SIZE];
sLogPath = new char[256];
sLadderFilePath = new char[256];
memset(pMEMBUF,0x00,MAX_PROG_SIZE);
iProgSize = MAX_PROG_SIZE;
bRUN = FALSE;
hFlowThread = NULL;
hClockThread = NULL;
iTimerHandle = 0;
bEnableTrace = FALSE;
thePLCCore = this; /* 這是為了讓 Call Back Function ?夠存取 PLC Core */
::iTimerCount = 0;
thePLCCore->fnRESETAll();
thePLCCore->fnWriteOutput();
pTRACE = fopen(TRACE_PATH,"ab");
PLCTRACE("PLCCore Log open");
}
cPLCCore::~cPLCCore(){
thePLCCore->fnRESETAll();
thePLCCore->fnWriteOutput();
delete pInPut;
delete pOutPut;
delete pAUX;
delete pSTATUS;
delete pTimer;
delete pCounter;
delete pMEMBUF;
delete sLogPath;
delete sLadderFilePath;
PLCTRACE("PLCCore Log close");
fclose(pTRACE);
}
void cPLCCore::fnRESETAll()
{
int i=0;
for(i = 0;i < MAX_NUM_INPUT;i++)pInPut[i].status = 0;
for(i = 0;i < MAX_NUM_OUTPUT;i++)pOutPut[i].status = 0;
for(i = 0;i < MAX_NUM_AUX;i++)pAUX[i].status = 0;
for(i = 0;i < MAX_NUM_STATUS;i++)pSTATUS[i].status = 0;
for(i = 0;i < MAX_NUM_TIMER;i++){
pTimer[i].status = 0;
pTimer[i].timeup = 0;
pTimer[i].clock = 0;
pTimer[i].limit = 0;
}
for(i = 0;i < MAX_NUM_COUNTER;i++){
pCounter[i].count = 0;
pCounter[i].fire = 0;
pCounter[i].limit = 0;
pCounter[i].status = 0;
pCounter[i].filpflop = 0;
}
}
int cPLCCore::cReadProgIntoMEM(char* sPath)
{
return iFileR(sPath,pMEMBUF,&iProgSize);
}
VOID CALLBACK MyTimerProc(HWND hwnd, UINT iMsg, UINT iTimerID, DWORD dwTime)
{
/* timeup do timer proc */
HWND hWnd;
char strBuf[20];
#ifdef ENABLE_TRECE
thePLCCore->PLCTRACE("timer msg");
#endif
hWnd = GetDlgItem(thePLCCore->m_Hwnd,IDC_STATUS);
GetWindowText(hWnd,strBuf,20);
switch(strBuf[0])
{
case '-':
SetWindowText(hWnd,"\\");
break;
case '\\':
SetWindowText(hWnd,"|");
break;
case '|':
SetWindowText(hWnd,"/");
break;
case '/':
SetWindowText(hWnd,"-");
break;
default:
SetWindowText(hWnd,"-");
break;
}
}
DWORD WINAPI fnClockThread( LPVOID pParam)
{
/* Multimedia Timer */
while(thePLCCore->bRUN)
{
#ifdef ENABLE_TRECE
thePLCCore->PLCTRACE("clock thread msg");
#endif
Sleep(100);
}
return 0;
}
void CALLBACK timerRoutine(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
#ifdef ENABLE_TRECE
thePLCCore->PLCTRACE("timerRoutine ...");
#endif
int i;
/* 處理 PLC Timer */
for(i = 0;i < MAX_NUM_TIMER;i++){
if(thePLCCore->pTimer[i].status == 1){
if(thePLCCore->pTimer[i].clock == thePLCCore->pTimer[i].limit)
thePLCCore->pTimer[i].timeup = 1;
else
thePLCCore->pTimer[i].clock+=100;
}else{
thePLCCore->pTimer[i].timeup = 0;
thePLCCore->pTimer[i].clock = 0;
}
}
}
int cPLCCore::fnLDAndCompute(sString* pCOMMAND, stPLC_OBJ *pPLC_OBJ,int* piStackDepth)
{
int iObjIndex = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'X':
pPLC_OBJ[*piStackDepth]=thePLCCore->pInPut[iObjIndex];
break;
case 'Y':
pPLC_OBJ[*piStackDepth]=thePLCCore->pOutPut[iObjIndex];
break;
case 'M':
pPLC_OBJ[*piStackDepth]=thePLCCore->pAUX[iObjIndex];
break;
case 'S':
pPLC_OBJ[*piStackDepth]=thePLCCore->pSTATUS[iObjIndex];
break;
case 'T':
pPLC_OBJ[*piStackDepth]=thePLCCore->pTimer[iObjIndex];
break;
case 'C':
pPLC_OBJ[*piStackDepth]=thePLCCore->pCounter[iObjIndex];
break;
default:
return -1;
}
return 0;
}
int cPLCCore::fnLDNotAndCompute(sString* pCOMMAND, stPLC_OBJ *pPLC_OBJ,int* piStackDepth)
{
int iObjIndex = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'X':
pPLC_OBJ[*piStackDepth]=!thePLCCore->pInPut[iObjIndex];
break;
case 'Y':
pPLC_OBJ[*piStackDepth]=!thePLCCore->pOutPut[iObjIndex];
break;
case 'M':
pPLC_OBJ[*piStackDepth]=!thePLCCore->pAUX[iObjIndex];
break;
case 'S':
pPLC_OBJ[*piStackDepth]=!thePLCCore->pSTATUS[iObjIndex];
break;
case 'T':
pPLC_OBJ[*piStackDepth]=!thePLCCore->pTimer[iObjIndex];
break;
case 'C':
pPLC_OBJ[*piStackDepth]=!thePLCCore->pCounter[iObjIndex];
break;
default:
return -1;
}
return 0;
}
int cPLCCore::fnANDAndCompute(sString* pCOMMAND, stPLC_OBJ *pPLC_OBJ,int* piStackDepth)
{
int iObjIndex = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'X':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]*thePLCCore->pInPut[iObjIndex];
break;
case 'Y':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]*thePLCCore->pOutPut[iObjIndex];
break;
case 'M':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]*thePLCCore->pAUX[iObjIndex];
break;
case 'S':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]*thePLCCore->pSTATUS[iObjIndex];
break;
case 'T':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]*thePLCCore->pTimer[iObjIndex];
break;
case 'C':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]*thePLCCore->pCounter[iObjIndex];
break;
default:
return -1;
}
return 0;
}
int cPLCCore::fnANDNotAndCompute(sString* pCOMMAND, stPLC_OBJ *pPLC_OBJ,int* piStackDepth)
{
int iObjIndex = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'X':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]*!thePLCCore->pInPut[iObjIndex]);
break;
case 'Y':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]*!thePLCCore->pOutPut[iObjIndex]);
break;
case 'M':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]*!thePLCCore->pAUX[iObjIndex]);
break;
case 'S':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]*!thePLCCore->pSTATUS[iObjIndex]);
break;
case 'T':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]*!thePLCCore->pTimer[iObjIndex]);
break;
case 'C':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]*!thePLCCore->pCounter[iObjIndex]);
break;
default:
return -1;
}
return 0;
}
int cPLCCore::fnORAndCompute(sString* pCOMMAND, stPLC_OBJ *pPLC_OBJ,int* piStackDepth)
{
int iObjIndex = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'X':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]+thePLCCore->pInPut[iObjIndex];
break;
case 'Y':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]+thePLCCore->pOutPut[iObjIndex];
break;
case 'M':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]+thePLCCore->pAUX[iObjIndex];
break;
case 'S':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]+thePLCCore->pSTATUS[iObjIndex];
break;
case 'T':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]+thePLCCore->pTimer[iObjIndex];
break;
case 'C':
pPLC_OBJ[*piStackDepth-1]=pPLC_OBJ[*piStackDepth-1]+thePLCCore->pCounter[iObjIndex];
break;
default:
return -1;
}
return 0;
}
int cPLCCore::fnORNotAndCompute(sString* pCOMMAND, stPLC_OBJ *pPLC_OBJ,int* piStackDepth)
{
int iObjIndex = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'X':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]+!thePLCCore->pInPut[iObjIndex]);
break;
case 'Y':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]+!thePLCCore->pOutPut[iObjIndex]);
break;
case 'M':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]+!thePLCCore->pAUX[iObjIndex]);
break;
case 'S':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]+!thePLCCore->pSTATUS[iObjIndex]);
break;
case 'T':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]+!thePLCCore->pTimer[iObjIndex]);
break;
case 'C':
pPLC_OBJ[*piStackDepth-1]=(pPLC_OBJ[*piStackDepth-1]+!thePLCCore->pCounter[iObjIndex]);
break;
default:
return -1;
}
return 0;
}
int cPLCCore::fnOUTAndCompute(sString *pCOMMAND, stPLC_OBJ *pPLC_OBJ, int *piStackDepth)
{
char sDebugBuffer[256];
int iObjIndex = 0;
int iK_Value = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'Y':
thePLCCore->pOutPut[iObjIndex].status = pPLC_OBJ[*piStackDepth-1].status;
break;
case 'M':
thePLCCore->pAUX[iObjIndex].status=pPLC_OBJ[*piStackDepth-1].status;
break;
case 'T':
thePLCCore->pTimer[iObjIndex].status=pPLC_OBJ[*piStackDepth-1].status;
iK_Value = atoi(&pCOMMAND[2].m_String[1]);
thePLCCore->pTimer[iObjIndex].limit = iK_Value;
break;
case 'C':
if(pPLC_OBJ[*piStackDepth-1].status == 1){
iK_Value = atoi(&pCOMMAND[2].m_String[1]);
thePLCCore->pCounter[iObjIndex].limit = iK_Value;
if(thePLCCore->pCounter[iObjIndex].filpflop==0 && thePLCCore->pCounter[iObjIndex].fire==0){
thePLCCore->pCounter[iObjIndex].count++;
thePLCCore->pCounter[iObjIndex].status=1;
thePLCCore->pCounter[iObjIndex].filpflop=1;
#ifdef ENABLE_TRECE
sprintf(sDebugBuffer,"count msg ok : %d ,%d, %d",
iObjIndex,
thePLCCore->pCounter[iObjIndex].count,
thePLCCore->pCounter[iObjIndex].status);
thePLCCore->PLCTRACE(sDebugBuffer);
#endif
}
}else{
thePLCCore->pCounter[iObjIndex].filpflop=0;
#ifdef ENABLE_TRECE
thePLCCore->PLCTRACE("count msg off");
#endif
}
if((thePLCCore->pCounter[iObjIndex].count >= thePLCCore->pCounter[iObjIndex].limit)&&(thePLCCore->pCounter[iObjIndex].status==1))
thePLCCore->pCounter[iObjIndex].fire=1;
break;
default:
return -1;
}
return 0;
}
int cPLCCore::fnANBAndCompute(sString *pCOMMAND, stPLC_OBJ *pPLC_OBJ, int *piStackDepth)
{
pPLC_OBJ[*piStackDepth-2]=pPLC_OBJ[*piStackDepth-2]*pPLC_OBJ[*piStackDepth-1];
return 0;
}
int cPLCCore::fnORBAndCompute(sString *pCOMMAND, stPLC_OBJ *pPLC_OBJ, int *piStackDepth)
{
pPLC_OBJ[*piStackDepth-2]=pPLC_OBJ[*piStackDepth-2]+pPLC_OBJ[*piStackDepth-1];
return 0;
}
int cPLCCore::fnSETAndCompute(sString *pCOMMAND, stPLC_OBJ *pPLC_OBJ, int *piStackDepth)
{
int iObjIndex = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'Y':
if(pPLC_OBJ[*piStackDepth-1].status == 1)
thePLCCore->pOutPut[iObjIndex].status = 1;
break;
case 'M':
if(pPLC_OBJ[*piStackDepth-1].status == 1)
thePLCCore->pAUX[iObjIndex].status=1;
break;
case 'S':
if(pPLC_OBJ[*piStackDepth-1].status == 1)
thePLCCore->pSTATUS[iObjIndex].status=1;
break;
case 'T':
if(pPLC_OBJ[*piStackDepth-1].status == 1)
thePLCCore->pTimer[iObjIndex].status=1;
break;
case 'C':
if(pPLC_OBJ[*piStackDepth-1].status == 1){
thePLCCore->pCounter[iObjIndex].status=1;
thePLCCore->pCounter[iObjIndex].fire=1;
}
break;
default:
return -1;
}
return 0;
}
int cPLCCore::fnRSTAndCompute(sString *pCOMMAND, stPLC_OBJ *pPLC_OBJ, int *piStackDepth)
{
int iObjIndex = 0;
iObjIndex = atoi(&pCOMMAND[1].m_String[1]);
switch(pCOMMAND[1].m_String[0]){
case 'Y':
if(pPLC_OBJ[*piStackDepth-1].status == 1)
thePLCCore->pOutPut[iObjIndex].status = 0;
break;
case 'M':
if(pPLC_OBJ[*piStackDepth-1].status == 1)
thePLCCore->pAUX[iObjIndex].status=0;
break;
case 'S':
if(pPLC_OBJ[*piStackDepth-1].status == 1)
thePLCCore->pSTATUS[iObjIndex].status=0;
break;
case 'T':
if(pPLC_OBJ[*piStackDepth-1].status == 1)
thePLCCore->pTimer[iObjIndex].status=0;
break;
case 'C':
if(pPLC_OBJ[*piStackDepth-1].status == 1){
thePLCCore->pCounter[iObjIndex].status=0;
thePLCCore->pCounter[iObjIndex].count=0;
thePLCCore->pCounter[iObjIndex].fire=0;
thePLCCore->pCounter[iObjIndex].filpflop=0;
}
break;
default:
return -1;
}
return 0;
}
DWORD WINAPI fnFlowCtrlThread( LPVOID pParam)
{
char cClearStack;
int iTokenStartPos;
int iStackDepth;
int iParseProgOffset;
int iTempBufferLength;
int iRet;
BOOL bProgEnd;
sString sCOMMAND[5];
char* pTempBuffer = new char[256];
stPLC_OBJ* pPLC_OBJ = new stPLC_OBJ[MAX_LADDER_DEPTH];
/* Ladder Prog */
thePLCCore->cReadProgIntoMEM(LADDER_PATH);
iTokenStartPos = 0;
iStackDepth = 0;
iParseProgOffset = 0;
thePLCCore->fnRESETAll();
thePLCCore->fnWriteOutput();
// HANDLE m_hEvent=CreateEvent(NULL,TRUE,TRUE,"XXXEvent");
while(thePLCCore->bRUN)
{
iStackDepth = 0;
iParseProgOffset = 0;
cClearStack = 0x00;
#ifdef ENABLE_TRECE
thePLCCore->PLCTRACE("flow thread msg");
#endif
/* 讀取 Input 狀態讀至記憶體中 */
thePLCCore->fnReadInput();
do{
memset(sCOMMAND,0x00,sizeof(sString)*5);
iTokenStartPos = iParseProgOffset;
/* 取得 Ladder ?式的?小段 such as LD X000分段的方式是以 0x0d,0x0a ?為識別符號 */
bProgEnd = thePLCCore->GetProgToken(&iParseProgOffset);
if(bProgEnd == TRUE){
memset(pTempBuffer,0x00,256);
memcpy(pTempBuffer,&thePLCCore->pMEMBUF[iTokenStartPos],iParseProgOffset - iTokenStartPos);
iParseProgOffset += 2;
iTempBufferLength = strlen(pTempBuffer);
/* LD X000 aa[0] = LD,aa[1] = X000 */
iRet = sSplitToStringArray(sCOMMAND,5,pTempBuffer,&iTempBufferLength,' ');
/* Ladder Prog Command */
// LD
if((sCOMMAND[0].m_String[0] == 'L') && (sCOMMAND[0].m_String[1] == 'D') && (sCOMMAND[0].m_String[2] == 0x00)){
if(cClearStack == 0x01){
iStackDepth--;
cClearStack = 0x00;
}
iRet = thePLCCore->fnLDAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
iStackDepth++;
}// LDI
else if((sCOMMAND[0].m_String[0] == 'L') && (sCOMMAND[0].m_String[1] == 'D') && (sCOMMAND[0].m_String[2] == 'I')){
iRet = thePLCCore->fnLDNotAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
iStackDepth++;
}// AND
else if((sCOMMAND[0].m_String[0] == 'A') && (sCOMMAND[0].m_String[1] == 'N') && (sCOMMAND[0].m_String[2] == 'D')){
iRet = thePLCCore->fnANDAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
}// ANI
else if((sCOMMAND[0].m_String[0] == 'A') && (sCOMMAND[0].m_String[1] == 'N') && (sCOMMAND[0].m_String[2] == 'I')){
iRet = thePLCCore->fnANDNotAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
}// OR
else if((sCOMMAND[0].m_String[0] == 'O') && (sCOMMAND[0].m_String[1] == 'R') && (sCOMMAND[0].m_String[2] == 0x00)){
iRet = thePLCCore->fnORAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
}// ORI
else if((sCOMMAND[0].m_String[0] == 'O') && (sCOMMAND[0].m_String[1] == 'R') && (sCOMMAND[0].m_String[2] == 'I')){
iRet = thePLCCore->fnORNotAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
}// ANB
else if((sCOMMAND[0].m_String[0] == 'A') && (sCOMMAND[0].m_String[1] == 'N') && (sCOMMAND[0].m_String[2] == 'B')){
iRet = thePLCCore->fnANBAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
iStackDepth--;
}// ORB
else if((sCOMMAND[0].m_String[0] == 'O') && (sCOMMAND[0].m_String[1] == 'R') && (sCOMMAND[0].m_String[2] == 'B')){
iRet = thePLCCore->fnORBAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
iStackDepth--;
}// SET
else if((sCOMMAND[0].m_String[0] == 'S') && (sCOMMAND[0].m_String[1] == 'E') && (sCOMMAND[0].m_String[2] == 'T')){
iRet = thePLCCore->fnSETAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
if(iStackDepth > 0)cClearStack=0x01;
}// RST
else if((sCOMMAND[0].m_String[0] == 'R') && (sCOMMAND[0].m_String[1] == 'S') && (sCOMMAND[0].m_String[2] == 'T')){
iRet = thePLCCore->fnRSTAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
if(iStackDepth > 0)cClearStack=0x01;
}// OUT
else if((sCOMMAND[0].m_String[0] == 'O') && (sCOMMAND[0].m_String[1] == 'U') && (sCOMMAND[0].m_String[2] == 'T')){
iRet = thePLCCore->fnOUTAndCompute(sCOMMAND,pPLC_OBJ,&iStackDepth);
if(iStackDepth > 0)cClearStack=0x01;
//ResetEvent(m_hEvent); 使用 EVENT 並不??低 CPU 的 Loading,所以還是用 Sleep(1)
//WaitForSingleObject(m_hEvent,1);
//Sleep(1);
}else if((sCOMMAND[0].m_String[0] == 'E') && (sCOMMAND[0].m_String[1] == 'N') && (sCOMMAND[0].m_String[2] == 'D')){
;
}else{
;
}
}
}while(bProgEnd);
thePLCCore->fnWriteOutput();
Sleep(100);
}
thePLCCore->fnRESETAll();
thePLCCore->fnWriteOutput();
// CloseHandle(m_hEvent);
delete pTempBuffer;
delete pPLC_OBJ;
return 0;
}
BOOL cPLCCore::GetProgToken(int* iParseProgOffset)
{
int iStringLen,iBufferLen;
char sCMD_Buffer[]={0x0d,0x0a};
iStringLen = MAX_PROG_SIZE;
iBufferLen = 2;
if(iFindKeyCharacterFromBuffer((char*)pMEMBUF,&iStringLen,sCMD_Buffer,&iBufferLen,iParseProgOffset) == 0)
return TRUE;
return FALSE;
}
void cPLCCore::fnReadInput()
{
FILE* pFile;
char* pBuffer;
pBuffer = new char[256];
pFile = fopen("input.txt","r");
fread(pBuffer,1,256,pFile);
fclose(pFile);
for(int i = 0;i < MAX_NUM_INPUT;i++){
pInPut[i].status = (pBuffer[i] - 0x30);
}
delete pBuffer;
}
void cPLCCore::fnWriteOutput()
{
int iOutputFile,iPos,iStatus;
char sFileName[256];
char sBuffer[3];
sBuffer[0] = 0x30;
sBuffer[1] = 0x31;
sBuffer[2] = 0x00;
sprintf(sFileName,"%s","output.txt");
iOutputFile = _open(sFileName,_O_RDWR , _S_IREAD | _S_IWRITE );
if(iOutputFile != -1){
for(int i = 0;i < MAX_NUM_OUTPUT;i++){
iPos = i;
_lseek( iOutputFile, iPos, SEEK_SET );
iStatus = pOutPut[i].status;
if(iStatus == 1)
_write( iOutputFile, &sBuffer[1], 1);
else
_write( iOutputFile, &sBuffer[0], 1);
}
close(iOutputFile);
}
}
int cPLCCore::fRUN()
{
if(bRUN == FALSE){
bRUN = TRUE;
PLCTRACE("plc core running");
iTimerHandle = SetTimer(m_Hwnd,500,10,MyTimerProc);
if(iTimerHandle == 0)
return -1;
hFlowThread = CreateThread(NULL,(4096*1024),fnFlowCtrlThread,NULL,0,&dwFlowThreadID);
// 嘗試使用 Multimedia Timer 取代
//hClockThread = CreateThread(NULL,(4096*1024),fnClockThread,NULL,0,&dwClockThreadID);
m_timerID = timeSetEvent(100,5,timerRoutine, NULL,TIME_PERIODIC);
}
else{
return -2;
}
return 0;
}
int cPLCCore::fSTOP()
{
DWORD dwThread;
if(bRUN == TRUE){
bRUN = FALSE;
KillTimer(m_Hwnd,iTimerHandle);
dwThread = WaitForSingleObject(hFlowThread,5000);
if(dwThread == WAIT_TIMEOUT)
{
TerminateThread(hFlowThread,0);
}
/* 嘗試使用 Multimedia Timer 取代
dwThread = WaitForSingleObject(hClockThread,5000);
if(dwThread == WAIT_TIMEOUT)
{
TerminateThread(hClockThread,0);
}
*/
PLCTRACE("plc core stoped");
// CloseHandle(hClockThread);
CloseHandle(hFlowThread);
ASSERT(m_timerID != 0);
timeKillEvent(m_timerID);
}
else
{
return -2;
}
return 0;
}
int cPLCCore::PLCTRACE(char* pMsg)
{
SYSTEMTIME dt;
#ifdef ENABLE_TRECE
GetSystemTime(&dt);
fprintf(pTRACE,"[%04d/%02d/%02d %02d:%02d:%02d %03d] %s\r\n",
dt.wYear,dt.wMonth,dt.wDay,dt.wHour,dt.wMinute,dt.wSecond,dt.wMilliseconds,pMsg);
fflush(pTRACE);
#endif
return 0;
}
stPLC_OBJ stPLC_OBJ::operator +(const stPLC_OBJ& a)
{
stPLC_OBJ _stPLC_OBJ;
stTimer* b = (stTimer*)&a;
stCounter* c = (stCounter*)&a;
if((this->iClassType != IS_TIMER) && (this->iClassType != IS_COUNTER))
{
switch(a.iClassType){
case IS_INPUT:
case IS_OUTPUT:
case IS_AUX:
case IS_STATUS:
if((this->status == 1) || (a.status == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
break;
case IS_TIMER:
if((this->status == 1) || (a.status == 1 && b->timeup == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
break;
case IS_COUNTER:
if((this->status == 1) || (a.status == 1 && c->fire == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
break;
}
}else{
if(this->iClassType == IS_TIMER){
stTimer* d = (stTimer*)this;
if(a.iClassType == IS_TIMER){
if((d->status == 1 && d->timeup==1) || (a.status == 1 && b->timeup == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
}else{
if((d->status == 1 && d->timeup==1) || (a.status == 1 && c->fire == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
}
}
if(this->iClassType == IS_COUNTER){
stCounter* d = (stCounter*)this;
if(a.iClassType == IS_TIMER){
if((d->status == 1 && d->fire==1) || (a.status == 1 && b->timeup == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
}else{
if((d->status == 1 && d->fire==1) || (a.status == 1 && c->fire == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
}
}
}
return _stPLC_OBJ;
}
stPLC_OBJ stPLC_OBJ::operator *(const stPLC_OBJ& a)
{
stPLC_OBJ _stPLC_OBJ;
stTimer* b = (stTimer*)&a;
stCounter* c = (stCounter*)&a;
if((this->iClassType != IS_TIMER) && (this->iClassType != IS_COUNTER))
{
switch(a.iClassType){
case IS_INPUT:
case IS_OUTPUT:
case IS_AUX:
case IS_STATUS:
if((this->status == 1) && (a.status == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
break;
case IS_TIMER:
if((this->status == 1) && (a.status == 1 && b->timeup == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
break;
case IS_COUNTER:
if((this->status == 1) && (a.status == 1 && c->fire == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
break;
}
}else{
if(this->iClassType == IS_TIMER){
stTimer* d = (stTimer*)this;
if(a.iClassType == IS_TIMER){
if((d->status == 1 && d->timeup==1) && (a.status == 1 && b->timeup == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
}else{
if((d->status == 1 && d->timeup==1) && (a.status == 1 && c->fire == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
}
}
if(this->iClassType == IS_COUNTER){
stCounter* d = (stCounter*)this;
if(a.iClassType == IS_TIMER){
if((d->status == 1 && d->fire==1) && (a.status == 1 && b->timeup == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
}else{
if((d->status == 1 && d->fire==1) && (a.status == 1 && c->fire == 1)) _stPLC_OBJ.status = 1;
else _stPLC_OBJ.status = 0;
}
}
}
return _stPLC_OBJ;
}
void stPLC_OBJ::operator =(const stPLC_OBJ& a)
{
stTimer* b = (stTimer*)&a;
stCounter* c = (stCounter*)&a;
if((a.iClassType != IS_TIMER) && (a.iClassType != IS_COUNTER))
this->status = a.status;
if(a.iClassType == IS_TIMER)
this->status = (a.status == 1 & b->timeup == 1);
if(a.iClassType == IS_COUNTER)
this->status = (a.status == 1 & c->fire == 1);
}
stPLC_OBJ stPLC_OBJ::operator!() const
{
stPLC_OBJ _stPLC_OBJ;
stTimer* d = (stTimer*)this;
stCounter* e = (stCounter*)this;
switch(this->iClassType){
case IS_INPUT:
case IS_OUTPUT:
case IS_AUX:
case IS_STATUS:
if(this->status == 1)
_stPLC_OBJ.status = 0;
else
_stPLC_OBJ.status = 1;
break;
case IS_TIMER:
if((this->status == 1)&&(d->timeup == 1))
_stPLC_OBJ.status = 0;
else
_stPLC_OBJ.status = 1;
break;
case IS_COUNTER:
if((this->status == 1)&&(e->fire == 1))
_stPLC_OBJ.status = 0;
else
_stPLC_OBJ.status = 1;
break;
}
return _stPLC_OBJ;
}

161
PLCSim2016/core/cCore.h Normal file
View File

@ -0,0 +1,161 @@
#include <stdio.h>
#include <stdlib.h>
#ifndef CLASS_PLC_CORE
#define CLASS_PLC_CORE
/* define all components */
#include <Afx.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#include "..\\lib\\lib.h"
#define MAX_LADDER_DEPTH 5
#define MAX_NUM_INPUT 8
#define MAX_NUM_OUTPUT 8
#define MAX_NUM_AUX 500
#define MAX_NUM_STATUS 500
#define MAX_NUM_TIMER 200
#define MAX_NUM_COUNTER 100
#define MAX_NUM_REGISTER 200
#define MAX_PROG_SIZE 4096000
#define TRACE_PATH "C:\\PLCSim2016\\plccore.log"
#define LADDER_PATH "C:\\PLCSim2016\\test.lad"
#define IS_INPUT 1
#define IS_OUTPUT 2
#define IS_AUX 3
#define IS_STATUS 4
#define IS_TIMER 5
#define IS_COUNTER 6
#define IS_REGISTER 7
class stTimer;
class stCounter;
class stRegister;
class sString;
class stPLC_OBJ{
public:
stPLC_OBJ(){
iClassType = IS_AUX;
status = 1;
}
short status;
void operator=(const stPLC_OBJ&);
stPLC_OBJ operator!()const;
stPLC_OBJ operator+(const stPLC_OBJ&);
stPLC_OBJ operator*(const stPLC_OBJ&);
public:
int iClassType;
int TestIsKindOf(stPLC_OBJ& a){
return a.iClassType;
}
};
/* 0:off,1:on */
class stInPut : public stPLC_OBJ
{
public:
stInPut(){status = 0;iClassType = IS_INPUT;}
};
class stOutPut : public stPLC_OBJ
{
public:
stOutPut(){status = 0;iClassType = IS_OUTPUT;}
};
class stAUX : public stPLC_OBJ
{
public:
stAUX(){status = 0;iClassType = IS_AUX;}
};
class stSTATUS : public stPLC_OBJ
{
public:
stSTATUS(){status = 0;iClassType = IS_STATUS;}
};
class stTimer : public stPLC_OBJ
{
public:
stTimer(){status = 0;limit=0;clock=0;timeup=0;iClassType = IS_TIMER;}
int limit;
int clock;
short timeup;
};
class stCounter : public stPLC_OBJ
{
public:
stCounter(){status = 0;limit=0;count=0;fire=0;/*filpflop=0;*/iClassType = IS_COUNTER;}
int limit;
int count;
short fire;
short filpflop;
};
class stRegister : public stPLC_OBJ
{
public:
stRegister(){status = 0;iClassType = IS_REGISTER;}
int number;
};
class cPLCCore{
public :
stInPut* pInPut;
stOutPut* pOutPut;
stAUX* pAUX;
stSTATUS* pSTATUS;
stTimer* pTimer;
stCounter* pCounter;
BYTE* pMEMBUF;
cPLCCore();
~cPLCCore();
int iProgSize;
int iTimerHandle;
UINT m_timerID;
HWND m_Hwnd;
HANDLE hFlowThread;
DWORD dwFlowThreadID;
HANDLE hClockThread;
DWORD dwClockThreadID;
BOOL bRUN;
FILE* pTRACE;
BOOL bEnableTrace;
char* sLogPath;
char* sLadderFilePath;
public:
int fnSETAndCompute(sString *pCOMMAND, stPLC_OBJ *pPLC_OBJ, int *piStackDepth);
int fnRSTAndCompute(sString *pCOMMAND, stPLC_OBJ *pPLC_OBJ, int *piStackDepth);
int fnORBAndCompute(sString *pCOMMAND, stPLC_OBJ *pPLC_OBJ, int *piStackDepth);
int fnANBAndCompute(sString* pCOMMAND, stPLC_OBJ *pPLC_OBJ,int* piStackDepth);
void fnRESETAll();
void fnWriteOutput();
int fnOUTAndCompute(sString* pCOMMAND,stPLC_OBJ* pPLC_OBJ,int* piStackDepth);
int fnLDAndCompute(sString* pCOMMAND,stPLC_OBJ* pPLC_OBJ,int* piStackDepth);
int fnLDNotAndCompute(sString* pCOMMAND,stPLC_OBJ* pPLC_OBJ,int* piStackDepth);
int fnANDAndCompute(sString* pCOMMAND,stPLC_OBJ* pPLC_OBJ,int* piStackDepth);
int fnANDNotAndCompute(sString* pCOMMAND,stPLC_OBJ* pPLC_OBJ,int* piStackDepth);
int fnORAndCompute(sString* pCOMMAND,stPLC_OBJ* pPLC_OBJ,int* piStackDepth);
int fnORNotAndCompute(sString* pCOMMAND,stPLC_OBJ* pPLC_OBJ,int* piStackDepth);
BOOL GetProgToken(int* iParseProgOffset);
void fnReadInput();
friend VOID CALLBACK MyTimerProc(HWND hwnd, UINT iMsg, UINT iTimerID, DWORD dwTime);
friend DWORD WINAPI fnFlowCtrlThread( LPVOID pParam);
friend DWORD WINAPI fnClockThread( LPVOID pParam);
friend void CALLBACK timerRoutine(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2);
int fRUN();
int fSTOP();
int cReadProgIntoMEM(char* sPath);
int PLCTRACE(char* pMsg);
};
#endif

170
PLCSim2016/lib/lib.cpp Normal file
View File

@ -0,0 +1,170 @@
#include "lib.h"
/*
* limit :
* 1. can't use this object in heap area
* 2. last character can't be cKEY
* type : int
* argument :
* 1. (sString*) sString array for store data
* 2. int sString array depth
* 3. (char*) Data Buffer to Parse
* 4. int* Buffer Length
* 5. (char) KEY character you want to split
* return :
* -1. not support
* -2. out of array index
* 0. ok
*/
int sSplitToStringArray(sString* sRetArray,
int iArrayDepth,
char* sStringBuffer,
int* iBufferLen,
char cKEY){
int iOccurCount=0;
int i,j,k;
if(sStringBuffer[*iBufferLen] == cKEY)
return -1;
for(i = 0;i < *iBufferLen;i++){
if(sStringBuffer[i] == cKEY)
iOccurCount++;
}
for(i=0,j=0,k=0;i < *iBufferLen;i++){
if(sStringBuffer[i] == cKEY){
j++;
k=0;
if(j > iArrayDepth)
return -2;
}else{
sRetArray[j].m_String[k++] = sStringBuffer[i];
}
}
return 0;
}
/*
* type : int
* argument :
* 1. (char*) Data Buffer to Parse
* 2. int* Buffer Length
* 3. (char*) KEY character you want to find
* 4. int* key length
* 5. int* offset begin from data buffer / first key character occur in buffer
* return :
* 0. success
* -1. failure
*/
int iFindKeyCharacterFromBuffer(char* sDataBuffer,
int* iBufferLength,
char* sKEY,
int* iKEY_Length,
int* iOffset){
/* Check if Job is over Buffer length return immediate */
if((*iOffset + *iKEY_Length) > *iBufferLength)
return -1;
for(int i = *iOffset;i+*iKEY_Length < *iBufferLength;i++){
if(memcmp(&sDataBuffer[i],sKEY,*iKEY_Length) == 0){
*iOffset = i;
return 0;
}
}
return -1;
}
/*
* type : int
* argument :
* 1. (char*) file path want to read
* 2. (BYTE*) buffer pointer for store file
* 3. (int*) buffer size and file size return
* return :
* 0. success
* -1. file read failure
* -2. buffer size not enougth
*/
int iFileR(char* sPath,BYTE* pBUF,int* piSize)
{
struct _stat lfilestat;
int result;
FILE* pFile;
result = _stat( sPath, &lfilestat );
if( result != 0 )
return -1;
if(lfilestat.st_size > *piSize)
return -2;
*piSize = lfilestat.st_size;
pFile = fopen(sPath,"rb");
if(pFile == NULL)
return -1;
result = fread(pBUF,1,*piSize,pFile);
if(result != *piSize)
{
fclose(pFile);
return -1;
}
fclose(pFile);
return 0;
}
/*
* type : int
* argument :
* 1. Windows Handle
* 2. (char*) Title for display
* 3. (char*) buffer for return string
* return :
* 0. failure
* n. buffer length
*/
int GetPathDialog(HWND hWnd,char* sTitle,char *pBuffer)
{
BROWSEINFO bf;
LPITEMIDLIST lpitem;
memset(&bf,0,sizeof BROWSEINFO);
bf.hwndOwner=hWnd;
bf.lpszTitle=sTitle;
bf.ulFlags=BIF_RETURNONLYFSDIRS;
lpitem=SHBrowseForFolder(&bf);
if(lpitem==NULL)
return 0;
SHGetPathFromIDList(lpitem,pBuffer);
return lstrlen(pBuffer);
}
#ifndef LIB_UNIT_TEST
#define LIB_UNIT_TEST
void main(int argc,char** argv)
{
int str_len,offset,keylen,iret;
sString AA[10];
char tt[]="AAA BBB CCC DDD EEE FFF GGG";
str_len = strlen(tt);
iret = sSplitToStringArray(AA,10,tt,&str_len,' ');
char test[]="1234567890AA123";
keylen=2;
str_len= strlen(test);
offset=0;
iret = iFindKeyCharacterFromBuffer(test,&str_len,"AA",&keylen,&offset);
/* iFileR Unit Test */
/*
int size,iRet;
BYTE* pBuffer;
size = 4096000;
pBuffer = new BYTE[size];
//iRet = iFileR("C:\\TWMJ_1032.exe",pBuffer,&size);
GetPathDialog(NULL,"¿ï¨ú°O¿ýÀɸô?",(char*)pBuffer);
delete pBuffer;
printf("Hello world\r\n");
*/
}
#endif

86
PLCSim2016/lib/lib.h Normal file
View File

@ -0,0 +1,86 @@
#ifndef CLASS_PLC_CORE
//#include <windows.h>
#endif
#include <memory.h>
#include <io.h>
#include <fcntl.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <shlobj.h>
#ifndef SSTRING
#define SSTRING
class sString{
public:
sString(){
memset(m_String,0x00,256);
}
~sString(){}
char m_String[256];
};
#endif
/*
* limit :
* 1. can't use this object in heap area
* 2. last character can't be cKEY
* type : int
* argument :
* 1. (sString*) sString array for store data
* 2. int sString array depth
* 3. (char*) Data Buffer to Parse
* 4. int* Buffer Length
* 5. (char) KEY character you want to split
* return :
* -1. not support
* -2. out of array index
* 0. ok
*/
int sSplitToStringArray(sString* sRetArray,
int iArrayDepth,
char* sStringBuffer,
int* iBufferLen,
char cKEY);
/*
* type : int
* argument :
* 1. (char*) file path want to read
* 2. (BYTE*) buffer pointer for store file
* 3. (int*) buffer size and file size return
* return :
* 0. success
* -1. file read failure
* -2. buffer size not enougth
*/
int iFileR(char* sPath,BYTE* pBUF,int* piSize);
/*
* type : int
* argument :
* 1. Windows Handle
* 2. (char*) Title for display
* 3. (char*) buffer for return string
* return :
* 0. failure
* n. buffer length
*/
int GetPathDialog(HWND hWnd,char* sTitle,char *pBuffer);
/*
* type : int
* argument :
* 1. (char*) Data Buffer to Parse
* 2. int* Buffer Length
* 3. (char*) KEY character you want to find
* 4. int* key length
* 5. int* offset begin from data buffer / first key character occur in buffer
* return :
* 0. success
* -1. failure
*/
int iFindKeyCharacterFromBuffer(char* sDataBuffer,int* iBufferLength,char* sKEY,int* iKEY_Length,int* iOffset);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

BIN
PLCSim2016/res/PLC.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

13
PLCSim2016/res/PLC.rc2 Normal file
View File

@ -0,0 +1,13 @@
//
// PLC.RC2 - resources Microsoft Visual C++ does not edit directly
//
#ifdef APSTUDIO_INVOKED
#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
// Add manually edited resources here...
/////////////////////////////////////////////////////////////////////////////

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

BIN
PLCSim2016/res/icon1.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

BIN
PLCSim2016/res/icon2.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

BIN
PLCSim2016/res/icon3.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

BIN
PLCSim2016/res/run1.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

8
PLCSim2016/stdafx.cpp Normal file
View File

@ -0,0 +1,8 @@
// stdafx.cpp : 표준 포함 파일만 들어 있는 소스 파일입니다.
// PLCSim2016.pch는 미리 컴파일된 헤더가 됩니다.
// stdafx.obj에는 미리 컴파일된 형식 정보가 포함됩니다.
#include "stdafx.h"

53
PLCSim2016/stdafx.h Normal file
View File

@ -0,0 +1,53 @@
// stdafx.h : 자주 사용하지만 자주 변경되지는 않는
// 표준 시스템 포함 파일 및 프로젝트 관련 포함 파일이
// 들어 있는 포함 파일입니다.
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // 거의 사용되지 않는 내용은 Windows 헤더에서 제외합니다.
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 일부 CString 생성자는 명시적으로 선언됩니다.
// MFC의 공통 부분과 무시 가능한 경고 메시지에 대한 숨기기를 해제합니다.
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC 핵심 및 표준 구성 요소입니다.
#include <afxext.h> // MFC 확장입니다.
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // Internet Explorer 4 공용 컨트롤에 대한 MFC 지원입니다.
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // Windows 공용 컨트롤에 대한 MFC 지원입니다.
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h> // MFC의 리본 및 컨트롤 막대 지원
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

8
PLCSim2016/targetver.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
// SDKDDKVer.h를 포함하면 최고 수준의 가용성을 가진 Windows 플랫폼이 정의됩니다.
// 이전 Windows 플랫폼에 대해 응용 프로그램을 빌드하려는 경우에는 SDKDDKVer.h를 포함하기 전에
// WinSDKVer.h를 포함하고 _WIN32_WINNT 매크로를 지원하려는 플랫폼으로 설정하십시오.
#include <SDKDDKVer.h>