├── .clang-format
├── .gitignore
├── mylib
├── ado.cpp
├── cadoclass.htm
├── ColorPickerCB.h
├── ColorPickerCB.cpp
├── StdAfx.cpp
├── resource.h
├── StdAfx.h
├── Tools.h
├── MYLIB.rc
├── StatLink.h
├── CommsLamp.h
├── ColorStatic.h
├── MYLIB.vcxproj.filters
├── StatLink.cpp
├── ColorStatic.cpp
├── MicroTick.h
├── CommsLamp.cpp
└── MicroTick.cpp
├── ModRSsim2
├── _README.CPP
├── res
│ ├── drag.bmp
│ ├── bitmap1.bmp
│ ├── cursor1.cur
│ ├── RTStimes.ico
│ ├── bmp00001.bmp
│ ├── bmp00002.bmp
│ ├── bmp00003.bmp
│ ├── bmp00004.bmp
│ ├── bmp00005.bmp
│ ├── bmp00006.bmp
│ ├── creditbm.bmp
│ ├── ico00001.ico
│ ├── ico00002.ico
│ ├── idr_main.ico
│ ├── multisla.bmp
│ ├── myhandcu.cur
│ ├── toolbar1.bmp
│ ├── MOD_RSsimul.ico
│ └── MOD_RSsim.rc2
├── ColorPickerCB.h
├── EasterDlg.cpp
├── help
│ ├── index.htm
│ └── images
│ │ ├── anim.gif
│ │ ├── juice.gif
│ │ ├── shot1.gif
│ │ ├── shot2.gif
│ │ ├── advemul.gif
│ │ ├── advemul2.GIF
│ │ ├── advmbus.gif
│ │ ├── joyshot.gif
│ │ ├── regsta2.GIF
│ │ └── toolbar.gif
├── ColorPickerCB.cpp
├── StarWarsCtrl.cpp
├── Scripts
│ ├── random.vbs
│ ├── timer.vbs
│ ├── timer1.vbs
│ ├── SIMUL_R0.html
│ ├── 123a.vbs
│ ├── 123.vbs
│ ├── timer2.vbs
│ ├── SIMUL.html
│ ├── input.html
│ └── plcsim.vbs
├── stringcvt.h
├── SelfRegistrationDlg.h
├── ServerSocketArray.h
├── StdAfx.cpp
├── EasterDlg.h
├── simport.h
├── Tools.h
├── DDKSrvSocket.h
├── UpdateCheck.h
├── processor.h
├── ModRSsim2.sln
├── joysccemulation.h
├── serverRS232array.h
├── plantsim.h
├── ServerSettingsEthDlg.h
├── mod_RSsim.odl
├── StarWarsCtrl.h
├── FaultsDlg.h
├── CommsLamp.h
├── EditMemoryDlg.h
├── TrainingSimDlg.h
├── HtmlOutput.h
├── AdvEmulationDlg.h
├── MyHostProxy.h
├── StdAfx.h
├── ServerSettings232Dlg.h
├── SimCmdLine.h
├── CSVFileImportDlg.h
├── Splash.h
├── SelfRegistrationDlg.cpp
├── ActiveScriptHost.h
├── MODEthCommsProcessor.h
├── MemWriteLock.h
├── stringcvt.cpp
├── AnimationSettings.h
├── CSVReader.h
├── mod_RSsim.h
├── About.h
├── joysccemulation.cpp
├── CreditStatic.h
├── ServerSettingsEthDlg.cpp
├── RS232Noise.h
├── util.h
├── MemoryEditorList.h
├── RS232Port.h
├── MicroTick.h
├── CommsLamp.cpp
├── SimCmdLine.cpp
├── message.h
├── simport.cpp
├── UTIL.CPP
└── Resizer.h
└── ReadMe.txt
/.clang-format:
--------------------------------------------------------------------------------
1 | DisableFormat: true
2 | SortIncludes: false
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Debug
2 | Release
3 | .vs
4 | *.user
5 | *.aps
6 |
--------------------------------------------------------------------------------
/mylib/ado.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/mylib/ado.cpp
--------------------------------------------------------------------------------
/mylib/cadoclass.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/mylib/cadoclass.htm
--------------------------------------------------------------------------------
/ModRSsim2/_README.CPP:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/_README.CPP
--------------------------------------------------------------------------------
/ModRSsim2/res/drag.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/drag.bmp
--------------------------------------------------------------------------------
/mylib/ColorPickerCB.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/mylib/ColorPickerCB.h
--------------------------------------------------------------------------------
/ModRSsim2/ColorPickerCB.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/ColorPickerCB.h
--------------------------------------------------------------------------------
/ModRSsim2/EasterDlg.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/EasterDlg.cpp
--------------------------------------------------------------------------------
/ModRSsim2/help/index.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/index.htm
--------------------------------------------------------------------------------
/ModRSsim2/res/bitmap1.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/bitmap1.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/cursor1.cur:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/cursor1.cur
--------------------------------------------------------------------------------
/mylib/ColorPickerCB.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/mylib/ColorPickerCB.cpp
--------------------------------------------------------------------------------
/ModRSsim2/ColorPickerCB.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/ColorPickerCB.cpp
--------------------------------------------------------------------------------
/ModRSsim2/StarWarsCtrl.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/StarWarsCtrl.cpp
--------------------------------------------------------------------------------
/ModRSsim2/res/RTStimes.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/RTStimes.ico
--------------------------------------------------------------------------------
/ModRSsim2/res/bmp00001.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/bmp00001.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/bmp00002.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/bmp00002.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/bmp00003.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/bmp00003.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/bmp00004.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/bmp00004.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/bmp00005.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/bmp00005.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/bmp00006.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/bmp00006.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/creditbm.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/creditbm.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/ico00001.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/ico00001.ico
--------------------------------------------------------------------------------
/ModRSsim2/res/ico00002.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/ico00002.ico
--------------------------------------------------------------------------------
/ModRSsim2/res/idr_main.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/idr_main.ico
--------------------------------------------------------------------------------
/ModRSsim2/res/multisla.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/multisla.bmp
--------------------------------------------------------------------------------
/ModRSsim2/res/myhandcu.cur:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/myhandcu.cur
--------------------------------------------------------------------------------
/ModRSsim2/res/toolbar1.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/toolbar1.bmp
--------------------------------------------------------------------------------
/ModRSsim2/help/images/anim.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/anim.gif
--------------------------------------------------------------------------------
/ModRSsim2/res/MOD_RSsimul.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/res/MOD_RSsimul.ico
--------------------------------------------------------------------------------
/ModRSsim2/help/images/juice.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/juice.gif
--------------------------------------------------------------------------------
/ModRSsim2/help/images/shot1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/shot1.gif
--------------------------------------------------------------------------------
/ModRSsim2/help/images/shot2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/shot2.gif
--------------------------------------------------------------------------------
/ModRSsim2/help/images/advemul.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/advemul.gif
--------------------------------------------------------------------------------
/ModRSsim2/help/images/advemul2.GIF:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/advemul2.GIF
--------------------------------------------------------------------------------
/ModRSsim2/help/images/advmbus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/advmbus.gif
--------------------------------------------------------------------------------
/ModRSsim2/help/images/joyshot.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/joyshot.gif
--------------------------------------------------------------------------------
/ModRSsim2/help/images/regsta2.GIF:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/regsta2.GIF
--------------------------------------------------------------------------------
/ModRSsim2/help/images/toolbar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cavaler/ModRSsim2/HEAD/ModRSsim2/help/images/toolbar.gif
--------------------------------------------------------------------------------
/mylib/StdAfx.cpp:
--------------------------------------------------------------------------------
1 | // stdafx.cpp : source file that includes just the standard includes
2 | // MYLIB.pch will be the pre-compiled header
3 | // stdafx.obj will contain the pre-compiled type information
4 |
5 | #include "stdafx.h"
6 |
7 |
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/random.vbs:
--------------------------------------------------------------------------------
1 | dim n
2 |
3 | Randomize
4 | n = Int((65535 * Rnd) + 1)'Generate random value between 1 and 65535.
5 | n = n - 32767 ' some signed values to test with :-)
6 | SetRegisterValue 3, (270*Rnd), n
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/timer.vbs:
--------------------------------------------------------------------------------
1 | dim x
2 | dim n
3 |
4 | n = int(timer/100)
5 | x = timer - n*100
6 |
7 | SetRegisterValue 3, 0, n
8 | SetRegisterValue 3, 1, x
9 |
10 | if ((int(x/10)*10 - x) >= -1) then
11 | SetRegisterValue 3, 2, x
12 | end if
13 |
14 |
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/timer1.vbs:
--------------------------------------------------------------------------------
1 | dim x
2 | dim n
3 |
4 | n = int(timer/100)
5 | x = GetRegisterValue (3, 0)
6 |
7 | 'SetRegisterValue 3, 0, n
8 | SetRegisterValue 3, 1, x
9 |
10 | 'if ((int(x/10)*10 - x) >= -1) then
11 | ' SetRegisterValue 3, 2, x
12 | 'end if
13 |
14 |
15 | AddDebugString ("test one")
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/SIMUL_R0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My test page
5 |
6 |
7 | Decinal Value: 3,0,1.
8 |
9 | Float Value: 3,0,6.
10 | Long Value: 3,0,5.
11 |
12 |
--------------------------------------------------------------------------------
/ModRSsim2/res/MOD_RSsim.rc2:
--------------------------------------------------------------------------------
1 | //
2 | // MOD_SIM.RC2 - resources Microsoft Visual C++ does not edit directly
3 | //
4 |
5 | #ifdef APSTUDIO_INVOKED
6 | #error this file is not editable by Microsoft Visual C++
7 | #endif //APSTUDIO_INVOKED
8 |
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // Add manually edited resources here...
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 |
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/123a.vbs:
--------------------------------------------------------------------------------
1 | dim x
2 | dim n
3 | dim runtime
4 | dim station
5 |
6 | n=0
7 | for n=1 to 5000
8 | x = getregistervalue(3,n)
9 | SetRegisterValue 3, n, x+1
10 | next
11 | runtime = Getlastruntime
12 | SetRegisterValue 3, 0, runtime
13 |
14 | if (StationEnabled (station)) then
15 | Disablestation station
16 | else
17 | enablestation station
18 | end if
19 |
20 | SetRegisterValue 3, 242, station
21 |
22 | station = station + 1
23 | if station > 12 then station = 0
24 |
--------------------------------------------------------------------------------
/mylib/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Developer Studio generated include file.
3 | // Used by MYLIB.rc
4 | //
5 | #define IDC_MYHANDCURSOR 101
6 |
7 | // Next default values for new objects
8 | //
9 | #ifdef APSTUDIO_INVOKED
10 | #ifndef APSTUDIO_READONLY_SYMBOLS
11 | #define _APS_NEXT_RESOURCE_VALUE 102
12 | #define _APS_NEXT_COMMAND_VALUE 40001
13 | #define _APS_NEXT_CONTROL_VALUE 1000
14 | #define _APS_NEXT_SYMED_VALUE 101
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/123.vbs:
--------------------------------------------------------------------------------
1 | dim x
2 | dim n
3 | dim runtime
4 | dim station
5 |
6 | n=0
7 | for n=0 to 240
8 | x = getregistervalue(3,n)
9 | SetRegisterValue 3, n, x+1
10 | next
11 | runtime = Getlastruntime
12 | SetRegisterValue 3, 241, runtime
13 |
14 | if (StationEnabled (station)) then
15 | Disablestation station
16 | else
17 | enablestation station
18 | end if
19 |
20 | SetRegisterValue 3, 242, station
21 |
22 | station = station + 1
23 | if station > 12 then station = 0
24 |
25 | 'DisplayAbout
26 |
--------------------------------------------------------------------------------
/ModRSsim2/stringcvt.h:
--------------------------------------------------------------------------------
1 | #if !defined(STRING_CONVERSIONS_H_INCLUDED)
2 | #define STRING_CONVERSIONS_H_INCLUDED
3 |
4 | //
5 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
6 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
7 | // ... GPL V3
8 |
9 | #define MAX_WORDHEXSTRINGLENGTH (10) // "0xFF 0xFF"
10 |
11 | void ConvertByteToASCII(CHAR * szString, const BYTE bValue);
12 | void ConvertWordToASCII(CHAR * szString, const WORD wValue);
13 | void ConvertWordToASCIICS(CString& csString, const WORD wValue);
14 | void ConvertASCIIToWord(const char*String, WORD &wValue);
15 |
16 |
17 | #endif
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/timer2.vbs:
--------------------------------------------------------------------------------
1 | dim x
2 | dim n
3 |
4 | n = int(timer/100)
5 | x = timer - n*100
6 |
7 | SetRegisterValue 3, 0, n
8 | SetRegisterValue 3, 1, x
9 |
10 | SetRegisterValue 3, 3, int(x/10)
11 | SetRegisterValue 3, 4, int(x/10)*10
12 | SetRegisterValue 3, 5, int(x/10)* 10 -x
13 |
14 |
15 | 'if ((int(x/10)*10 - x) > -0.5) then
16 | 'Or
17 | 'if (Cint(int(x/10)*10 - x)=0) then
18 | 'Or
19 | if (Cint(int(x/10)*10) = Cint(x)) then
20 | SetRegisterValue 3, 2, x
21 | end if
22 |
23 | x = GetRegisterValue(3, 11)
24 | SetRegisterValue 3, 10, x
25 |
26 | x = Second(Now)
27 | SetRegisterValue 3, 20, x
28 |
29 | x = GetLastRunTime
30 | SetRegisterValue 3, 30, x
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/SIMUL.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ModRSsim2 Test Page
5 |
6 |
7 | Decimal Value: 3,0,1.
8 |
9 | Hex Value: 3,10,2.
10 | Word Value: 3,20,3.
11 | DWord Value: 3,30,4.
12 | Long Value: 3,40,5.
13 | Float Value: 3,50,6.
14 | Chars Value: 3,60,7.
15 | Coil Bit Value: 0,0,1.
16 |
17 |
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ModRSsim2 Test Page
5 |
6 |
7 | Decimal Value: 3,0,1.
8 |
9 | Hex Value: 3,10,2.
10 | Word Value: 3,20,3.
11 | DWord Value: 3,30,4.
12 | Long Value: 3,40,5.
13 | Float Value: 3,50,6.
14 | Chars Value: 3,60,7.
15 | Coil Bit Value: 0,0,1.
16 |
17 |
--------------------------------------------------------------------------------
/ModRSsim2/SelfRegistrationDlg.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | // CSelfRegistrationDlg dialog
5 |
6 | class CSelfRegistrationDlg : public CDialog
7 | {
8 | DECLARE_DYNAMIC(CSelfRegistrationDlg)
9 |
10 | public:
11 | CSelfRegistrationDlg(CWnd* pParent = NULL); // standard constructor
12 | virtual ~CSelfRegistrationDlg();
13 |
14 | void OnDetailsChanged();
15 | // Dialog Data
16 | enum { IDD = IDD_REGISTRATIONDLG };
17 |
18 | protected:
19 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
20 |
21 | DECLARE_MESSAGE_MAP()
22 | public:
23 | afx_msg void OnEnChangeRegistrationKey();
24 | afx_msg void OnEnChangeUsername();
25 | CString m_username;
26 | CString m_registrationkey;
27 | virtual BOOL OnInitDialog();
28 | afx_msg void OnBnClickedOk();
29 | };
30 |
--------------------------------------------------------------------------------
/mylib/StdAfx.h:
--------------------------------------------------------------------------------
1 | // stdafx.h : include file for standard system include files,
2 | // or project specific include files that are used frequently, but
3 | // are changed infrequently
4 | //
5 |
6 | #if !defined(AFX_STDAFX_H__090A43A7_F5DE_450E_B572_6EB2EBB7E8E4__INCLUDED_)
7 | #define AFX_STDAFX_H__090A43A7_F5DE_450E_B572_6EB2EBB7E8E4__INCLUDED_
8 |
9 | #define _WIN32_WINNT 0x501 // Target XP - Changed from 0x502 on 2016-08-07 by DL
10 |
11 | #if _MSC_VER > 1000
12 | #pragma once
13 | #endif // _MSC_VER > 1000
14 |
15 |
16 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | // TODO: reference additional headers your program requires here
23 | #include "mylib.h"
24 | //#include "ado.h"
25 | #include "statlink.h"
26 | #include "colorstatic.h"
27 |
28 |
29 | //{{AFX_INSERT_LOCATION}}
30 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
31 |
32 | #endif // !defined(AFX_STDAFX_H__090A43A7_F5DE_450E_B572_6EB2EBB7E8E4__INCLUDED_)
33 |
--------------------------------------------------------------------------------
/ReadMe.txt:
--------------------------------------------------------------------------------
1 | Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
2 | AUTHOR: Conrad Braam. http://www.plcsimulator.org
3 | email: zaphodikus@hotmail.com
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Affero General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Affero General Public License for more details.
14 |
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program. If not, see .
17 |
18 | Revisions above 8.20
19 | ModRSsim2 (c) Doug Lyons, 2015, 2016
20 | AUTHOR: Doug Lyons http://www.douglyons.us
21 | Support: https://sourceforge.net/p/modrssim2/tickets
22 |
23 | Revisions above 8.22
24 | Support: https://github.com/Cavaler/ModRSsim2/issues
25 |
--------------------------------------------------------------------------------
/ModRSsim2/ServerSocketArray.h:
--------------------------------------------------------------------------------
1 | // ServerSocketArray.h: interface for the CServerSocketArray class.
2 | //
3 | //////////////////////////////////////////////////////////////////////
4 |
5 | #if !defined(AFX_SERVERSOCKETARRAY_H__FFE95178_01F8_4161_870F_B035AD11D09A__INCLUDED_)
6 | #define AFX_SERVERSOCKETARRAY_H__FFE95178_01F8_4161_870F_B035AD11D09A__INCLUDED_
7 |
8 | #if _MSC_VER > 1000
9 | #pragma once
10 | #endif // _MSC_VER > 1000
11 |
12 | class CServerSocketArray : public CObArray
13 | {
14 | public:
15 | CServerSocketArray(int size = 10);
16 | virtual ~CServerSocketArray();
17 |
18 | void CloseAll();
19 | LONG AddServers(int numServers,
20 | int port,
21 | int responseDelay,
22 | BOOL linger,
23 | BOOL MOSCADchecks,
24 | BOOL modifyThenRespond,
25 | BOOL disableWrites,
26 | BOOL rtuFrame,
27 | DWORD PDUSize);
28 | LONG NumberConnected(); // # servers that are still connected
29 | SOCKET FirstConnected(); // # servers that are still connected
30 |
31 | BOOL kill;
32 | BOOL initiating;
33 | };
34 |
35 | #endif // !defined(AFX_SERVERSOCKETARRAY_H__FFE95178_01F8_4161_870F_B035AD11D09A__INCLUDED_)
36 |
--------------------------------------------------------------------------------
/ModRSsim2/StdAfx.cpp:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: STDAFX.cpp
4 | //
5 | //
6 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
7 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
8 | // email: zaphodikus@hotmail.com
9 | //
10 | // This program is free software: you can redistribute it and/or modify
11 | // it under the terms of the GNU Affero General Public License as
12 | // published by the Free Software Foundation, either version 3 of the
13 | // License, or (at your option) any later version.
14 | //
15 | // This program is distributed in the hope that it will be useful,
16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | // GNU Affero General Public License for more details.
19 | //
20 | // You should have received a copy of the GNU Affero General Public License
21 | // along with this program. If not, see .
22 | //
23 | // stdafx.cpp : source file that includes just the standard includes
24 | // MOD_RSsim.pch will be the pre-compiled header
25 | // stdafx.obj will contain the pre-compiled type information
26 | //
27 | /////////////////////////////////////////////////////////////////////////////
28 |
29 | #include "stdafx.h"
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/ModRSsim2/EasterDlg.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_EASTERDLG_H__80DE8125_6D9F_40C0_84B1_4E45FD9D9447__INCLUDED_)
2 | #define AFX_EASTERDLG_H__80DE8125_6D9F_40C0_84B1_4E45FD9D9447__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // EasterDlg.h : header file
8 | //
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // CEasterDlg dialog
12 |
13 | class CEasterDlg : public CDialog
14 | {
15 | // Construction
16 | public:
17 | CEasterDlg(CWnd* pParent = NULL); // standard constructor
18 |
19 | // Dialog Data
20 | //{{AFX_DATA(CEasterDlg)
21 | enum { IDD = IDD_EASTEREGG };
22 | CStarWarsCtrl m_starsCtrl;
23 | //}}AFX_DATA
24 |
25 | CString m_userName;
26 | // Overrides
27 | // ClassWizard generated virtual function overrides
28 | //{{AFX_VIRTUAL(CEasterDlg)
29 | protected:
30 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
31 | //}}AFX_VIRTUAL
32 |
33 | // Implementation
34 | protected:
35 |
36 | // Generated message map functions
37 | //{{AFX_MSG(CEasterDlg)
38 | virtual BOOL OnInitDialog();
39 | afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
40 | //}}AFX_MSG
41 | DECLARE_MESSAGE_MAP()
42 | };
43 |
44 | //{{AFX_INSERT_LOCATION}}
45 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
46 |
47 | #endif // !defined(AFX_EASTERDLG_H__80DE8125_6D9F_40C0_84B1_4E45FD9D9447__INCLUDED_)
48 |
--------------------------------------------------------------------------------
/ModRSsim2/simport.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: SimPort.cpp : headder file
4 | //
5 | // See _README.CPP
6 | //
7 | // interface for the SimulationSerialPort class.
8 | /////////////////////////////////////////////////////////////////////////////
9 |
10 | #if !defined(SIMPORT_H__265B8E5E_6549_42d7_98C5_99CB5BD69127_INCLUDED)
11 | #define SIMPORT_H__265B8E5E_6549_42d7_98C5_99CB5BD69127_INCLUDED
12 |
13 |
14 | #if _MSC_VER > 1000
15 | #pragma once
16 | #endif // _MSC_VER > 1000
17 |
18 | // modbus stuff here
19 | #define MAX_MODBUS_MESSAGELEN 256 // RX of a command
20 | #define MODBUS_HEADDER_LEN 6 // STN CMD and Address and Length fields
21 | #define MODBUS_CRC_LEN 2 // STANDARD CRC Length
22 | #define MODBUS_NORMAL_LEN (MODBUS_HEADDER_LEN + MODBUS_CRC_LEN)
23 |
24 | class SimulationSerialPort : public CRS232Port
25 | {
26 | public:
27 |
28 | DECLARE_DYNAMIC(SimulationSerialPort)
29 |
30 | SimulationSerialPort();
31 |
32 | static LONG CalculateReadAheadLength(const BYTE* rxBuffer, DWORD rxBufferIndex);
33 |
34 | // implemented in the parent class
35 | virtual void ActivateStationLED(LONG stationID) = NULL;
36 | virtual BOOL StationIsEnabled(LONG stationID) = NULL;
37 |
38 | virtual LPCTSTR ProtocolName() = NULL;
39 | // diagnostic
40 |
41 | #ifdef _DEBUG
42 | VOID Dump(CDumpContext& dc) const;
43 | #endif
44 | };
45 |
46 | #endif // SIMPORT_H__265B8E5E_6549_42d7_98C5_99CB5BD69127_INCLUDED
--------------------------------------------------------------------------------
/mylib/Tools.h:
--------------------------------------------------------------------------------
1 | #ifndef TOOLS_H
2 | #define TOOLS_H
3 |
4 |
5 | ///////////////////////////////////////////////////////////////////////////////
6 | // Usefull macros
7 | //
8 | #define KEYDOWN(Key) ((GetKeyState(Key)&0x8000)!=0)
9 | #define VIRTUAL_KEY(nChar,nFlags) (((nFlags)&0x0100)||(nChar)<=VK_ESCAPE||(nChar)>=VK_F1)
10 | #define ANSI_KEY(nChar) ((nChar)>VK_ESCAPE)
11 | #define VK_CTRL_A 1
12 | #define VK_CTRL_Z 26
13 | #define VK_ALT VK_MENU
14 |
15 | // To not have to type the 4 fields !
16 | #define EXPAND_RECT(rc) (rc).left,(rc).top,(rc).right,(rc).bottom
17 |
18 |
19 | ///////////////////////////////////////////////////////////////////////////////
20 | // CRect of the window's client area
21 | ///////////////////////////////////////////////////////////////////////////////
22 | class CClientRect : public CRect
23 | {
24 | public:
25 | CClientRect (HWND hWnd)
26 | {
27 | ::GetClientRect (hWnd, this);
28 | };
29 | CClientRect (const CWnd* pWnd)
30 | {
31 | ::GetClientRect (pWnd->GetSafeHwnd(), this);
32 | };
33 | };
34 |
35 |
36 | ///////////////////////////////////////////////////////////////////////////////
37 | // CRect of the window
38 | ///////////////////////////////////////////////////////////////////////////////
39 | class CWindowRect : public CRect
40 | {
41 | public:
42 | CWindowRect (HWND hWnd)
43 | {
44 | ::GetWindowRect (hWnd, this);
45 | };
46 | CWindowRect (const CWnd* pWnd)
47 | {
48 | ::GetWindowRect (pWnd->GetSafeHwnd(), this);
49 | };
50 | };
51 |
52 |
53 | #endif // TOOLS_H
54 |
--------------------------------------------------------------------------------
/ModRSsim2/Tools.h:
--------------------------------------------------------------------------------
1 | #ifndef TOOLS_H
2 | #define TOOLS_H
3 |
4 |
5 | ///////////////////////////////////////////////////////////////////////////////
6 | // Usefull macros
7 | //
8 | #define KEYDOWN(Key) ((GetKeyState(Key)&0x8000)!=0)
9 | #define VIRTUAL_KEY(nChar,nFlags) (((nFlags)&0x0100)||(nChar)<=VK_ESCAPE||(nChar)>=VK_F1)
10 | #define ANSI_KEY(nChar) ((nChar)>VK_ESCAPE)
11 | #define VK_CTRL_A 1
12 | #define VK_CTRL_Z 26
13 | #define VK_ALT VK_MENU
14 |
15 | // To not have to type the 4 fields !
16 | #define EXPAND_RECT(rc) (rc).left,(rc).top,(rc).right,(rc).bottom
17 |
18 |
19 | ///////////////////////////////////////////////////////////////////////////////
20 | // CRect of the window's client area
21 | ///////////////////////////////////////////////////////////////////////////////
22 | class CClientRect : public CRect
23 | {
24 | public:
25 | CClientRect (HWND hWnd)
26 | {
27 | ::GetClientRect (hWnd, this);
28 | };
29 | CClientRect (const CWnd* pWnd)
30 | {
31 | ::GetClientRect (pWnd->GetSafeHwnd(), this);
32 | };
33 | };
34 |
35 |
36 | ///////////////////////////////////////////////////////////////////////////////
37 | // CRect of the window
38 | ///////////////////////////////////////////////////////////////////////////////
39 | class CWindowRect : public CRect
40 | {
41 | public:
42 | CWindowRect (HWND hWnd)
43 | {
44 | ::GetWindowRect (hWnd, this);
45 | };
46 | CWindowRect (const CWnd* pWnd)
47 | {
48 | ::GetWindowRect (pWnd->GetSafeHwnd(), this);
49 | };
50 | };
51 |
52 |
53 | #endif // TOOLS_H
54 |
--------------------------------------------------------------------------------
/ModRSsim2/DDKSrvSocket.h:
--------------------------------------------------------------------------------
1 | // DDKSrvSocket.h: interface for the CDDKSrvSocket class.
2 | //
3 | //////////////////////////////////////////////////////////////////////
4 |
5 | #if !defined(AFX_DDKSRVSOCKET_H__30C44B26_2876_4CE0_AA67_6A37BD065CAE__INCLUDED_)
6 | #define AFX_DDKSRVSOCKET_H__30C44B26_2876_4CE0_AA67_6A37BD065CAE__INCLUDED_
7 |
8 | #if _MSC_VER > 1000
9 | #pragma once
10 | #endif // _MSC_VER > 1000
11 |
12 |
13 | #include
14 | //extern DWORD m_SockTO; // Ethernet Socket Timeout
15 | //extern DWORD m_localPort;
16 |
17 | // U have to derive from this class in order to use it.
18 | class CDDKSrvSocket : public CDDKSocket
19 | {
20 | public:
21 | CDDKSrvSocket(unsigned short port,unsigned long IPAddrULONG = ADDR_ANY, SOCKET * pServerSocket = NULL);
22 | DECLARE_DYNAMIC(CDDKSrvSocket)
23 |
24 | // diagnostic
25 | #ifdef _DEBUG
26 | VOID Dump(CDumpContext& dc) const;
27 | #endif
28 |
29 | virtual ~CDDKSrvSocket();
30 |
31 | void Poll(CHAR * debugStr);
32 | UINT friend AsyncFriend(LPVOID pParam);
33 |
34 | // user must derive from this class and override this method.
35 | virtual BOOL ProcessData(SOCKET openSocket,
36 | const CHAR *pBuffer,
37 | const DWORD numBytes) = NULL;
38 |
39 | // data
40 | BOOL accepted;
41 | SOCKET AcceptedAsyncSocket;
42 |
43 | public:
44 | CEvent m_threadStartupEvent, m_threadDeadEvent;
45 | protected:
46 | LONG m_debuggerStep;
47 | };
48 |
49 | #endif // !defined(AFX_DDKSRVSOCKET_H__30C44B26_2876_4CE0_AA67_6A37BD065CAE__INCLUDED_)
50 |
--------------------------------------------------------------------------------
/mylib/MYLIB.rc:
--------------------------------------------------------------------------------
1 | //Microsoft Developer Studio generated resource script.
2 | //
3 | #include "resource.h"
4 |
5 | #define APSTUDIO_READONLY_SYMBOLS
6 | /////////////////////////////////////////////////////////////////////////////
7 | //
8 | // Generated from the TEXTINCLUDE 2 resource.
9 | //
10 | #include "afxres.h"
11 |
12 | /////////////////////////////////////////////////////////////////////////////
13 | #undef APSTUDIO_READONLY_SYMBOLS
14 |
15 | /////////////////////////////////////////////////////////////////////////////
16 | // English (U.S.) resources
17 |
18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
19 | #ifdef _WIN32
20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21 | #pragma code_page(1252)
22 | #endif //_WIN32
23 |
24 | #ifdef APSTUDIO_INVOKED
25 | /////////////////////////////////////////////////////////////////////////////
26 | //
27 | // TEXTINCLUDE
28 | //
29 |
30 | 1 TEXTINCLUDE DISCARDABLE
31 | BEGIN
32 | "resource.h\0"
33 | END
34 |
35 | 2 TEXTINCLUDE DISCARDABLE
36 | BEGIN
37 | "#include ""afxres.h""\r\n"
38 | "\0"
39 | END
40 |
41 | 3 TEXTINCLUDE DISCARDABLE
42 | BEGIN
43 | "\r\n"
44 | "\0"
45 | END
46 |
47 | #endif // APSTUDIO_INVOKED
48 |
49 | #endif // English (U.S.) resources
50 | /////////////////////////////////////////////////////////////////////////////
51 |
52 |
53 |
54 | #ifndef APSTUDIO_INVOKED
55 | /////////////////////////////////////////////////////////////////////////////
56 | //
57 | // Generated from the TEXTINCLUDE 3 resource.
58 | //
59 |
60 |
61 | /////////////////////////////////////////////////////////////////////////////
62 | #endif // not APSTUDIO_INVOKED
63 |
64 |
--------------------------------------------------------------------------------
/ModRSsim2/UpdateCheck.h:
--------------------------------------------------------------------------------
1 | // UpdateCheck.h
2 | // from CodeProject.com
3 | // by Alexander Bischofberger - http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=14715
4 | // source - http://www.codeproject.com/KB/cpp/updatecheck.aspx
5 | //////////////////////////////////////////////////////////////////////
6 |
7 | #if !defined(AFX_UPDATECHECK_H__6D1C0A60_F616_43C6_9850_F3C0F052C0DB__INCLUDED_)
8 | #define AFX_UPDATECHECK_H__6D1C0A60_F616_43C6_9850_F3C0F052C0DB__INCLUDED_
9 |
10 | #if _MSC_VER > 1000
11 | #pragma once
12 | #endif // _MSC_VER > 1000
13 | #include
14 |
15 | #include
16 |
17 |
18 | #define UPDATECHECK_BROWSER_STRING _T("Update search")
19 |
20 | class CUpdateCheck
21 | {
22 | public:
23 | virtual void Check(UINT uiURL);
24 | virtual bool Check(const CString& strURL); // was void. Changed to send success or fail by DL on 2016-07-13
25 | CUpdateCheck();
26 | virtual ~CUpdateCheck();
27 |
28 | static HINSTANCE GotoURL(LPCTSTR url, int showcmd);
29 | static BOOL GetFileVersion(DWORD &dwMS, DWORD &dwLS);
30 | static LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);
31 | bool InternetReadWholeFile(HINTERNET hUrl,LPVOID lpBuffer,DWORD dwNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead);
32 |
33 | protected:
34 | // override these methods if necessary
35 | virtual void MsgUpdateAvailable(DWORD dwMSlocal, DWORD dwLSlocal, DWORD dwMSWeb, DWORD dwLSWeb, const CString& strURL);
36 | virtual void MsgUpdateNotAvailable(DWORD dwMSlocal, DWORD dwLSlocal);
37 | virtual void MsgUpdateNoCheck(DWORD dwMSlocal, DWORD dwLSlocal);
38 | };
39 |
40 | #endif // !defined(AFX_UPDATECHECK_H__6D1C0A60_F616_43C6_9850_F3C0F052C0DB__INCLUDED_)
41 |
--------------------------------------------------------------------------------
/ModRSsim2/processor.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _PROCESSOR_H_INLCUDED
3 | #define _PROCESSOR_H_INLCUDED
4 |
5 | ///////////////////////////////////////////////////////////////////////////////////
6 | // Declares the BASE communication state-engine, which will simulate
7 | // a real CPU's actions.
8 | //
9 | // TCP/Ethernet comms is far simpler, and has no state engine, TCP/IP protocols
10 | // will derive a CPU class directly from the socket wrapper class.
11 | class CCommsProcessor : public SimulationSerialPort
12 | {
13 | public:
14 | DECLARE_DYNAMIC(CCommsProcessor)
15 |
16 | CCommsProcessor(LPCTSTR portNameShort,
17 | DWORD baud,
18 | DWORD byteSize,
19 | DWORD parity,
20 | DWORD stopBits,
21 | DWORD rts,
22 | int responseDelay);
23 |
24 | virtual ~CCommsProcessor();
25 |
26 | virtual BOOL OnProcessData(const CHAR *pBuffer, DWORD numBytes, BOOL *discardData) = NULL;
27 |
28 | void SetPDUSize(DWORD size) {m_PDUSize = size;};
29 |
30 | // overrridden functions
31 | virtual void RSDataDebugger(const BYTE * buffer, LONG length, int transmit);
32 | void RSStateChanged(DWORD state);
33 |
34 | virtual void ActivateStation(LONG stationID);
35 | virtual BOOL StationIsActivated(LONG stationID);
36 |
37 | // data/members
38 | virtual BOOL IsMasterBusy() {return(TRUE);}
39 | virtual BOOL SupportsMaster() {return(FALSE);}
40 |
41 | UINT m_responseDelay;
42 | //BOOL m_MOSCADchecks; // MOSCAD
43 | //CRS232Noise m_NoiseSimulator;
44 |
45 | CRITICAL_SECTION stateCS;
46 |
47 | private:
48 |
49 | DWORD m_PDUSize;
50 | };
51 |
52 |
53 | #endif //_PROCESSOR_H_INLCUDED
--------------------------------------------------------------------------------
/ModRSsim2/ModRSsim2.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.33423.256
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ModRSsim2", "ModRSsim2.vcxproj", "{7690E3EF-B981-43F5-A13D-A7C70A56C000}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {492645C1-2BFF-4C83-8C77-6F82D91CC490} = {492645C1-2BFF-4C83-8C77-6F82D91CC490}
9 | EndProjectSection
10 | EndProject
11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MYLIB", "..\mylib\MYLIB.vcxproj", "{492645C1-2BFF-4C83-8C77-6F82D91CC490}"
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Win32 = Debug|Win32
16 | Release|Win32 = Release|Win32
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {7690E3EF-B981-43F5-A13D-A7C70A56C000}.Debug|Win32.ActiveCfg = Debug|Win32
20 | {7690E3EF-B981-43F5-A13D-A7C70A56C000}.Debug|Win32.Build.0 = Debug|Win32
21 | {7690E3EF-B981-43F5-A13D-A7C70A56C000}.Release|Win32.ActiveCfg = Release|Win32
22 | {7690E3EF-B981-43F5-A13D-A7C70A56C000}.Release|Win32.Build.0 = Release|Win32
23 | {492645C1-2BFF-4C83-8C77-6F82D91CC490}.Debug|Win32.ActiveCfg = Debug|Win32
24 | {492645C1-2BFF-4C83-8C77-6F82D91CC490}.Debug|Win32.Build.0 = Debug|Win32
25 | {492645C1-2BFF-4C83-8C77-6F82D91CC490}.Release|Win32.ActiveCfg = Release|Win32
26 | {492645C1-2BFF-4C83-8C77-6F82D91CC490}.Release|Win32.Build.0 = Release|Win32
27 | EndGlobalSection
28 | GlobalSection(SolutionProperties) = preSolution
29 | HideSolutionNode = FALSE
30 | EndGlobalSection
31 | GlobalSection(ExtensibilityGlobals) = postSolution
32 | SolutionGuid = {43AC3ABF-718D-4EA0-AC0E-06F3ADE63BE3}
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/ModRSsim2/joysccemulation.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_JOYSCCEMULATION_H__B0688A3C_3519_489A_98EB_FEB88DFA5B32__INCLUDED_)
2 | #define AFX_JOYSCCEMULATION_H__B0688A3C_3519_489A_98EB_FEB88DFA5B32__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // JoySCCEmulation.h : header file
8 | //
9 |
10 | #include "AdvEmulationDlg.h"
11 |
12 | /////////////////////////////////////////////////////////////////////////////
13 | // CJoySCCEmulationDlg dialog
14 |
15 | class CJoySCCEmulationDlg : public CDialog
16 | {
17 | // Construction
18 | public:
19 | CJoySCCEmulationDlg(CWnd* pParent = NULL); // standard constructor
20 |
21 | // Dialog Data
22 | //{{AFX_DATA(CJoySCCEmulationDlg)
23 | enum { IDD = IDD_JOYSCC_EMULATION };
24 | UINT m_destAddr;
25 | UINT m_sourceAddr;
26 | BOOL m_runMode;
27 | UINT m_numShields;
28 | BOOL m_readVariables;
29 | BOOL m_writeVariables;
30 | UINT m_ABidletime;
31 | UINT m_ABtimeout;
32 | //}}AFX_DATA
33 |
34 | CAdvEmulationDlg *m_emuDlgPtr;
35 | BOOL m_emulationOK;
36 |
37 | SetCurrentTopic m_topic;
38 |
39 | // Overrides
40 | // ClassWizard generated virtual function overrides
41 | //{{AFX_VIRTUAL(CJoySCCEmulationDlg)
42 | protected:
43 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
44 | //}}AFX_VIRTUAL
45 |
46 | // Implementation
47 | protected:
48 |
49 | // Generated message map functions
50 | //{{AFX_MSG(CJoySCCEmulationDlg)
51 | virtual void OnOK();
52 | virtual void OnCancel();
53 | afx_msg void OnEmu();
54 | //}}AFX_MSG
55 | DECLARE_MESSAGE_MAP()
56 | };
57 |
58 | //{{AFX_INSERT_LOCATION}}
59 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
60 |
61 | #endif // !defined(AFX_JOYSCCEMULATION_H__B0688A3C_3519_489A_98EB_FEB88DFA5B32__INCLUDED_)
62 |
--------------------------------------------------------------------------------
/ModRSsim2/serverRS232array.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: ServerRS232Array.h : headder file
4 | //
5 | // See _README.CPP
6 | //
7 | // interface for the CServerRS232Array class.
8 | //
9 | /////////////////////////////////////////////////////////////////////////////
10 |
11 | #if !defined(AFX_ServerRS232Array_H__FFE95178_01F8_4161_870F_B035AD11D09A__INCLUDED_)
12 | #define AFX_ServerRS232Array_H__FFE95178_01F8_4161_870F_B035AD11D09A__INCLUDED_
13 |
14 | #if _MSC_VER > 1000
15 | #pragma once
16 | #endif // _MSC_VER > 1000
17 |
18 | class CServerRS232Array : public CObArray
19 | {
20 | public:
21 | CServerRS232Array(int size = 2);
22 | virtual ~CServerRS232Array();
23 |
24 | void CloseAll();
25 | LONG AddServers(DWORD protocolSel,
26 | LPCTSTR portNameShort,
27 | DWORD baud,
28 | DWORD byteSize,
29 | DWORD parity,
30 | DWORD stopBits,
31 | DWORD rts,
32 | int responseDelay,
33 | BOOL MOSCADchecks,
34 | BOOL modifyThenRespond,
35 | BOOL disableWrites,
36 | DWORD PDUSize,
37 | BOOL useBCC,
38 | DWORD source,
39 | DWORD dest,
40 | DWORD files,
41 | BOOL run,
42 | BOOL JOYread,
43 | BOOL JOYwrite,
44 | DWORD masterIdleTime,
45 | DWORD timeoutValue,
46 | BOOL longTimeouts
47 | );
48 | LONG NumberConnected(); // # servers that are still connected
49 | };
50 |
51 | #endif // !defined(AFX_ServerRS232Array_H__FFE95178_01F8_4161_870F_B035AD11D09A__INCLUDED_)
52 |
--------------------------------------------------------------------------------
/mylib/StatLink.h:
--------------------------------------------------------------------------------
1 | #ifndef _STATLINK_CLASS_H_INCLUDED
2 | #define _STATLINK_CLASS_H_INCLUDED
3 | //////////////////////////////////////////////////////////////////
4 | // CStaticLink 1997 Microsoft Systems Journal.
5 | // If this program works, it was written by Paul DiLascia.
6 | // If not, I don't know who wrote it.
7 | ////////////////
8 | // CStaticLink implements a static control that's a hyperlink
9 | // to any file on your desktop or web. You can use it in dialog boxes
10 | // to create hyperlinks to web sites. When clicked, opens the file/URL
11 | //
12 | class CStaticLink : public CStatic {
13 | public:
14 | CStaticLink();
15 |
16 | //{{AFX_VIRTUAL(CStaticLink)
17 | public:
18 | //}}AFX_VIRTUAL
19 |
20 | // you can change these any time:
21 | COLORREF m_colorUnvisited; // color for unvisited
22 | COLORREF m_colorVisited; // color for visited
23 | BOOL m_bVisited; // whether visited or not
24 |
25 | // URL/filename for non-text controls (e.g., icon, bitmap) or when link is
26 | // different from window text. If you don't set this, CStaticLink will
27 | // use GetWindowText to get the link.
28 | CString m_link;
29 | HCURSOR m_hHandCursor;
30 |
31 | void SetHoverCursorHandle(HCURSOR handle) {m_hHandCursor = handle;}
32 |
33 | protected:
34 | DECLARE_DYNAMIC(CStaticLink)
35 | CFont m_font; // underline font for text control
36 |
37 | //{{AFX_MSG(CStaticLink)
38 | afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
39 | //}}AFX_MSG
40 |
41 | // message handlers
42 | afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
43 | afx_msg void OnClicked();
44 | DECLARE_MESSAGE_MAP()
45 | };
46 |
47 | #endif // _STATLINK_CLASS_H_INCLUDED
--------------------------------------------------------------------------------
/ModRSsim2/plantsim.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE; plantsim.h ; header file
4 | //
5 | // See "_README.CPP"
6 | // built-in plant simulation module constants
7 | //
8 | /////////////////////////////////////////////////////////////////////////////
9 |
10 |
11 | //////////////////////////////////////////////////////////////////////////////////////
12 | // Plant Simulation section
13 | #define AMBIENT 2100 // 21 deg C.
14 | #define TEMPMAX 11000 // 110 deg C.
15 |
16 | // PS or PlantSim registers
17 | #define PS_MASK_INPUT1 0x01
18 | #define PS_MASK_INPUT2 0x02
19 | #define PS_MASK_DRAIN 0x04
20 | #define PS_MASK_HEATER 0x08
21 | #define PS_MASK_RESET 0x10
22 | #define PS_MASK_LOWLEVEL 0x20
23 | #define PS_MASK_AUTO 0x40
24 | #define PS_STIRRER_START 0x80
25 |
26 |
27 | #define PS_CONTROLBITS 0 // register 1
28 | #define PS_FEEDBACKBITS 1 // reflected PS_CONTROLBITS
29 | #define PS_MIXERTIME 2
30 | #define PS_LEVEL 3 //
31 | #define PS_MAXLEVEL 4 //
32 | #define PS_TANK1LEVEL 5
33 | #define PS_MAXTANK1LEVEL 6
34 | #define PS_TANK2LEVEL 7
35 | #define PS_MAXTANK2LEVEL 8
36 | #define PS_TEMP 9 // register 5
37 | #define PS_TEMPSETPOINT 10
38 | #define PS_HEATERAMPS 11
39 | #define PS_HEATEREFFECT 12 // heater effectiveness
40 | #define PS_MILLISECONDS 13
41 | #define PS_SECONDS 14
42 | #define PS_MINUTES 15
43 | #define PS_HOURS 16
44 | #define PS_DAY 17
45 | #define PS_WEEKDAY 18 // 0=sunday
46 | #define PS_RANDOM 19
47 | #define PS_LASTREGISTER (PS_RANDOM)
48 |
49 | #define PS_AUTO_HYSTERESIS 200 // 1 degrees
50 |
51 | extern char *plantSim_registerNames[PS_LASTREGISTER+1];
52 |
53 |
--------------------------------------------------------------------------------
/ModRSsim2/ServerSettingsEthDlg.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_ESERVERSETTINGSDLG_H__5EE467B0_3A96_41BA_BEC2_27A1C3528C4E__INCLUDED_)
2 | #define AFX_ESERVERSETTINGSDLG_H__5EE467B0_3A96_41BA_BEC2_27A1C3528C4E__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // ServerSettingsDlg.h : header file
8 | //
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // CServerSettingsEthDlg dialog
12 |
13 | class CServerSettingsEthDlg : public CDialog
14 | {
15 | // Construction
16 | public:
17 | CServerSettingsEthDlg(CWnd* pParent = NULL); // standard constructor
18 |
19 | // Dialog Data
20 | //{{AFX_DATA(CServerSettingsEthDlg)
21 | enum { IDD = IDD_SERVERSETTINGS_ETH };
22 | UINT m_localPort;
23 | UINT m_SockTO;
24 | UINT m_responseDelay;
25 | BOOL m_linger;
26 | UINT m_numServers;
27 | CString m_localIPStr;
28 | CString m_remoteIPStr;
29 | DWORD m_other;
30 | BOOL m_autoLoad; // Added 2015-07-19 by DL to show these on Eth screen
31 | BOOL m_startAsOff; // Added 2015-07-19 by DL to show these on Eth screen
32 | BOOL m_rtuFrame;
33 | //}}AFX_DATA
34 |
35 |
36 | // Overrides
37 | // ClassWizard generated virtual function overrides
38 | //{{AFX_VIRTUAL(CServerSettingsEthDlg)
39 | protected:
40 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
41 | //}}AFX_VIRTUAL
42 |
43 | SetCurrentTopic m_topic;
44 |
45 | // Implementation
46 | protected:
47 |
48 | // Generated message map functions
49 | //{{AFX_MSG(CServerSettingsEthDlg)
50 | virtual void OnOK();
51 | virtual BOOL OnInitDialog();
52 | //}}AFX_MSG
53 | DECLARE_MESSAGE_MAP()
54 | };
55 |
56 | //{{AFX_INSERT_LOCATION}}
57 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
58 |
59 | #endif // !defined(AFX_ESERVERSETTINGSDLG_H__5EE467B0_3A96_41BA_BEC2_27A1C3528C4E__INCLUDED_)
60 |
--------------------------------------------------------------------------------
/ModRSsim2/mod_RSsim.odl:
--------------------------------------------------------------------------------
1 | // mod_rssim.odl : type library source for mod_rssim.exe
2 |
3 | // This file will be processed by the MIDL compiler to produce the
4 | // type library (mod_rssim.tlb).
5 |
6 | [ uuid(4E917CC5-A38B-4ae4-9241-C1B0A7FF317D), version(1.0) ]
7 | library mod_rssim
8 | {
9 | importlib("stdole32.tlb");
10 | importlib("stdole2.tlb");
11 |
12 |
13 | // Primary dispatch interface for CMyHostProxy
14 |
15 | [ uuid(8570A0E2-963E-4673-8404-0D5D685B5B23) ]
16 | dispinterface IMyHostProxy
17 | {
18 | properties:
19 | // NOTE - ClassWizard will maintain property information here.
20 | // Use extreme caution when editing this section.
21 | //{{AFX_ODL_PROP(CMyHostProxy)
22 | //}}AFX_ODL_PROP
23 |
24 | methods:
25 | // NOTE - ClassWizard will maintain method information here.
26 | // Use extreme caution when editing this section.
27 | //{{AFX_ODL_METHOD(CMyHostProxy)
28 | [id(1)] short GetRegisterValue(long registertype, long registernumber);
29 | [id(2)] void EnableStation(short stationid);
30 | [id(3)] void DisableStation(short stationid);
31 | [id(4)] void DisplayAbout();
32 | [id(5)] long GetLastRunTime();
33 | [id(6)] void SetRegisterValue(long registertype, long registernumber, long registervalue);
34 | [id(7)] long StationEnabled(short stationid);
35 | [id(8)] void ClearRegisters();
36 | [id(9)] long TransmitRegisters(short sourceStation, short destinationStation, long file_areaNumber, long startRegister, long numRegisters);
37 | [id(10)] void AddDebugString(BSTR text);
38 | [id(11)] long TransacationBusy();
39 | //}}AFX_ODL_METHOD
40 |
41 | };
42 |
43 | // Class information for CMyHostProxy
44 |
45 | [ uuid(BC4F4528-805B-4F08-9B17-78BE23DF531D) ]
46 | coclass MyHostProxy
47 | {
48 | [default] dispinterface IMyHostProxy;
49 | };
50 |
51 | //{{AFX_APPEND_ODL}}
52 | //}}AFX_APPEND_ODL}}
53 | };
54 |
--------------------------------------------------------------------------------
/ModRSsim2/StarWarsCtrl.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_STARWARSCTRL_H__B75B0B9E_367D_11D6_AB38_00D0B70C3D79__INCLUDED_)
2 | #define AFX_STARWARSCTRL_H__B75B0B9E_367D_11D6_AB38_00D0B70C3D79__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // StarWarsCtrl.h : header file
8 | //
9 | // See "StarWarsCtrl.cpp" for details
10 |
11 | #define NUM_STARS 100
12 |
13 |
14 | class CStarWarsCtrl : public CStatic
15 | {
16 | struct CStar
17 | {
18 | int x;
19 | int y;
20 | int z;
21 | };
22 |
23 | CStar m_StarArray[NUM_STARS];
24 |
25 | // Construction
26 | public:
27 | CStarWarsCtrl();
28 |
29 | // Attributes
30 | public:
31 |
32 | // Operations
33 | public:
34 |
35 | // Overrides
36 | // ClassWizard generated virtual function overrides
37 | //{{AFX_VIRTUAL(CStarWarsCtrl)
38 | protected:
39 | virtual void PreSubclassWindow();
40 | //}}AFX_VIRTUAL
41 |
42 | // Implementation
43 | public:
44 | void AddTextLine(LPCTSTR lpszText);
45 | void SetStarSpeed(int nSpeed);
46 | void SetScrollSpeed(int nSpeed);
47 | virtual ~CStarWarsCtrl();
48 |
49 | // Generated message map functions
50 | protected:
51 | int m_nStarsSpeed;
52 | int m_nScrollSpeed;
53 | int m_nScrollPos;
54 | void DoScrollText(CDC *pDC);
55 | void DoStars(CDC *pDC);
56 | void InvalidateCtrl();
57 |
58 | CFont m_Font;
59 |
60 | CRect m_rectClient;
61 |
62 | CDC m_MainDC;
63 | CBitmap m_MainBitmap;
64 |
65 | CBitmap *m_pOldBitmap;
66 |
67 | CStringArray m_TextLines;
68 | //{{AFX_MSG(CStarWarsCtrl)
69 | afx_msg void OnPaint();
70 | afx_msg void OnSize(UINT nType, int cx, int cy);
71 | afx_msg void OnTimer(UINT nIDEvent);
72 | //}}AFX_MSG
73 |
74 | DECLARE_MESSAGE_MAP()
75 | };
76 |
77 | //{{AFX_INSERT_LOCATION}}
78 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
79 |
80 | #endif // !defined(AFX_STARWARSCTRL_H__B75B0B9E_367D_11D6_AB38_00D0B70C3D79__INCLUDED_)
81 |
--------------------------------------------------------------------------------
/ModRSsim2/FaultsDlg.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_FAULTSDLG_H__03268BDB_A3F4_4A6D_8590_C7DB7326B890__INCLUDED_)
2 | #define AFX_FAULTSDLG_H__03268BDB_A3F4_4A6D_8590_C7DB7326B890__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // FaultsDlg.h : header file
8 | //
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // CFaultsDlg dialog
12 |
13 | class CFaultsDlg : public CDialog
14 | {
15 | // Construction
16 | public:
17 | CFaultsDlg(CWnd* pParent = NULL); // standard constructor
18 |
19 | // Dialog Data
20 | //{{AFX_DATA(CFaultsDlg)
21 | enum { IDD = IDD_FAULTSDLG };
22 | CSliderCtrl m_freqSlider;
23 | BOOL m_beep;
24 | int m_delaysPeriod;
25 | int m_errorFrequency;
26 | BOOL m_insertCharacters;
27 | BOOL m_removeCharacters;
28 | BOOL m_modifyCharacters;
29 | BOOL m_ignoreReq;
30 | BOOL m_corruptFraming;
31 | BOOL m_parityFaults;
32 | BOOL m_errors;
33 | BOOL m_etherNet;
34 | //}}AFX_DATA
35 |
36 | protected:
37 | // TOOLTIPS
38 | CToolTipCtrl m_ToolTip;
39 | BOOL OnTTN_NeedText( UINT id, NMHDR * pTTTStruct, LRESULT * pResult );
40 |
41 | // Overrides
42 | // ClassWizard generated virtual function overrides
43 | //{{AFX_VIRTUAL(CFaultsDlg)
44 | public:
45 | virtual BOOL PreTranslateMessage(MSG* pMsg);
46 | protected:
47 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
48 | //}}AFX_VIRTUAL
49 |
50 | // Implementation
51 | protected:
52 |
53 | // Generated message map functions
54 | //{{AFX_MSG(CFaultsDlg)
55 | afx_msg void OnBeepClicked();
56 | afx_msg void OnDelaysClicked();
57 | afx_msg void OnEnableClicked();
58 | virtual BOOL OnInitDialog();
59 | virtual void OnOK();
60 | //}}AFX_MSG
61 | DECLARE_MESSAGE_MAP()
62 | };
63 |
64 | //{{AFX_INSERT_LOCATION}}
65 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
66 |
67 | #endif // !defined(AFX_FAULTSDLG_H__03268BDB_A3F4_4A6D_8590_C7DB7326B890__INCLUDED_)
68 |
--------------------------------------------------------------------------------
/mylib/CommsLamp.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_COMMSLAMP_H__CC09A381_06D6_4D45_95C3_A6583D61501D__INCLUDED_)
2 | #define AFX_COMMSLAMP_H__CC09A381_06D6_4D45_95C3_A6583D61501D__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // CommsLamp.h : header file
8 | //
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // CCommsLamp window
12 |
13 | class CCommsLamp : public CButton
14 | {
15 | // Construction
16 | public:
17 | CCommsLamp();
18 |
19 | BOOL SetupLamp(DWORD onTimerDuration);
20 | // Attributes
21 | public:
22 | COLORREF GetONcolor() { return m_ONcolor;};
23 | COLORREF GetOFFcolor() { return m_OFFcolor;};
24 | BOOL GetState() { return m_state;};
25 |
26 | // Operations
27 | public:
28 | void SetONcolor(COLORREF color) {m_ONcolor = color; UpdateMyCtrl();};
29 | void SetOFFcolor(COLORREF color) {m_OFFcolor = color; UpdateMyCtrl();};
30 | void SetState(BOOL state);
31 |
32 | // Overrides
33 | // ClassWizard generated virtual function overrides
34 | //{{AFX_VIRTUAL(CCommsLamp)
35 | public:
36 | virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
37 | protected:
38 | virtual void PreSubclassWindow();
39 | //}}AFX_VIRTUAL
40 |
41 | // Implementation
42 | public:
43 | virtual ~CCommsLamp();
44 |
45 | // Generated message map functions
46 | protected:
47 | //{{AFX_MSG(CCommsLamp)
48 | afx_msg void OnPaint();
49 | afx_msg void OnDestroy();
50 | afx_msg void OnTimer(UINT nIDEvent);
51 | //}}AFX_MSG
52 |
53 | // methods
54 | void UpdateMyCtrl();
55 |
56 | // variables
57 | BOOL m_state;
58 | COLORREF m_ONcolor, m_OFFcolor;
59 |
60 | DWORD m_timerDuration;
61 | DWORD m_timerID;
62 |
63 | DECLARE_MESSAGE_MAP()
64 | };
65 |
66 | /////////////////////////////////////////////////////////////////////////////
67 |
68 | //{{AFX_INSERT_LOCATION}}
69 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
70 |
71 | #endif // !defined(AFX_COMMSLAMP_H__CC09A381_06D6_4D45_95C3_A6583D61501D__INCLUDED_)
72 |
--------------------------------------------------------------------------------
/ModRSsim2/CommsLamp.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_COMMSLAMP_H__CC09A381_06D6_4D45_95C3_A6583D61501D__INCLUDED_)
2 | #define AFX_COMMSLAMP_H__CC09A381_06D6_4D45_95C3_A6583D61501D__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // CommsLamp.h : header file
8 | //
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // CCommsLamp window
12 |
13 | class CCommsLamp : public CButton
14 | {
15 | // Construction
16 | public:
17 | CCommsLamp();
18 |
19 | BOOL SetupLamp(DWORD onTimerDuration);
20 | // Attributes
21 | public:
22 | COLORREF GetONcolor() { return m_ONcolor;};
23 | COLORREF GetOFFcolor() { return m_OFFcolor;};
24 | BOOL GetState() { return m_state;};
25 |
26 | // Operations
27 | public:
28 | void SetONcolor(COLORREF color) {m_ONcolor = color; UpdateMyCtrl();};
29 | void SetOFFcolor(COLORREF color) {m_OFFcolor = color; UpdateMyCtrl();};
30 | void SetState(BOOL state);
31 |
32 | // Overrides
33 | // ClassWizard generated virtual function overrides
34 | //{{AFX_VIRTUAL(CCommsLamp)
35 | public:
36 | virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
37 | protected:
38 | virtual void PreSubclassWindow();
39 | //}}AFX_VIRTUAL
40 |
41 | // Implementation
42 | public:
43 | virtual ~CCommsLamp();
44 |
45 | // Generated message map functions
46 | protected:
47 | //{{AFX_MSG(CCommsLamp)
48 | afx_msg void OnPaint();
49 | afx_msg void OnDestroy();
50 | afx_msg void OnTimer(UINT nIDEvent);
51 | //}}AFX_MSG
52 |
53 | // methods
54 | void UpdateMyCtrl();
55 |
56 | // variables
57 | BOOL m_state;
58 | COLORREF m_ONcolor, m_OFFcolor;
59 |
60 | DWORD m_timerDuration;
61 | DWORD m_timerID;
62 |
63 | DECLARE_MESSAGE_MAP()
64 | };
65 |
66 | /////////////////////////////////////////////////////////////////////////////
67 |
68 | //{{AFX_INSERT_LOCATION}}
69 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
70 |
71 | #endif // !defined(AFX_COMMSLAMP_H__CC09A381_06D6_4D45_95C3_A6583D61501D__INCLUDED_)
72 |
--------------------------------------------------------------------------------
/ModRSsim2/EditMemoryDlg.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_EDITMEMORYDLG_H__3B29C5BB_9C00_4EFD_B8B2_8E7E5D322F29__INCLUDED_)
2 | #define AFX_EDITMEMORYDLG_H__3B29C5BB_9C00_4EFD_B8B2_8E7E5D322F29__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // FILE: EditMemoryDlg.h : headder file
10 | //
11 | // See _README.CPP
12 | //
13 | /////////////////////////////////////////////////////////////////////////////
14 |
15 | extern void ConvertWordToASCIICS(CString& csString, const WORD wValue);
16 | extern void ConvertASCIIToWord(const char*String, WORD &wValue);
17 | /////////////////////////////////////////////////////////////////////////////
18 | // CEditMemoryDlg dialog
19 |
20 | class CEditMemoryDlg : public CDialog
21 | {
22 | // Construction
23 | public:
24 | CEditMemoryDlg(LPCTSTR formatting, LPCTSTR registerName, DWORD memoryValue, WORD valueType, LPCTSTR description, CWnd* pParent = NULL); // standard constructor
25 |
26 | // Dialog Data
27 | //{{AFX_DATA(CEditMemoryDlg)
28 | enum { IDD = IDD_EDITMEMCELL };
29 | // NOTE: the ClassWizard will add data members here
30 | //}}AFX_DATA
31 |
32 | CString m_description;
33 | DWORDLONG m_value; // changed from DWORD to allow 64-bit numbers for over/under value comparisons by DL on 2016-07-10
34 | CString m_formatting;
35 | CString m_registerName;
36 |
37 | WORD m_valueType;
38 | // Overrides
39 | // ClassWizard generated virtual function overrides
40 | //{{AFX_VIRTUAL(CEditMemoryDlg)
41 | protected:
42 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
43 | //}}AFX_VIRTUAL
44 |
45 | // Implementation
46 | protected:
47 |
48 | // Generated message map functions
49 | //{{AFX_MSG(CEditMemoryDlg)
50 | virtual BOOL OnInitDialog();
51 | virtual void OnOK();
52 | //}}AFX_MSG
53 | DECLARE_MESSAGE_MAP()
54 | };
55 |
56 | //{{AFX_INSERT_LOCATION}}
57 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
58 |
59 | #endif // !defined(AFX_EDITMEMORYDLG_H__3B29C5BB_9C00_4EFD_B8B2_8E7E5D322F29__INCLUDED_)
60 |
--------------------------------------------------------------------------------
/ModRSsim2/TrainingSimDlg.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_TRAININGSIMDLG_H__CD8860EF_5F04_46CF_8D62_1F6F6DBAD2D8__INCLUDED_)
2 | #define AFX_TRAININGSIMDLG_H__CD8860EF_5F04_46CF_8D62_1F6F6DBAD2D8__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // TrainingSimDlg.h : header file
8 | //
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // CTrainingSimDlg dialog
12 |
13 | #include "plantsim.h"
14 |
15 | class CTrainingSimDlg : public CDialog
16 | {
17 | // Construction
18 | public:
19 | CTrainingSimDlg(CWnd* pParent = NULL); // standard constructor
20 |
21 | void ToggleCheckOnItem(int checkID, int bitNum);
22 | int m_selectedRegister;
23 | SetCurrentTopic m_topic;
24 |
25 | // Dialog Data
26 | //{{AFX_DATA(CTrainingSimDlg)
27 | enum { IDD = IDD_TRAININGSIM };
28 | CComboBox m_registerNames;
29 | //}}AFX_DATA
30 |
31 | // TOOLTIPS
32 | CToolTipCtrl m_ToolTip;
33 | int m_numDisabledControls;
34 | CWnd *m_pDisabledControls[256]; //only can get 256 controls
35 |
36 | // Overrides
37 | // ClassWizard generated virtual function overrides
38 | //{{AFX_VIRTUAL(CTrainingSimDlg)
39 | public:
40 | virtual BOOL PreTranslateMessage(MSG* pMsg);
41 | protected:
42 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
43 | //}}AFX_VIRTUAL
44 |
45 | // Implementation
46 | protected:
47 |
48 | // Generated message map functions
49 | //{{AFX_MSG(CTrainingSimDlg)
50 | virtual BOOL OnInitDialog();
51 | afx_msg void OnSet();
52 | afx_msg void OnTimer(UINT nIDEvent);
53 | afx_msg void OnSelchangeCbregisternames();
54 | afx_msg void OnCheck1();
55 | afx_msg void OnCheck2();
56 | afx_msg void OnCheck3();
57 | afx_msg void OnCheck4();
58 | afx_msg void OnCheck5();
59 | afx_msg void OnCheck6();
60 | afx_msg void OnCheck7();
61 | afx_msg void OnCheck8();
62 | //}}AFX_MSG
63 | DECLARE_MESSAGE_MAP()
64 | };
65 |
66 | //{{AFX_INSERT_LOCATION}}
67 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
68 |
69 | #endif // !defined(AFX_TRAININGSIMDLG_H__CD8860EF_5F04_46CF_8D62_1F6F6DBAD2D8__INCLUDED_)
70 |
--------------------------------------------------------------------------------
/ModRSsim2/HtmlOutput.h:
--------------------------------------------------------------------------------
1 | // HtmlOutput.h
2 |
3 | #if !defined(HTMLOUT__INCLUDED_)
4 | #define HTMLOUT__INCLUDED_
5 |
6 | #if _MSC_VER > 1000
7 | #pragma once
8 | #endif // _MSC_VER > 1000
9 |
10 | #define MAX_ERRMESSAGELEN 180
11 | #define FOREVER (TRUE)
12 |
13 | ///////////////////////////////////////////////////////////////////////////////////////////
14 | // The CHTMLOutput class provides the HTML output feature
15 | //
16 | // Basically we do three things in this class on a thread
17 | // 1. Read an input HTML file
18 | // 2. Replace all occurences of the registertype,registeroffset,formatting tag with it's value
19 | // 3. Write to output HTML file
20 | //
21 |
22 | //
23 | // This is the TAG in the HTML that I use
24 | #define REPLACEMENT_TAGPREFIX ""
25 | #define REPLACEMENT_TAGSUFIX ""
26 | #define REPLACEMENT_TAGPREFIXLC "" // lowercase variants
27 | #define REPLACEMENT_TAGSUFIXLC ""
28 |
29 |
30 | class CHTMLOutput:public CObject
31 | {
32 | public:
33 | CHTMLOutput();
34 |
35 | virtual ~CHTMLOutput();
36 |
37 | void Watch(DWORD dwInterval, LPCTSTR inFile, LPCTSTR outFile); // create thread
38 | void StopWatching(); // kill thread
39 |
40 | protected:
41 | static UINT threadfunc(void* pThis);
42 | UINT NotifierThread();
43 |
44 | void ParseInnards(LPCTSTR formatter, CString &replacement);
45 | void RefreshOutput(bool inputchanged = true);
46 | void FetchRegisterValue(LONG index, LONG subIndex, CString& value, LONG format=-1);
47 | void LogError(LPCTSTR errorString);
48 |
49 | private:
50 | CFile m_inputFile; // used only to read the file when it changes
51 | CFile m_outputFile;
52 | DWORD m_dwMsInterval; // ms before we refresh the output file anyway
53 | HANDLE m_hInputFileEvent; // handle to incomming 'drop' folder change notification event
54 | HANDLE m_hShutDownEvent;
55 | HANDLE m_hThreadDoneEvent;
56 |
57 | CString m_outputFileName;
58 | CString m_inputFileName;
59 |
60 | CString m_inputTextBuffer;
61 | bool m_shut;
62 | CWinThread *m_pwThread;
63 |
64 | DECLARE_DYNAMIC( CHTMLOutput )
65 | };
66 |
67 | #endif // HTMLOUT__INCLUDED_
68 |
--------------------------------------------------------------------------------
/ModRSsim2/AdvEmulationDlg.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_ADVEMULATIONDLG_H__4AC409B4_17EB_4295_84E9_814AF3E31BB4__INCLUDED_)
2 | #define AFX_ADVEMULATIONDLG_H__4AC409B4_17EB_4295_84E9_814AF3E31BB4__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // AdvEmulationDlg.h : header file
8 | //
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // CAdvEmulationDlg dialog
12 | #include "resource.h"
13 |
14 | class CAdvEmulationDlg : public CDialog
15 | {
16 | // Construction
17 | public:
18 | CAdvEmulationDlg(CWnd* pParent = NULL); // standard constructor
19 |
20 | // Dialog Data
21 | //{{AFX_DATA(CAdvEmulationDlg)
22 | enum { IDD = IDD_ADVEMULATION };
23 | CStatic m_staticBmpMode;
24 | DWORD m_numInputs;
25 | DWORD m_numOutputs;
26 | DWORD m_numHolding;
27 | DWORD m_numExtended;
28 | DWORD m_numAnalogs;
29 | BOOL m_MOSCADchecks;
30 | DWORD m_PDUSize;
31 | BOOL m_modifyThenRespond;
32 | BOOL m_disableWrites;
33 | UINT m_numSeperate;
34 | BOOL m_seperateRegisters;
35 | //}}AFX_DATA
36 |
37 | CWnd* SetParentWnd(CWnd*pWndNew) {CWnd *pOld = pWndNew; m_pParentWnd = pWndNew; return(pOld);}
38 |
39 | CBitmap m_bmpModeBitmap;
40 | SetCurrentTopic m_topic; // help topic thingy
41 |
42 | // TOOLTIPS
43 | CToolTipCtrl m_ToolTip;
44 | int m_numDisabledControls;
45 | CWnd *m_pDisabledControls[256]; //only can get 256 controls
46 |
47 |
48 | // Overrides
49 | // ClassWizard generated virtual function overrides
50 | //{{AFX_VIRTUAL(CAdvEmulationDlg)
51 | public:
52 | virtual BOOL PreTranslateMessage(MSG* pMsg);
53 | protected:
54 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
55 | //}}AFX_VIRTUAL
56 |
57 | // Implementation
58 | protected:
59 |
60 | // Generated message map functions
61 | //{{AFX_MSG(CAdvEmulationDlg)
62 | virtual BOOL OnInitDialog();
63 | virtual void OnOK();
64 | afx_msg void OnDefaults();
65 | afx_msg void OnMaximum();
66 | afx_msg void OnSeperatedClicked();
67 | afx_msg void OnBmpmodeClicked();
68 | //}}AFX_MSG
69 | DECLARE_MESSAGE_MAP()
70 | };
71 |
72 | //{{AFX_INSERT_LOCATION}}
73 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
74 |
75 | #endif // !defined(AFX_ADVEMULATIONDLG_H__4AC409B4_17EB_4295_84E9_814AF3E31BB4__INCLUDED_)
76 |
--------------------------------------------------------------------------------
/ModRSsim2/MyHostProxy.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_MYHOSTPROXY_H__476FB980_9F8F_40F5_9D31_FCB4AE615943__INCLUDED_)
2 | #define AFX_MYHOSTPROXY_H__476FB980_9F8F_40F5_9D31_FCB4AE615943__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // MyHostProxy.h : header file
8 | //
9 |
10 |
11 |
12 | /////////////////////////////////////////////////////////////////////////////
13 | // CMyHostProxy command target
14 |
15 | class CMyHostProxy : public CActiveScriptHost
16 | {
17 | DECLARE_DYNCREATE(CMyHostProxy)
18 |
19 | CMyHostProxy(); // protected constructor used by dynamic creation
20 | virtual ~CMyHostProxy();
21 |
22 | virtual BOOL GetDispatchIID(IID* riid);
23 | DECLARE_OLETYPELIB(CMyHostProxy)
24 |
25 | // Attributes
26 | public:
27 |
28 | // Operations
29 | public:
30 |
31 | // Overrides
32 | // ClassWizard generated virtual function overrides
33 | //{{AFX_VIRTUAL(CMyHostProxy)
34 | public:
35 | virtual void OnFinalRelease();
36 | //}}AFX_VIRTUAL
37 |
38 | // Implementation
39 | protected:
40 |
41 | // Generated message map functions
42 | //{{AFX_MSG(CMyHostProxy)
43 | // NOTE - the ClassWizard will add and remove member functions here.
44 | //}}AFX_MSG
45 |
46 | DECLARE_MESSAGE_MAP()
47 | // Generated OLE dispatch map functions
48 | //{{AFX_DISPATCH(CMyHostProxy)
49 | afx_msg short xGetRegisterValue(long registertype, long registernumber);
50 | afx_msg void xEnableStation(short stationid);
51 | afx_msg void xDisableStation(short stationid);
52 | // afx_msg void xDisplayAbout(long delaytime); // Modified 2016-04-15 by DL
53 | afx_msg void xDisplayAbout();
54 | afx_msg long xGetLastRunTime();
55 | afx_msg void xSetRegisterValue(long registertype, long registernumber, long registervalue);
56 | afx_msg long xStationEnabled(short stationid);
57 | afx_msg void xClearRegisters();
58 | afx_msg long xTransmitRegisters(short sourceStation, short destinationStation, long file_areaNumber, long startRegister, long numRegisters);
59 | afx_msg void xAddDebugString(LPCTSTR text);
60 | afx_msg long xMasterBusy();
61 | //}}AFX_DISPATCH
62 | DECLARE_DISPATCH_MAP()
63 | DECLARE_INTERFACE_MAP()
64 | };
65 |
66 | /////////////////////////////////////////////////////////////////////////////
67 |
68 | //{{AFX_INSERT_LOCATION}}
69 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
70 |
71 | #endif // !defined(AFX_MYHOSTPROXY_H__476FB980_9F8F_40F5_9D31_FCB4AE615943__INCLUDED_)
72 |
--------------------------------------------------------------------------------
/ModRSsim2/StdAfx.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // stdafx.h : include file for standard system include files,
4 | // or project specific include files that are used frequently, but
5 | // are changed infrequently
6 | //
7 | // See _README.CPP
8 | //
9 | /////////////////////////////////////////////////////////////////////////////
10 |
11 | #if !defined(AFX_STDAFX_H__99C3C71E_6549_443C_B532_6557AB4C5095__INCLUDED_)
12 | #define AFX_STDAFX_H__99C3C71E_6549_443C_B532_6557AB4C5095__INCLUDED_
13 |
14 | #if _MSC_VER > 1000
15 | #pragma once
16 | #endif // _MSC_VER > 1000
17 |
18 | #ifndef WINVER
19 | #define WINVER 0x0501 //WinXP Changed from 0x0500 on 2016-08-06 by D. Lyons
20 | #endif
21 |
22 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
23 |
24 | #include // MFC core and standard components
25 | #include // MFC extensions
26 | #include // MFC Automation classes
27 | #include // MFC support for Internet Explorer 4 Common Controls
28 | #ifndef _AFX_NO_AFXCMN_SUPPORT
29 | #include // MFC support for Windows Common Controls
30 | #endif // _AFX_NO_AFXCMN_SUPPORT
31 | #include // MFC Multithreading
32 | #include
33 | #include
34 | #include // windows sockets APIs
35 |
36 | #include "..\mylib\mylib.h"
37 |
38 | #include "DDKSocket.h" // Ethernet TCP/IP socket
39 | #include "DDKSrvSocket.h" // Server end of socket
40 | #include "ServerSocketArray.h"
41 | #include "util.h" // globally used application functions & macros
42 |
43 | // Vinay
44 | #include "CsvReader.h"
45 |
46 | #include "MemWriteLock.h"
47 | #include "MemoryEditorList.h"
48 | #include "ServerRS232Array.h"
49 | #include "ServerSocketArray.h"
50 | #include "splash.h"
51 | #include "ActiveScriptHost.h" // Active scripting class by Ernest Laurentin (Code-Project)
52 | #include "MyHostProxy.h"
53 |
54 | #include "mod_RSsim.h"
55 | #include "htmloutput.h"
56 | #include "mod_RSsimdlg.h"
57 |
58 | #include "MemoryEditorList.h"
59 | #include "RS232Port.h"
60 | #include "simport.h"
61 | #include "RS232Noise.h"
62 | #include "MODEthCommsProcessor.h"
63 | #include "MOD232CommsProcessor.h"
64 | #include "AdvEmulationDlg.h"
65 |
66 |
67 |
68 | //{{AFX_INSERT_LOCATION}}
69 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
70 |
71 | #endif // !defined(AFX_STDAFX_H__99C3C71E_6549_443C_B532_6557AB4C5095__INCLUDED_)
72 |
--------------------------------------------------------------------------------
/ModRSsim2/ServerSettings232Dlg.h:
--------------------------------------------------------------------------------
1 |
2 | #if !defined(AFX_SERVERSETTINGSDLG_H__5EE467B0_3A96_41BA_BEC2_27A1C3528C4E__INCLUDED_)
3 | #define AFX_SERVERSETTINGSDLG_H__5EE467B0_3A96_41BA_BEC2_27A1C3528C4E__INCLUDED_
4 |
5 | #if _MSC_VER > 1000
6 | #pragma once
7 | #endif // _MSC_VER > 1000
8 | /////////////////////////////////////////////////////////////////////////////
9 | //
10 | // FILE: ServerSettingsDlg.h : headder file
11 | //
12 | // See _README.CPP
13 | //
14 | //
15 | /////////////////////////////////////////////////////////////////////////////
16 |
17 |
18 |
19 |
20 | /////////////////////////////////////////////////////////////////////////////
21 | // CServerSettings232Dlg dialog
22 |
23 | class CServerSettings232Dlg : public CDialog
24 | {
25 | // Construction
26 | public:
27 | CServerSettings232Dlg(CWnd* pParent = NULL); // standard constructor
28 |
29 | // Dialog Data
30 | //{{AFX_DATA(CServerSettings232Dlg)
31 | enum { IDD = IDD_SERVERSETTINGS_232 };
32 | CComboBox m_checkTypeCombo;
33 | CComboBox m_rtsCombo;
34 | CComboBox m_stopBitCombo;
35 | CComboBox m_portCombo;
36 | CComboBox m_parityCombo;
37 | CComboBox m_dataBitsCombo;
38 | CComboBox m_baudCombo;
39 | UINT m_responseDelay;
40 | BOOL m_MOSCADchecks;
41 | BOOL m_autoLoad;
42 | BOOL m_startAsOff;
43 | BOOL m_ABMastermode;
44 | //}}AFX_DATA
45 | DWORD m_stopBits;
46 | CString m_portName;
47 | DWORD m_parity;
48 | DWORD m_dataBits;
49 | DWORD m_baud;
50 | DWORD m_rts;
51 | BOOL m_useBCC;
52 | DWORD m_protocol; // which 232 protcol to use
53 | BOOL m_longTimeouts;
54 |
55 | SetCurrentTopic m_topic;
56 |
57 | // Overrides
58 | // ClassWizard generated virtual function overrides
59 | //{{AFX_VIRTUAL(CServerSettings232Dlg)
60 | public:
61 | virtual BOOL PreTranslateMessage(MSG* pMsg);
62 | protected:
63 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
64 | //}}AFX_VIRTUAL
65 |
66 | // Implementation
67 | protected:
68 |
69 | // TOOLTIPS
70 | CToolTipCtrl m_ToolTip;
71 | BOOL OnTTN_NeedText( UINT id, NMHDR * pTTTStruct, LRESULT * pResult );
72 |
73 | // Generated message map functions
74 | //{{AFX_MSG(CServerSettings232Dlg)
75 | virtual void OnOK();
76 | virtual BOOL OnInitDialog();
77 | //}}AFX_MSG
78 | DECLARE_MESSAGE_MAP()
79 | };
80 |
81 | //{{AFX_INSERT_LOCATION}}
82 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
83 |
84 | #endif // !defined(AFX_SERVERSETTINGSDLG_H__5EE467B0_3A96_41BA_BEC2_27A1C3528C4E__INCLUDED_)
85 |
--------------------------------------------------------------------------------
/mylib/ColorStatic.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_COLORSTATIC_H__38E16084_70AB_45D2_9CE9_D09537E6F278__INCLUDED_)
2 | #define AFX_COLORSTATIC_H__38E16084_70AB_45D2_9CE9_D09537E6F278__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | // ColorStatic.h : header file
8 | //
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // CColorStatic window
12 |
13 | class CColorStatic : public CStatic
14 | {
15 | // Construction
16 | public:
17 | CColorStatic();
18 |
19 | // Attributes
20 | public:
21 |
22 | // Operations
23 | public:
24 |
25 | void SetColor(COLORREF color) {m_color = color;};
26 | COLORREF GetColor() {return(m_color);};
27 | // Overrides
28 | // ClassWizard generated virtual function overrides
29 | //{{AFX_VIRTUAL(CColorStatic)
30 | //}}AFX_VIRTUAL
31 |
32 | // Implementation
33 | public:
34 | virtual ~CColorStatic();
35 |
36 | protected:
37 | CFont m_font; // underline font for text control
38 | COLORREF m_color; // color
39 |
40 | // Generated message map functions
41 | protected:
42 | //{{AFX_MSG(CColorStatic)
43 | // NOTE - the ClassWizard will add and remove member functions here.
44 | //}}AFX_MSG
45 |
46 | afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
47 | DECLARE_MESSAGE_MAP()
48 | };
49 |
50 |
51 | /////////////////////////////////////////////////////////////////////////////
52 | // CSampler window
53 |
54 | class CSampler : public CEdit
55 | {
56 | // Construction
57 | public:
58 | CSampler();
59 |
60 | void SetNewColor(COLORREF color); // only call after window is created
61 | COLORREF CSampler::BrowseColor(); // open the colour browser dialog
62 |
63 | // Attributes
64 | COLORREF GetColor() {return(m_color);}
65 | private:
66 |
67 |
68 | COLORREF m_color;
69 | // Operations
70 | public:
71 |
72 | // Overrides
73 | // ClassWizard generated virtual function overrides
74 | //{{AFX_VIRTUAL(CSampler)
75 | //}}AFX_VIRTUAL
76 |
77 | // Implementation
78 | public:
79 | virtual ~CSampler();
80 |
81 | // Generated message map functions
82 | protected:
83 | //{{AFX_MSG(CSampler)
84 | afx_msg void OnPaint();
85 | //}}AFX_MSG
86 |
87 | DECLARE_MESSAGE_MAP()
88 | }; // class CSampler
89 |
90 |
91 | /////////////////////////////////////////////////////////////////////////////
92 |
93 | //{{AFX_INSERT_LOCATION}}
94 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
95 |
96 | #endif // !defined(AFX_COLORSTATIC_H__38E16084_70AB_45D2_9CE9_D09537E6F278__INCLUDED_)
97 |
--------------------------------------------------------------------------------
/ModRSsim2/SimCmdLine.h:
--------------------------------------------------------------------------------
1 | // SimCmdLine.h: interface for the CSimCmdLine class.
2 | //
3 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
4 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU Affero General Public License as
8 | // published by the Free Software Foundation, either version 3 of the
9 | // License, or (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Affero General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Affero General Public License
17 | // along with this program. If not, see .
18 | //
19 | //////////////////////////////////////////////////////////////////////
20 |
21 | #if !defined(AFX_SIMCMDLINE_H__4A30F9B7_455E_41F3_810A_6072FF55AD2D__INCLUDED_)
22 | #define AFX_SIMCMDLINE_H__4A30F9B7_455E_41F3_810A_6072FF55AD2D__INCLUDED_
23 |
24 | #if _MSC_VER > 1000
25 | #pragma once
26 | #endif // _MSC_VER > 1000
27 |
28 | class CSimCmdLine : public CCommandLineInfo
29 | {
30 | public:
31 | CSimCmdLine();
32 | virtual ~CSimCmdLine();
33 |
34 | /*virtual */ void ParseParam( LPCTSTR lpszParam, BOOL bFlag, BOOL bLast );
35 |
36 | void SetPortParams ( const DWORD &aBaudRate,
37 | const DWORD &aByteSize,
38 | const DWORD &aParity,
39 | const DWORD & aStop,
40 | const DWORD &aRTS);
41 |
42 | bool GetPortSettings(char aPortName[MAX_COMPORT_NAME] ,
43 | DWORD &aBaudRate,
44 | DWORD &aByteSize,
45 | DWORD &aParity,
46 | DWORD & aStop,
47 | DWORD &aRTS);
48 | bool GetProtocol(DWORD &aProtocol);
49 | bool GetIPSettings(DWORD &aPort);
50 |
51 | bool ParamsValid() { return( m_SerialControls || m_protocol!= -1);};
52 | // data
53 | private:
54 | CString m_portName;
55 | DWORD m_baud ;
56 | DWORD m_byte;
57 | DWORD m_parity ;
58 | DWORD m_stop ;
59 | DWORD m_rts ;
60 | DWORD m_protocol ;
61 | DWORD m_ipPort ;
62 |
63 | DCB m_dcbBlock;
64 | bool m_SerialControls;
65 | CString m_DCBParams;
66 | };
67 |
68 | #endif // !defined(AFX_SIMCMDLINE_H__4A30F9B7_455E_41F3_810A_6072FF55AD2D__INCLUDED_)
69 |
--------------------------------------------------------------------------------
/ModRSsim2/CSVFileImportDlg.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_CSVFILEIMPORTDLG_H__3890B814_575B_4FE5_85E8_11105A59A384__INCLUDED_)
2 | #define AFX_CSVFILEIMPORTDLG_H__3890B814_575B_4FE5_85E8_11105A59A384__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 |
8 | #include "resource.h"
9 |
10 | // CSVFileImportDlg.h : header file
11 | //
12 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
13 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
14 | //
15 | // This program is free software: you can redistribute it and/or modify
16 | // it under the terms of the GNU Affero General Public License as
17 | // published by the Free Software Foundation, either version 3 of the
18 | // License, or (at your option) any later version.
19 | //
20 | // This program is distributed in the hope that it will be useful,
21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 | // GNU Affero General Public License for more details.
24 | //
25 | // You should have received a copy of the GNU Affero General Public License
26 | // along with this program. If not, see .
27 | //
28 | // CREDIT: uses a edit control by JP Arendse
29 | // http://www.codeproject.com/KB/edit/fileeditctrl.aspx
30 |
31 | /////////////////////////////////////////////////////////////////////////////
32 | // CCSVFileImportDlg dialog
33 |
34 | class CCSVFileImportDlg : public CDialog
35 | {
36 | // Construction
37 | public:
38 | CCSVFileImportDlg(CWnd* pParent = NULL); // standard constructor
39 |
40 | // Dialog Data
41 | //{{AFX_DATA(CCSVFileImportDlg)
42 | enum { IDD = IDD_CSV_IMPORTDLG };
43 | BOOL m_csvImportEnable;
44 | CString m_importFolder;
45 | CString m_logFileName;
46 | CString m_importStatus;
47 | //}}AFX_DATA
48 | CFileEditCtrl m_FileEditCtrl;
49 | CFileEditCtrl m_FolderEditCtrl;
50 | //CFileEditCtrl m_ImportStatusCtrl;
51 |
52 |
53 | // Overrides
54 | // ClassWizard generated virtual function overrides
55 | //{{AFX_VIRTUAL(CCSVFileImportDlg)
56 | protected:
57 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
58 | //}}AFX_VIRTUAL
59 |
60 | // Implementation
61 | protected:
62 |
63 | // Generated message map functions
64 | //{{AFX_MSG(CCSVFileImportDlg)
65 | virtual void OnOK();
66 | virtual void OnCancel();
67 | virtual BOOL OnInitDialog();
68 | afx_msg void OnQuickImport();
69 | //}}AFX_MSG
70 | DECLARE_MESSAGE_MAP()
71 | };
72 |
73 | //{{AFX_INSERT_LOCATION}}
74 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
75 |
76 | #endif // !defined(AFX_CSVFILEIMPORTDLG_H__3890B814_575B_4FE5_85E8_11105A59A384__INCLUDED_)
77 |
--------------------------------------------------------------------------------
/ModRSsim2/Splash.h:
--------------------------------------------------------------------------------
1 | // Splash.h : header file
2 | //
3 | // CG: This file was added by the Splash Screen component.
4 | //
5 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
6 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
7 | // email: zaphodikus@hotmail.com
8 | //
9 | // This program is free software: you can redistribute it and/or modify
10 | // it under the terms of the GNU Affero General Public License as
11 | // published by the Free Software Foundation, either version 3 of the
12 | // License, or (at your option) any later version.
13 | //
14 | // This program is distributed in the hope that it will be useful,
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | // GNU Affero General Public License for more details.
18 | //
19 | // You should have received a copy of the GNU Affero General Public License
20 | // along with this program. If not, see .
21 | //
22 |
23 | #ifndef _SPLASH_SCRN_
24 | #define _SPLASH_SCRN_
25 |
26 | #define INVALID_SPLASH_TXT_COLOR (0xFF000000)
27 |
28 | /////////////////////////////////////////////////////////////////////////////
29 | // Splash Screen class
30 |
31 | class CSplashWnd : public CWnd
32 | {
33 | // Construction
34 | protected:
35 | CSplashWnd();
36 |
37 | // Attributes:
38 | public:
39 | CBitmap m_bitmap;
40 |
41 | static void SetWaitCount(int w) {m_splashShowCount = w;}
42 | static CSplashWnd* GetSWnd() {return(c_pSplashWnd);}
43 | // Operations
44 | public:
45 | static void EnableSplashScreen(BOOL bEnable = TRUE);
46 | static void ShowSplashScreen(CWnd* pParentWnd = NULL);
47 | static BOOL PreTranslateAppMessage(MSG* pMsg);
48 |
49 | // Overrides
50 | // ClassWizard generated virtual function overrides
51 | //{{AFX_VIRTUAL(CSplashWnd)
52 | //}}AFX_VIRTUAL
53 |
54 | // Implementation
55 | public:
56 | ~CSplashWnd();
57 | virtual void PostNcDestroy();
58 |
59 | static int m_splashShowDelay;
60 | protected:
61 | BOOL Create(CWnd* pParentWnd = NULL);
62 | void HideSplashScreen();
63 | static BOOL c_bShowSplashWnd;
64 | static CSplashWnd* c_pSplashWnd;
65 | void AddDrawText(CPaintDC& dc, const char *text, COLORREF color= INVALID_SPLASH_TXT_COLOR);
66 |
67 | static int m_splashShowCount;
68 | CFont * m_pFont;
69 | CFont * m_pLargeFont;
70 |
71 | int m_textDrawPosY; // used by AddDrawText()
72 |
73 | // Generated message map functions
74 | protected:
75 | //{{AFX_MSG(CSplashWnd)
76 | afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
77 | afx_msg void OnPaint();
78 | afx_msg void OnTimer(UINT nIDEvent);
79 | //}}AFX_MSG
80 | DECLARE_MESSAGE_MAP()
81 | };
82 |
83 |
84 | #endif
85 |
--------------------------------------------------------------------------------
/mylib/MYLIB.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {a1857cd7-8ffa-4c7d-8933-57062fb41bd8}
6 | cpp;c;cxx;rc;def;r;odl;idl;hpj;bat
7 |
8 |
9 | {f139bcc4-d76a-45c6-a629-912519ef4ab7}
10 | h;hpp;hxx;hm;inl
11 |
12 |
13 |
14 |
15 | Source Files
16 |
17 |
18 | Source Files
19 |
20 |
21 | Source Files
22 |
23 |
24 | Source Files
25 |
26 |
27 | Source Files
28 |
29 |
30 | Source Files
31 |
32 |
33 | Source Files
34 |
35 |
36 | Source Files
37 |
38 |
39 | Source Files
40 |
41 |
42 | Source Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
51 |
52 | Header Files
53 |
54 |
55 | Header Files
56 |
57 |
58 | Header Files
59 |
60 |
61 | Header Files
62 |
63 |
64 | Header Files
65 |
66 |
67 | Header Files
68 |
69 |
70 | Header Files
71 |
72 |
73 | Header Files
74 |
75 |
76 |
--------------------------------------------------------------------------------
/ModRSsim2/SelfRegistrationDlg.cpp:
--------------------------------------------------------------------------------
1 | // SelfRegistrationDlg.cpp : implementation file
2 | //
3 |
4 | #include "stdafx.h"
5 | #include "mod_RSsim.h"
6 | #include "SelfRegistrationDlg.h"
7 |
8 |
9 | // CSelfRegistrationDlg dialog
10 |
11 | IMPLEMENT_DYNAMIC(CSelfRegistrationDlg, CDialog)
12 |
13 | CSelfRegistrationDlg::CSelfRegistrationDlg(CWnd* pParent /*=NULL*/)
14 | : CDialog(CSelfRegistrationDlg::IDD, pParent)
15 | , m_username(_T(""))
16 | , m_registrationkey(_T(""))
17 | {
18 |
19 | }
20 |
21 | CSelfRegistrationDlg::~CSelfRegistrationDlg()
22 | {
23 | }
24 |
25 | void CSelfRegistrationDlg::DoDataExchange(CDataExchange* pDX)
26 | {
27 | CDialog::DoDataExchange(pDX);
28 | DDX_Text(pDX, IDC_USERNAME, m_username);
29 | DDV_MaxChars(pDX, m_username, 60);
30 | DDX_Text(pDX, IDC_REGISTRATION_KEY, m_registrationkey);
31 | DDV_MaxChars(pDX, m_registrationkey, 8);
32 | }
33 |
34 |
35 | BEGIN_MESSAGE_MAP(CSelfRegistrationDlg, CDialog)
36 | ON_EN_CHANGE(IDC_REGISTRATION_KEY, &CSelfRegistrationDlg::OnEnChangeRegistrationKey)
37 | ON_EN_CHANGE(IDC_USERNAME, &CSelfRegistrationDlg::OnEnChangeUsername)
38 | ON_BN_CLICKED(IDOK, &CSelfRegistrationDlg::OnBnClickedOk)
39 | END_MESSAGE_MAP()
40 |
41 |
42 | // CSelfRegistrationDlg message handlers
43 |
44 | void CSelfRegistrationDlg::OnEnChangeRegistrationKey()
45 | {
46 | OnDetailsChanged();
47 | }
48 |
49 | void CSelfRegistrationDlg::OnEnChangeUsername()
50 | {
51 | OnDetailsChanged();
52 | }
53 |
54 | void CSelfRegistrationDlg::OnDetailsChanged()
55 | {
56 | UpdateData(1);
57 | CWnd *okButton = GetDlgItem(IDOK);
58 |
59 | if (okButton)
60 | {
61 | // Removed 2016-10-22 by DL
62 | //okButton->EnableWindow(CRegistrationTest::CheckRegistrationKey(m_username, m_registrationkey, TRUE));
63 | }
64 | }
65 |
66 | BOOL CSelfRegistrationDlg::OnInitDialog()
67 | {
68 | CString registryPath;
69 | DRegKey key;
70 |
71 | CDialog::OnInitDialog();
72 |
73 | // TODO: Add extra initialization here
74 | registryPath = APPREGISTRY_SETTINGSKEY;
75 |
76 | key.Open(DRegKey::current_user, registryPath);
77 | key.QueryValue("RegistrationUserName", m_username);
78 | key.QueryValue("RegistrationKey", m_registrationkey);
79 |
80 | UpdateData(FALSE);
81 | OnDetailsChanged();
82 | return TRUE; // return TRUE unless you set the focus to a control
83 | // EXCEPTION: OCX Property Pages should return FALSE
84 | }
85 |
86 | void CSelfRegistrationDlg::OnBnClickedOk()
87 | {
88 | CString registryPath;
89 | DRegKey key;
90 | // TODO: Add your control notification handler code here
91 | UpdateData(1);
92 | registryPath = APPREGISTRY_SETTINGSKEY;
93 |
94 | key.Open(DRegKey::current_user, registryPath);
95 | key.SetValue("RegistrationUserName", m_username);
96 | key.SetValue("RegistrationKey", m_registrationkey);
97 |
98 | OnOK();
99 | }
100 |
--------------------------------------------------------------------------------
/ModRSsim2/ActiveScriptHost.h:
--------------------------------------------------------------------------------
1 | /************************************************************
2 | * FILENAME : ActiveScriptHost.h
3 | * INITIAL CODING : Ernest Laurentin (EL)
4 | *************************************************************/
5 |
6 | #ifndef ACTIVESCRIPT_HOST
7 | #define ACTIVESCRIPT_HOST
8 | #include
9 |
10 | #define LANG_ENGLISH_NEUTRAL (MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL))
11 | #define LOCALE_SCRIPT_DEFAULT (MAKELCID(LANG_ENGLISH_NEUTRAL, SORT_DEFAULT))
12 |
13 | #define ACTIVS_HOST L"ScriptHost"
14 | #define SCRIPTITEM_NAMEDITEM (SCRIPTITEM_ISSOURCE | \
15 | SCRIPTITEM_ISVISIBLE | \
16 | SCRIPTITEM_GLOBALMEMBERS)
17 |
18 | #ifdef _AFXDLL
19 | class CActiveScriptHost : public CCmdTarget
20 | #else
21 | class AFX_NOVTABLE CActiveScriptHost : public CCmdTarget
22 | #endif
23 | {
24 | DECLARE_DYNAMIC(CActiveScriptHost)
25 |
26 | public:
27 | // Constructors
28 | CActiveScriptHost();
29 | virtual ~CActiveScriptHost();
30 |
31 | // Operations
32 | BOOL SetHostWindow(HWND hWnd);
33 | BOOL CreateEngine(LPCOLESTR pstrProgID);
34 | BOOL AddScriptItem(LPCOLESTR pstrNamedItem, LPUNKNOWN lpUnknown, DWORD dwFlags = SCRIPTITEM_NAMEDITEM);
35 | BOOL AddScriptCode(LPCOLESTR pstrScriptCode);
36 | BOOL AddScriptlet(LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode,
37 | LPCOLESTR pstrItemName, LPCOLESTR pstrEventName);
38 | // Helper functions
39 | LPDISPATCH CreateObjectHelper(LPCOLESTR bstrProgID);
40 | WCHAR* ReadTextFileHelper(LPCOLESTR strFileName);
41 | void DestroyDataHelper(LPVOID lpvData);
42 | HRESULT InvokeFuncHelper(LPCOLESTR lpszName, VARIANT* pvarParams, int nParams, VARIANT* pvarRet = NULL);
43 |
44 | BOOL IsRunning() { return(m_xActiveScriptSite.m_running);};
45 |
46 | protected:
47 | void CommonConstruct();
48 | void ReleaseObjects();
49 | CMapStringToPtr mapNamedItems; // Named items
50 | IActiveScriptParse* m_pAxsParse; // Active Script parse object
51 | IActiveScript* m_pAxsScript; // Active Script
52 | HWND m_hHostWnd; // Host Window
53 |
54 | // Interface Maps
55 | public:
56 | DECLARE_INTERFACE_MAP()
57 |
58 | BEGIN_INTERFACE_PART(ActiveScriptSite, IActiveScriptSite)
59 | STDMETHOD(GetLCID)(LCID*);
60 | STDMETHOD(GetItemInfo)(LPCOLESTR, DWORD, LPUNKNOWN*, LPTYPEINFO*);
61 | STDMETHOD(GetDocVersionString)(BSTR*);
62 | STDMETHOD(OnScriptTerminate)(const VARIANT*, const EXCEPINFO*);
63 | STDMETHOD(OnStateChange)(SCRIPTSTATE);
64 | STDMETHOD(OnScriptError)(IActiveScriptError*);
65 | STDMETHOD(OnEnterScript)();
66 | STDMETHOD(OnLeaveScript)();
67 |
68 | BOOL m_running;
69 | END_INTERFACE_PART(ActiveScriptSite)
70 |
71 | BEGIN_INTERFACE_PART(ActiveScriptSiteWindow, IActiveScriptSiteWindow)
72 | STDMETHOD(EnableModeless)(BOOL);
73 | STDMETHOD(GetWindow)(HWND*);
74 | END_INTERFACE_PART(ActiveScriptSiteWindow)
75 |
76 | //DECLARE_DISPATCH_MAP()
77 | };
78 |
79 | #endif // ACTIVESCRIPT_HOST
80 |
--------------------------------------------------------------------------------
/ModRSsim2/MODEthCommsProcessor.h:
--------------------------------------------------------------------------------
1 | // MODCommsProcessor.h: interface for the CMODEthCommsProcessor class.
2 | //
3 | // Ethernet :
4 | //
5 | //////////////////////////////////////////////////////////////////////
6 |
7 | #if !defined(AFX_TICOMMSPROCESSOR_H__FDE99A84_435C_4094_826C_175DBDB6E61F__INCLUDED_)
8 | #define AFX_TICOMMSPROCESSOR_H__FDE99A84_435C_4094_826C_175DBDB6E61F__INCLUDED_
9 |
10 | #if _MSC_VER > 1000
11 | #pragma once
12 | #endif // _MSC_VER > 1000
13 |
14 | #include "DDKSrvSocket.h"
15 |
16 | #define MAX_RX_MESSAGELENGTH 4096 // a big buffer
17 |
18 | extern BOOL m_CommsDecodeShow; // Added 2016-12-28 by DL to allow use outside mod_RSsimDLG
19 |
20 | class CMODEthCommsProcessor : public CDDKSrvSocket
21 | {
22 | public:
23 | CMODEthCommsProcessor(int responseDelay,
24 | BOOL MOSCADchecks,
25 | BOOL modifyThenRespond,
26 | BOOL disableWrites,
27 | BOOL rtuFrame,
28 | LONG PDUSize,
29 | WORD portNum);
30 | CMODEthCommsProcessor(int responseDelay,
31 | BOOL MOSCADchecks,
32 | BOOL modifyThenRespond,
33 | BOOL disableWrites,
34 | BOOL rtuFrame,
35 | LONG PDUSize,
36 | SOCKET * pServerSocket);
37 | virtual ~CMODEthCommsProcessor();
38 |
39 | BOOL ProcessData(SOCKET openSocket,
40 | const CHAR *pBuffer,
41 | const DWORD numBytes);
42 |
43 | // overrridden functions
44 | void SockDataDebugger(const CHAR * buffer, LONG length, dataDebugAttrib att);
45 | void SockStateChanged(DWORD state);
46 |
47 | virtual void SockDataMessage(LPCTSTR msg);
48 | void ActivateStationLED(LONG stationID);
49 | BOOL StationIsEnabled(LONG stationID);
50 |
51 |
52 | void SetEmulationParameters(BOOL moscadChecks,
53 | BOOL modifyThenRespond,
54 | BOOL disableWrites);
55 | void SetPDUSize(DWORD size) {m_PDUSize = size;};
56 | BOOL LoadRegisters();
57 | BOOL SaveRegisters();
58 |
59 |
60 | // data members
61 | UINT m_responseDelay;
62 | BOOL m_linger;
63 | BOOL m_rtuFrame;
64 | //BOOL m_useEthernetStationID;
65 | //DWORD m_stationID;
66 | // noise/error sim
67 | BOOL m_modifyThenRespond;
68 | BOOL m_MOSCADchecks; // MOSCAD
69 | BOOL m_disableWrites; // simple test
70 |
71 | LONG m_noiseIndexValue;
72 | CEthernetNoise m_NoiseSimulator;
73 | //CRS232Noise m_NoiseSimulator;
74 |
75 | LPCTSTR ProtocolName() { return(m_protocolName);};
76 |
77 | private:
78 | CString m_protocolName;
79 | DWORD m_PDUSize;
80 | CRITICAL_SECTION stateCS;
81 |
82 | };
83 |
84 | #endif // !defined(AFX_TICOMMSPROCESSOR_H__FDE99A84_435C_4094_826C_175DBDB6E61F__INCLUDED_)
85 |
--------------------------------------------------------------------------------
/ModRSsim2/MemWriteLock.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: MemWriteLock.h : headder file
4 | //
5 | // See _README.CPP
6 | //
7 | // interface for the CMemWriteLock class.
8 | //
9 | /////////////////////////////////////////////////////////////////////////////
10 |
11 | #if !defined(AFX_MEMWRITELOCK_H__FBDCD1E8_1DF6_47DA_BEB7_3890FF55A74B__INCLUDED_)
12 | #define AFX_MEMWRITELOCK_H__FBDCD1E8_1DF6_47DA_BEB7_3890FF55A74B__INCLUDED_
13 |
14 | #if _MSC_VER > 1000
15 | #pragma once
16 | #endif // _MSC_VER > 1000
17 |
18 | // -------------------------------- CMemWriteLock ----------------------------
19 | // Mutex object to lock multi-thread access to the PLC memory.
20 | class CMemWriteLock : public CSingleLock
21 | {
22 | public:
23 | CMemWriteLock(CMutex *pMutex);
24 | virtual ~CMemWriteLock();
25 |
26 | protected:
27 | CMutex * m_pMutex;
28 |
29 | };
30 |
31 | // ----------------------- class CControllerMemoryArea -------------------
32 | // This class emulates an array of 16-bit registers, if the register is actually only
33 | // 1 bit (I/O), then values of 0=off and 1=on.
34 | // The array can be any size, tested up to 100 000.
35 | //
36 | class CControllerMemoryArea : private CWordArray
37 | {
38 | friend class CControllerMemory;
39 |
40 | public:
41 | CControllerMemoryArea();
42 |
43 | void SetSize(const DWORD numWords); // set array depth
44 | int GetSize() {return(CWordArray::GetSize());}
45 |
46 | WORD GetAt(const DWORD index); // read the array
47 | WORD operator [](const DWORD index); // read the array
48 |
49 | void SetAt(const DWORD index, WORD data, CMutex *pMutex); // Write to array,
50 | // requires the write interlock object
51 | void IncrementAt(const DWORD index, WORD incValue, CMutex *pMutex); // increment by
52 |
53 | private:
54 | DWORD m_size;
55 |
56 | DWORD m_numberRegistersLimit;
57 | }; // class CControllerMemoryArea
58 |
59 |
60 | // ----------------------------- class CControllerMemory --------------------------
61 | // This class emulates all of the variables/memory in the PLC. Because memory/variables
62 | // are not arranged contigously in a Programmable-Controller, this class has an array of
63 | // these "blocks" normally identified as register or data types.
64 | //
65 | // Each block is called an area, and represented in a CControllerMemoryArea object.
66 | //
67 | class CControllerMemory : public CObArray
68 | {
69 | public:
70 | CControllerMemory();
71 | ~CControllerMemory();
72 |
73 | void SetSize(const DWORD numAreas); // set array depth
74 |
75 | CControllerMemoryArea& GetAt(const DWORD index);
76 | CControllerMemoryArea& operator [](const DWORD index);
77 |
78 | void SetAt(const DWORD index, const DWORD subIndex, WORD data);
79 | void IncrementAt(const DWORD index, const DWORD subIndex, WORD incValue); // increment by
80 |
81 | CMutex *GetMutex() {return(&m_Mutex);};
82 | private:
83 | //methods
84 | void FreeOldMemory();
85 | void AllocateNewMemory(const DWORD areas);
86 |
87 | //data
88 | CMutex m_Mutex;
89 | DWORD m_size;
90 |
91 | };
92 |
93 |
94 | #endif // !defined(AFX_MEMWRITELOCK_H__FBDCD1E8_1DF6_47DA_BEB7_3890FF55A74B__INCLUDED_)
95 |
--------------------------------------------------------------------------------
/ModRSsim2/Scripts/plcsim.vbs:
--------------------------------------------------------------------------------
1 | '---------------------------------------------------------------
2 | ' Data simulation using modRSim
3 | '
4 | ' Note that all subroutines / functions must appear before the
5 | ' subroutine is called.
6 | '
7 | ' Note: Addressing in the automtion calls is Off by one. So,
8 | ' when you want to read/modify value of holding register 305,
9 | ' you will need to pass 304 as the register address.
10 | '---------------------------------------------------------------
11 |
12 | '---------------------------------------------------------------
13 | ' Routine to simulate saw tooth data pattern. The value of specified
14 | ' holding register will increase from minValue to maxValue, and
15 | ' upon reaching maxValue it will drop to minValue
16 | '---------------------------------------------------------------
17 | Sub SimulateSawTooth(reg, minValue, maxValue)
18 | Dim hrValue
19 |
20 | hrValue = GetRegisterValue(3, reg)
21 | if (hrValue > maxValue) then
22 | hrValue = minValue
23 | else
24 | hrValue = hrValue + 1
25 | end if
26 | SetRegisterValue 3, reg, hrValue
27 | End Sub
28 |
29 | '---------------------------------------------------------------
30 | ' Routine to simulate correlated random variations in specified
31 | ' holding register value.
32 | '---------------------------------------------------------------
33 | Sub RandomVariation(reg, minVal, maxVal, noiseLevel)
34 | Dim hrValue
35 | Dim minChg
36 | Dim maxChg
37 | Dim chg
38 |
39 | minChg = -noiseLevel
40 | maxChg = noiseLevel
41 |
42 | hrValue = GetRegisterValue(3, reg)
43 |
44 | chg = Int((maxChg-minChg+1)*Rnd+minChg)
45 | hrValue = hrValue + chg
46 |
47 | if (hrValue < minVal) then
48 | hrValue = minVal
49 | end if
50 |
51 | if (hrValue > maxVal) then
52 | hrValue = maxVal
53 | end if
54 |
55 | SetRegisterValue 3, reg, hrValue
56 | End Sub
57 |
58 | '--------------------- Execution portion -----------------------
59 | Dim reg
60 |
61 | dim hrStart
62 | dim hrEnd
63 |
64 | dim coilStart
65 | dim coilEnd
66 | Dim coilValue
67 |
68 | ' Holding registers - Randomly modified the holding register values in
69 | ' the specified register range
70 | '
71 | ' Note: using too large a range can cause disconnection
72 | '
73 | 'hrStart = 302 ' 40002
74 | 'hrEnd = 360 ' 40100
75 |
76 | 'for reg = hrStart to hrEnd
77 | ' call RandomVariation(reg, 100, 150)
78 | 'next
79 |
80 | ' Simulate saw tooth input on 40302
81 | Call SimulateSawTooth(301, 15, 50)
82 | Call SimulateSawTooth(316, 10, 40)
83 | 'Call SimulateTriangular(331, 20, 60)
84 | 'Call SimulateTriangular(346, 30, 70)
85 |
86 | 'call RandomVariation(301, 10, 50)
87 | 'call RandomVariation(316, 10, 50)
88 | call RandomVariation(331, 10, 50, 3)
89 | call RandomVariation(346, 10, 50, 2)
90 |
91 | 'Coils - Randomly toggles coil values in the specified register range
92 | 'coilStart = 0 ' 001
93 | 'coilEnd = 100 ' 100
94 |
95 | ' reg = Int((coilEnd - coilStart) * Rnd+coilStart)
96 |
97 | '0 indicates holding registers
98 | ' coilValue = GetRegisterValue(0, reg)
99 | ' if (coilValue = 1) then
100 | ' coilValue = 0
101 | ' else
102 | ' coilValue = 1
103 | ' end if
104 | ' SetRegisterValue 0, reg, coilValue
105 |
106 |
--------------------------------------------------------------------------------
/ModRSsim2/stringcvt.cpp:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: stringcvt.cpp
4 | //
5 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
6 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
7 | //
8 | // This program is free software: you can redistribute it and/or modify
9 | // it under the terms of the GNU Affero General Public License as
10 | // published by the Free Software Foundation, either version 3 of the
11 | // License, or (at your option) any later version.
12 | //
13 | // This program is distributed in the hope that it will be useful,
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | // GNU Affero General Public License for more details.
17 | //
18 | // You should have received a copy of the GNU Affero General Public License
19 | // along with this program. If not, see .
20 | //
21 | // string conversion functions
22 | //
23 | /////////////////////////////////////////////////////////////////////////////
24 |
25 | #include "stdafx.h"
26 | #include "MemoryEditorList.h"
27 | #include "EditMemoryDlg.h"
28 | #include "stringcvt.h"
29 |
30 | #ifdef _DEBUG
31 | #define new DEBUG_NEW
32 | #undef THIS_FILE
33 | static char THIS_FILE[] = __FILE__;
34 | #endif
35 |
36 |
37 |
38 | // ----------------------------- ConvertByteToASCII --------------------------
39 | void ConvertByteToASCII(CHAR * szString, const BYTE bValue)
40 | {
41 | if (isgraph(bValue))
42 | sprintf(szString, "%c", bValue);
43 | else
44 | sprintf(szString, "x%02X", bValue);
45 | }
46 |
47 | // ----------------------------- ConvertWordToASCII --------------------------
48 | // return ASCII text for a 16-bit register's contents.
49 | // This function maps non-printable chars into mnemonics
50 | void ConvertWordToASCII(CHAR * szString, const WORD wValue)
51 | {
52 | ConvertByteToASCII(szString, HIBYTE(wValue));
53 | strcat(szString," ");
54 | ConvertByteToASCII(&szString[strlen(szString)], LOBYTE(wValue));
55 | }
56 |
57 | // CString overload of above function
58 | void ConvertWordToASCIICS(CString& csString, const WORD wValue)
59 | {
60 | char*p = csString.GetBufferSetLength(MAX_WORDHEXSTRINGLENGTH);
61 |
62 | ConvertWordToASCII(p, wValue);
63 | csString.ReleaseBuffer();
64 | }
65 |
66 |
67 | // -------------------------- ConvertASCIIToWord ---------------------
68 | // reverse of ConvertWordToASCII
69 | void ConvertASCIIToWord(const char*String, WORD &wValue)
70 | {
71 | CString hiByteCS, loByteCS, inputString(String);
72 | int pos;
73 | BYTE hiByte, loByte;
74 | // search for a space, split into 2 there
75 | // check for x and interpret as hex
76 | // else just convert it
77 |
78 | pos = inputString.Find(' ');
79 | if (pos >=1)
80 | {
81 | hiByteCS = inputString.Left(pos);
82 | loByteCS = inputString.Mid(pos+1);
83 | ConvertASCIIToByte(hiByteCS, hiByte);
84 | ConvertASCIIToByte(loByteCS, loByte);
85 | wValue = loByte + (hiByte<<8);
86 | }
87 | else
88 | {
89 | if (inputString.GetLength() == 2)
90 | {
91 | inputString.Insert(1, ' ');
92 | ConvertASCIIToWord(inputString, wValue);
93 | }
94 | else
95 | {
96 | ConvertASCIIToByte(inputString, hiByte);
97 | wValue = hiByte;
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/ModRSsim2/AnimationSettings.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_ANIMATIONSETTINGS_H__788EF6C0_384E_4725_A2D6_A20B436C0981__INCLUDED_)
2 | #define AFX_ANIMATIONSETTINGS_H__788EF6C0_384E_4725_A2D6_A20B436C0981__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // FILE: AnimationSettings.h : headder file
10 | //
11 | // See _README.CPP
12 | //
13 | /////////////////////////////////////////////////////////////////////////////
14 |
15 | /////////////////////////////////////////////////////////////////////////////
16 | // CAnimationSettingsDlg dialog
17 |
18 | class CAnimationSettingsDlg : public CDialog
19 | {
20 | // Construction
21 | public:
22 | CAnimationSettingsDlg(CWnd* pParent = NULL); // standard constructor
23 |
24 | // Dialog Data
25 | //{{AFX_DATA(CAnimationSettingsDlg)
26 | enum { IDD = IDD_ANIMATE };
27 | long m_value;
28 | long m_refreshes;
29 | DWORD m_animationPeriod;
30 | CString m_inputHtmlFilename;
31 | CString m_outputHtmlFilename;
32 | BOOL m_enableHTMLGUI;
33 | DWORD m_HtmlUpdateRate;
34 | //}}AFX_DATA
35 | BOOL m_animationON;
36 | BOOL m_plantAnimation;
37 | BOOL m_animationBYTE;
38 | BOOL m_animationWORD;
39 | CString m_scriptFile;
40 | CString m_scriptEngine;
41 |
42 | BOOL m_firstPaint;
43 |
44 | CColorPickerCB m_ctlEnabledColor;
45 | CColorPickerCB m_ctlDisabledColor;
46 | CColorPickerCB m_ctlActiveColor;
47 | CColorPickerCB m_ctlInactiveColor;
48 | CColorPickerCB m_ctlTextColor;
49 | CColorPickerCB m_ctlDisabledTextColor;
50 |
51 | CMicroTick m_demoTick;
52 | // the colors
53 | COLORREF m_mTickColorEnabled;
54 | COLORREF m_mTickColorDisabled;
55 | COLORREF m_mTickColorActive;
56 | COLORREF m_mTickColorInactive;
57 | COLORREF m_mTickColorText;
58 | COLORREF m_mTickDisColorText;
59 |
60 | // file browse boxes
61 | CFileEditCtrl m_ScriptNameEditCtrl;
62 | CFileEditCtrl m_HtmlInEditCtrl;
63 | CFileEditCtrl m_HtmlOutEditCtrl;
64 |
65 |
66 | // Overrides
67 | // ClassWizard generated virtual function overrides
68 | //{{AFX_VIRTUAL(CAnimationSettingsDlg)
69 | public:
70 | virtual BOOL PreTranslateMessage(MSG* pMsg);
71 | protected:
72 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
73 | //}}AFX_VIRTUAL
74 |
75 | // TOOLTIPS
76 | CToolTipCtrl m_ToolTip;
77 | BOOL OnTTN_NeedText( UINT id, NMHDR * pTTTStruct, LRESULT * pResult );
78 |
79 |
80 | // Implementation
81 | protected:
82 |
83 | // Generated message map functions
84 | //{{AFX_MSG(CAnimationSettingsDlg)
85 | virtual BOOL OnInitDialog();
86 | virtual void OnOK();
87 | afx_msg void OnTimer(UINT nIDEvent);
88 | afx_msg void OnSelchangeStnEnabled();
89 | afx_msg void OnSelchangeStnDisabled();
90 | afx_msg void OnSelchangeStnActive();
91 | afx_msg void OnSelchangeStnInactive();
92 | afx_msg void OnSelchangeStnText();
93 | afx_msg void OnSelchangeStnDisabledtext();
94 | afx_msg void OnPaint();
95 | afx_msg void OnAnimatebytes();
96 | afx_msg void OnAnimatewords();
97 | afx_msg void OnAnimTraining();
98 | afx_msg void OnNoanimate();
99 | //}}AFX_MSG
100 | DECLARE_MESSAGE_MAP()
101 | };
102 |
103 | //{{AFX_INSERT_LOCATION}}
104 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
105 |
106 | #endif // !defined(AFX_ANIMATIONSETTINGS_H__788EF6C0_384E_4725_A2D6_A20B436C0981__INCLUDED_)
107 |
--------------------------------------------------------------------------------
/ModRSsim2/CSVReader.h:
--------------------------------------------------------------------------------
1 | #ifndef CSVREADER_H_INCLUDED
2 | #define CSVREADER_H_INCLUDED
3 |
4 | // include the instrument#
5 | #define MAX_CSVFILE_COLUMNS 4 // Changed from 17 to 1 for better readability by DL on 2015-01-02
6 | // Changed from 1 to 4 for using first number as index and second number as floating point value on 2015-Nov-15 by DL
7 | #define MAX_DEBUG_STR_LEN 256
8 |
9 |
10 | class CRegisterUpdaterIF
11 | {
12 | public:
13 | virtual void DebugMessage(LPCTSTR message)=0;
14 | virtual BOOL SetRegister(LONG index, WORD value)=0;
15 | virtual BOOL SetAnalogs(LONG index, WORD value)=0; // Added 2015-Nov-15 by DL
16 | virtual BOOL SetCoils(LONG index, WORD value)=0; // Added 2015-Nov-16 by DL
17 | virtual BOOL SetInputs(LONG index, WORD value)=0; // Added 2015-Nov-16 by DL
18 | virtual BOOL ModbusClone() = 0;
19 | };
20 |
21 |
22 | //////////////////////////////////////////////////////////////////////////////
23 | // CCSVTextImporter
24 | class CCSVTextImporter : public CObject
25 | {
26 | public:
27 | CCSVTextImporter();
28 | virtual ~CCSVTextImporter();
29 |
30 |
31 | private:
32 | //friend class
33 | //////////////////////////////////////////////////////////////////////////////
34 | // CCSVTextLine
35 | class CCSVTextLine : public CString
36 | {
37 | //DECLARE_DYNAMIC(CCSVTextLine)
38 | friend class CCSVLineArray;
39 |
40 | public:
41 | CCSVTextLine(LPCSTR string);
42 | CCSVTextLine(CCSVTextLine& other);
43 | CCSVTextLine();
44 |
45 | CCSVTextLine & operator = (CCSVTextLine &otherLine);
46 | CCSVTextLine & operator = (CString &otherString);
47 |
48 | // functions to get the values out
49 | double GetElement(LONG index);
50 |
51 | void Parse();
52 |
53 | private:
54 | //double m_double;
55 |
56 | // misc variables
57 | BOOL m_init;
58 | INT m_sizedouble;
59 | double m_values[MAX_CSVFILE_COLUMNS];
60 |
61 | };
62 |
63 | //////////////////////////////////////////////////////////////////////////////
64 | // CCSVLineArray
65 | class CCSVLineArray : public CObArray
66 | {
67 | friend class CCSVTextLine;
68 | public:
69 | ~CCSVLineArray();
70 |
71 | LONG Add(CCSVTextLine *pLine);
72 | CCSVTextLine *operator [](LONG index);
73 | CCSVTextLine *GetAt(LONG index);
74 | };
75 |
76 |
77 | //////////////////////////////////////////////////////////////////////////////
78 | // CCSVTextFile
79 | class CCSVTextFile : public CFile
80 | {
81 | public:
82 | CCSVTextFile(LPCTSTR fileName, UINT flags);
83 | ~CCSVTextFile();
84 |
85 | LPCTSTR Data();
86 |
87 | private:
88 | DWORD m_length;
89 | BYTE * m_data;
90 | };
91 |
92 | // main class
93 | friend class CCSVLineArray;
94 | public:
95 |
96 | LONG ImportFile(LPCTSTR csvName, BOOL manual=FALSE, CRegisterUpdaterIF * =0);
97 | BOOL HandleTimer(LPCTSTR importFolder, CRegisterUpdaterIF *pParentInterface);
98 |
99 | double GetElement(LONG line, LONG index);
100 | LONG LineCount() {return((myArray?myArray->GetSize():0));}; // # instruments
101 |
102 | void Open(LPCTSTR fileName);
103 | BOOL LoadedOK();
104 |
105 | LONG UpdateRegisters(BOOL manual);
106 | CCSVLineArray *myArray;
107 |
108 | private:
109 | CString m_lastProcessed;
110 | SYSTEMTIME m_lastInterval;
111 |
112 | //CCSVLineArray *myArray;
113 | CRegisterUpdaterIF *m_parentInterface;
114 | };
115 |
116 | #endif // CSVREADER_H_INCLUDED
117 |
--------------------------------------------------------------------------------
/ModRSsim2/mod_RSsim.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: MOD_sim.h : headder file
4 | //
5 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
6 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
7 | // email:zaphodikus@hotmail.com
8 | //
9 | // This program is free software: you can redistribute it and/or modify
10 | // it under the terms of the GNU Affero General Public License as
11 | // published by the Free Software Foundation, either version 3 of the
12 | // License, or (at your option) any later version.
13 | //
14 | // This program is distributed in the hope that it will be useful,
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | // GNU Affero General Public License for more details.
18 | //
19 | // You should have received a copy of the GNU Affero General Public License
20 | // along with this program. If not, see .
21 | //
22 | /////////////////////////////////////////////////////////////////////////////
23 |
24 | #if !defined(AFX_TI_SIM_H__D74EE401_3D1B_4510_B1F5_58781391FEF1__INCLUDED_)
25 | #define AFX_TI_SIM_H__D74EE401_3D1B_4510_B1F5_58781391FEF1__INCLUDED_
26 |
27 | #if _MSC_VER > 1000
28 | #pragma once
29 | #endif // _MSC_VER > 1000
30 |
31 | #ifndef __AFXWIN_H__
32 | #error include 'stdafx.h' before including this file for PCH
33 | #endif
34 |
35 | #include "resource.h" // main symbols
36 |
37 | #ifndef WS_EX_LAYERED
38 | #define WS_EX_LAYERED 0x00080000
39 | #define LWA_COLORKEY 0x00000001
40 | #define LWA_ALPHA 0x00000002
41 | #endif // ndef WS_EX_LAYERED
42 |
43 | // Preparation for the function we want to import from USER32.DLL
44 | typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
45 |
46 | extern lpfnSetLayeredWindowAttributes m_pSetLayeredWindowAttributes;
47 |
48 |
49 | extern BOOL GetTNImport();
50 |
51 | extern CHAR lpsMyAppVersion[10];
52 | #define __MY_APPVERSION__ (lpsMyAppVersion)
53 |
54 | #define SIMULATOR_WINDOW_CLASSNAME "MYSimulator_Window_Classname"
55 |
56 | extern const CHAR lpAuthor_email[40];
57 |
58 | /////////////////////////////////////////////////////////////////////////////
59 | // CMOD_simApp:
60 | // See MOD_sim.cpp for the implementation of this class
61 | //
62 |
63 | class CMOD_simApp : public CWinApp
64 | {
65 | public:
66 | CMOD_simApp();
67 |
68 | // Overrides
69 | // ClassWizard generated virtual function overrides
70 | //{{AFX_VIRTUAL(CMOD_simApp)
71 | public:
72 | virtual BOOL InitInstance();
73 | //}}AFX_VIRTUAL
74 |
75 | // Implementation
76 | private:
77 | CString m_htmBookmark;
78 |
79 | public:
80 | void GetMyHelpTopic(CString &topic);
81 | void SetMyHelpTopic(LPCTSTR topic);
82 |
83 | void OnHelp();
84 | //{{AFX_MSG(CMOD_simApp)
85 | // NOTE - the ClassWizard will add and remove member functions here.
86 | // DO NOT EDIT what you see in these blocks of generated code !
87 | //}}AFX_MSG
88 | DECLARE_MESSAGE_MAP()
89 | };
90 |
91 | class SetCurrentTopic
92 | {
93 | public:
94 | SetCurrentTopic();
95 | SetCurrentTopic(LPCTSTR topic);
96 | ~SetCurrentTopic();
97 |
98 | void SetHelpTopic(LPCTSTR topic) { SetTopic(topic);};
99 |
100 | private:
101 | CString m_topicLast;
102 | void SetTopic(LPCTSTR topic);
103 | void GetTopic(CString& topic);
104 | };
105 |
106 |
107 |
108 |
109 | /////////////////////////////////////////////////////////////////////////////
110 |
111 | //{{AFX_INSERT_LOCATION}}
112 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
113 |
114 | #endif // !defined(AFX_TI_SIM_H__D74EE401_3D1B_4510_B1F5_58781391FEF1__INCLUDED_)
115 |
--------------------------------------------------------------------------------
/ModRSsim2/About.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_ABOUT_H__E2C72AC3_9FBF_4BB0_A2C7_0A07706C57A8__INCLUDED_)
2 | #define AFX_ABOUT_H__E2C72AC3_9FBF_4BB0_A2C7_0A07706C57A8__INCLUDED_
3 | /////////////////////////////////////////////////////////////////////////////
4 | // About.h : header file
5 | // CAboutDlg dialog
6 | //
7 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
8 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
9 | // email:zaphodikus@hotmail.com
10 | //
11 | // This program is free software: you can redistribute it and/or modify
12 | // it under the terms of the GNU Affero General Public License as
13 | // published by the Free Software Foundation, either version 3 of the
14 | // License, or (at your option) any later version.
15 | //
16 | // This program is distributed in the hope that it will be useful,
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | // GNU Affero General Public License for more details.
20 | //
21 | // You should have received a copy of the GNU Affero General Public License
22 | // along with this program. If not, see .
23 |
24 | #include "CreditStatic.h"
25 |
26 | class CAboutDlg : public CDialog
27 | {
28 | // Construction
29 | public:
30 | CAboutDlg(CWnd* pParent = NULL); // standard constructor
31 |
32 | // Dialog Data
33 | //{{AFX_DATA(CAboutDlg)
34 | enum { IDD = IDD_ABOUTBOX };
35 | // NOTE: the ClassWizard will add data members here
36 | //}}AFX_DATA
37 |
38 | CStaticLink m_hyperlink1; // plcsimulator.org
39 | //CStaticLink m_hyperlink2; // modicon // Deleted 2015-07-26 by DL
40 | CStaticLink m_emaillink1;
41 |
42 | CCreditStatic m_static;
43 |
44 | CString m_registeredUser, m_registeredKey;
45 | BOOL m_registeredOK;
46 |
47 | SetCurrentTopic m_topic; //help system
48 |
49 | // Implementation
50 | protected:
51 |
52 | // TOOLTIPS
53 | CToolTipCtrl m_ToolTip;
54 | BOOL OnTTN_NeedText( UINT id, NMHDR * pTTTStruct, LRESULT * pResult );
55 | void SetRegStatus();
56 | // Overrides
57 | // ClassWizard generated virtual function overrides
58 | //{{AFX_VIRTUAL(CAboutDlg)
59 | public:
60 | virtual BOOL PreTranslateMessage(MSG* pMsg);
61 | protected:
62 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
63 | //}}AFX_VIRTUAL
64 |
65 | // Implementation
66 | protected:
67 |
68 | // Generated message map functions
69 | //{{AFX_MSG(CAboutDlg)
70 | virtual BOOL OnInitDialog();
71 | virtual void OnOK();
72 | afx_msg void OnSplash();
73 | //}}AFX_MSG
74 | DECLARE_MESSAGE_MAP()
75 | public:
76 | afx_msg void OnBnClickedCheckupdates();
77 | afx_msg void OnBnClickedEditregistration();
78 | };
79 |
80 | /////////////////////////////////////////////////////////////////////////////////
81 | // A Dialog and methods to remind the user they must 'register'.
82 | // Basically you e-mail me and I send a free .REG file key
83 | //
84 | #define DEMOSECONDS (60*45) // 45 minutes
85 |
86 | class CRegistrationTest
87 | {
88 | public:
89 | CRegistrationTest();
90 |
91 | //static void ShowRegistrationMessage(); // Removed 2016-10-22 by DL
92 | //void RegistrationReminder(); // Removed 2016-10-22 by DL
93 |
94 | // perform the check
95 | //BOOL CheckRegistrationKey(LPCTSTR name, LPCTSTR key); // Removed 2016-10-22 by DL
96 | //static BOOL CheckRegistrationKey(LPCTSTR name, LPCTSTR key, bool suppressUI); // Removed 2016-10-22 by DL
97 |
98 | BOOL IsRegistered() {return(m_registeredOK);};
99 |
100 | private:
101 | BOOL m_registeredOK;
102 | DWORD m_registrationTimerStart;
103 | BOOL m_demoPeriodEnded;
104 | }; // CRegistrationTest
105 |
106 | //{{AFX_INSERT_LOCATION}}
107 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
108 |
109 | #endif // !defined(AFX_ABOUT_H__E2C72AC3_9FBF_4BB0_A2C7_0A07706C57A8__INCLUDED_)
110 |
--------------------------------------------------------------------------------
/ModRSsim2/joysccemulation.cpp:
--------------------------------------------------------------------------------
1 | // JoySCCEmulation.cpp : implementation file
2 | //
3 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
4 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU Affero General Public License as
8 | // published by the Free Software Foundation, either version 3 of the
9 | // License, or (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Affero General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Affero General Public License
17 | // along with this program. If not, see .
18 | //
19 |
20 | #include "stdafx.h"
21 | #include "mod_rssim.h"
22 | #include "resource.h"
23 | #include "JoySCCEmulation.h"
24 |
25 | #ifdef _DEBUG
26 | #define new DEBUG_NEW
27 | #undef THIS_FILE
28 | static char THIS_FILE[] = __FILE__;
29 | #endif
30 |
31 | /////////////////////////////////////////////////////////////////////////////
32 | // CJoySCCEmulationDlg dialog
33 |
34 |
35 | CJoySCCEmulationDlg::CJoySCCEmulationDlg(CWnd* pParent /*=NULL*/)
36 | : CDialog(CJoySCCEmulationDlg::IDD, pParent)
37 | {
38 | //{{AFX_DATA_INIT(CJoySCCEmulationDlg)
39 | m_destAddr = 0;
40 | m_sourceAddr = 0;
41 | m_runMode = FALSE;
42 | m_numShields = 0;
43 | m_readVariables = FALSE;
44 | m_writeVariables = FALSE;
45 | m_ABidletime = 0;
46 | m_ABtimeout = 0;
47 | //}}AFX_DATA_INIT
48 |
49 | m_emulationOK = TRUE;
50 | m_topic.SetHelpTopic("ProtocolsJoy");
51 | }
52 |
53 |
54 | void CJoySCCEmulationDlg::DoDataExchange(CDataExchange* pDX)
55 | {
56 | CDialog::DoDataExchange(pDX);
57 | //{{AFX_DATA_MAP(CJoySCCEmulationDlg)
58 | DDX_Text(pDX, IDC_SCC_DEST, m_destAddr);
59 | DDV_MinMaxUInt(pDX, m_destAddr, 0, 255);
60 | DDX_Text(pDX, IDC_SCC_SOURCE, m_sourceAddr);
61 | DDV_MinMaxUInt(pDX, m_sourceAddr, 0, 255);
62 | DDX_Check(pDX, IDC_RUN, m_runMode);
63 | DDX_Text(pDX, IDC_NUMSHIELDS, m_numShields);
64 | DDV_MinMaxUInt(pDX, m_numShields, 1, 154);
65 | DDX_Check(pDX, IDC_READVARIABLES, m_readVariables);
66 | DDX_Check(pDX, IDC_WRITEVARIABLES, m_writeVariables);
67 | DDX_Text(pDX, IDC_IDLE, m_ABidletime);
68 | DDV_MinMaxUInt(pDX, m_ABidletime, 0, 10000);
69 | DDX_Text(pDX, IDC_TIMEOUT, m_ABtimeout);
70 | DDV_MinMaxUInt(pDX, m_ABtimeout, 100, 20000);
71 | //}}AFX_DATA_MAP
72 | }
73 |
74 |
75 | BEGIN_MESSAGE_MAP(CJoySCCEmulationDlg, CDialog)
76 | //{{AFX_MSG_MAP(CJoySCCEmulationDlg)
77 | ON_BN_CLICKED(IDC_EMU, OnEmu)
78 | //}}AFX_MSG_MAP
79 | END_MESSAGE_MAP()
80 |
81 | /////////////////////////////////////////////////////////////////////////////
82 | // CJoySCCEmulationDlg message handlers
83 |
84 | void CJoySCCEmulationDlg::OnOK()
85 | {
86 | // TODO: Add extra validation here
87 | CDialog::OnOK();
88 | if (!m_readVariables && !m_writeVariables)
89 | {
90 | m_writeVariables = TRUE;
91 | }
92 | }
93 |
94 | void CJoySCCEmulationDlg::OnCancel()
95 | {
96 | // TODO: Add extra cleanup here
97 |
98 | CDialog::OnCancel();
99 | }
100 |
101 | void CJoySCCEmulationDlg::OnEmu()
102 | {
103 | void *pDialogRam;
104 | DWORD ClsSize = sizeof(CAdvEmulationDlg);
105 |
106 | pDialogRam = new char[ClsSize];
107 | memcpy(pDialogRam, m_emuDlgPtr, ClsSize);
108 |
109 | // set the bookmark in the help!
110 | m_topic.SetHelpTopic("ProtocolsModbus");
111 | //
112 | m_emulationOK = m_emuDlgPtr->DoModal();
113 | if (IDOK != m_emulationOK)
114 | {
115 | // restore things to what they where, since user cancelled the dialog
116 | memcpy(m_emuDlgPtr, pDialogRam, ClsSize);
117 | }
118 | delete pDialogRam;
119 |
120 | // change help topic bookmark back again
121 | m_topic.SetHelpTopic("ProtocolsJoy");
122 | }
123 |
--------------------------------------------------------------------------------
/ModRSsim2/CreditStatic.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_CREDITSTATIC_H__4ABD7701_49F5_11D1_9E3C_00A0245800CF__INCLUDED_)
2 | #define AFX_CREDITSTATIC_H__4ABD7701_49F5_11D1_9E3C_00A0245800CF__INCLUDED_
3 |
4 | #if _MSC_VER >= 1000
5 | #pragma once
6 | #endif // _MSC_VER >= 1000
7 | // CreditStatic.h : header file
8 | // source from : http://codeguru.earthweb.com/staticctrl/credit_static.shtml
9 |
10 | #define DISPLAY_SLOW 0
11 | #define DISPLAY_MEDIUM 1
12 | #define DISPLAY_FAST 2
13 |
14 | #define BACKGROUND_COLOR 0
15 | #define TOP_LEVEL_TITLE_COLOR 1
16 | #define TOP_LEVEL_GROUP_COLOR 2
17 | #define GROUP_TITLE_COLOR 3
18 | #define NORMAL_TEXT_COLOR 4
19 |
20 | #define TOP_LEVEL_TITLE_HEIGHT 21
21 | #define TOP_LEVEL_GROUP_HEIGHT 19
22 | #define GROUP_TITLE_HEIGHT 17
23 | #define NORMAL_TEXT_HEIGHT 15
24 |
25 | #define TOP_LEVEL_TITLE 0 // '\t'
26 | #define TOP_LEVEL_GROUP 1 // '\n'
27 | #define GROUP_TITLE 2 // '\r'
28 | #define DISPLAY_BITMAP 3 // '^'
29 | #define NORMAL_CENTER 4 // '%'
30 | #define LEFT_ALIGN1 5 // '$'
31 | #define LEFT_ALIGN2 6 // '`'
32 |
33 | #define MAX_STYLES (LEFT_ALIGN2+1)
34 |
35 | #define GRADIENT_NONE 0
36 | #define GRADIENT_RIGHT_DARK 1
37 | #define GRADIENT_RIGHT_LIGHT 2
38 | #define GRADIENT_LEFT_DARK 3
39 | #define GRADIENT_LEFT_LIGHT 4
40 |
41 | class CCreditStatic : public CStatic
42 | {
43 | protected:
44 | COLORREF m_Colors[5];
45 | int m_TextHeights[MAX_STYLES];
46 | TCHAR m_Escapes[MAX_STYLES];
47 | int m_DisplaySpeed[3],m_CurrentSpeed;
48 | // CRect m_ScrollRect; // rect of Static Text frame
49 | CStringList m_ArrCredit;
50 | CString m_szWork;
51 | int m_nCounter; // work ints
52 | POSITION m_ArrIndex;
53 | BOOL m_bFirstTime;
54 | BOOL m_bDrawText;
55 | int m_nClip,m_ScrollAmount;
56 | int m_nCurrentFontHeight;
57 |
58 | CBitmap m_bmpWork; // bitmap holder
59 | CBitmap m_BmpMain; // bitmap holder
60 |
61 | CSize m_size; // drawing helpers
62 | CPoint m_pt;
63 | BOOL m_bProcessingBitmap;
64 | CPalette m_pal;
65 | CBitmap m_bitmap;
66 | int m_cxBitmap, m_cyBitmap;
67 | BOOL m_bFirstTurn;
68 | UINT m_Gradient;
69 | BOOL m_bTransparent;
70 | int n_MaxWidth;
71 | UINT TimerOn;
72 | // Construction
73 | public:
74 | CCreditStatic();
75 |
76 | // Attributes
77 | public:
78 |
79 | // Operations
80 | public:
81 | BOOL StartScrolling();
82 | void EndScrolling();
83 | void SetCredits(LPCTSTR credits, char delimiter = '|');
84 | void SetCredits(UINT nID, char delimiter = '|');
85 | void SetSpeed(UINT index, int speed = 0);
86 | void SetColor(UINT index, COLORREF col);
87 | void SetTextHeight(UINT index, int height);
88 | void SetEscape(UINT index, char escape);
89 | void SetGradient(UINT value = GRADIENT_RIGHT_DARK);
90 | BOOL SetBkImage(UINT nIDResource);
91 | BOOL SetBkImage(LPCTSTR lpszResourceName);
92 | void SetTransparent(BOOL bTransparent = TRUE);
93 | // Overrides
94 | // ClassWizard generated virtual function overrides
95 | //{{AFX_VIRTUAL(CCreditStatic)
96 | //}}AFX_VIRTUAL
97 |
98 | // Implementation
99 | public:
100 | virtual ~CCreditStatic();
101 |
102 | // Generated message map functions
103 | protected:
104 | void MoveCredit(CDC *pDC, CRect& r, CRect& r2, BOOL bCheck);
105 | void AddBackGround(CDC* pDC, CRect& m_ScrollRect, CRect& m_ClientRect);
106 | void DrawCredit(CDC* pDC, CRect& m_ScrollRect);
107 | void FillGradient(CDC *pDC, CRect *m_ScrollRect, CRect *m_FillRect, COLORREF color);
108 | void DrawBitmap(CDC* pDC, CDC* pDC2, CRect *rBitmap);
109 |
110 | //{{AFX_MSG(CCreditStatic)
111 | afx_msg void OnPaint();
112 | afx_msg BOOL OnEraseBkgnd(CDC* pDC);
113 | afx_msg void OnTimer(UINT nIDEvent);
114 | afx_msg void OnDestroy();
115 | //}}AFX_MSG
116 |
117 | DECLARE_MESSAGE_MAP()
118 | };
119 |
120 | /////////////////////////////////////////////////////////////////////////////
121 |
122 | //{{AFX_INSERT_LOCATION}}
123 | // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
124 |
125 | #endif // !defined(AFX_CREDITSTATIC_H__4ABD7701_49F5_11D1_9E3C_00A0245800CF__INCLUDED_)
126 |
--------------------------------------------------------------------------------
/mylib/StatLink.cpp:
--------------------------------------------------------------------------------
1 |
2 | //StatLink.cpp
3 |
4 | //////////////////////////////////////////////////////////////////
5 | // CStaticLink 1997 Microsoft Systems Journal.
6 | // If this program works, it was written by Paul DiLascia.
7 | // If not, I don't know who wrote it.
8 | // CStaticLink implements a static control that's a hyperlink
9 | // to any file on your desktop or web. You can use it in dialog boxes
10 | // to create hyperlinks to web sites. When clicked, opens the file/URL
11 | //
12 | #include "StdAfx.h"
13 | #include "resource.h"
14 |
15 | #ifdef _DEBUG
16 | #define new DEBUG_NEW
17 | #undef THIS_FILE
18 | static char THIS_FILE[] = __FILE__;
19 | #endif
20 |
21 | IMPLEMENT_DYNAMIC(CStaticLink, CStatic)
22 |
23 | BEGIN_MESSAGE_MAP(CStaticLink, CStatic)
24 | //{{AFX_MSG_MAP(CStaticLink)
25 | ON_WM_SETCURSOR()
26 | //}}AFX_MSG_MAP
27 | ON_WM_CTLCOLOR_REFLECT()
28 | ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
29 | END_MESSAGE_MAP()
30 | ///////////////////
31 | // Constructor sets default colors = blue/purple.
32 | //
33 | CStaticLink::CStaticLink()
34 | {
35 | m_colorUnvisited = RGB(0,0,255); // blue
36 | m_colorVisited = RGB(128,0,128); // purple
37 | m_bVisited = FALSE; // not visited yet
38 | m_hHandCursor = 0;
39 | //{{AFX_DATA_INIT(CStaticLink)
40 | //}}AFX_DATA_INIT
41 | }
42 | //////////////////// Handle reflected WM_CTLCOLOR to set custom control color.
43 | // For a text control, use visited/unvisited colors and underline font.
44 | // For non-text controls, do nothing. Also ensures SS_NOTIFY is on.
45 | //
46 | HBRUSH CStaticLink::CtlColor(CDC* pDC, UINT nCtlColor)
47 | {
48 | ASSERT(nCtlColor == CTLCOLOR_STATIC);
49 | DWORD dwStyle = GetStyle();
50 | if (!(dwStyle & SS_NOTIFY)) {
51 | // Turn on notify flag to get mouse messages and STN_CLICKED.
52 | // Otherwise, I'll never get any mouse clicks!
53 | ::SetWindowLong(m_hWnd, GWL_STYLE, dwStyle | SS_NOTIFY);
54 | }
55 |
56 | HBRUSH hbr = NULL;
57 | if ((dwStyle & 0xFF) <= SS_RIGHT) {
58 |
59 | // this is a text control: set up font and colors
60 | if (!(HFONT)m_font) {
61 | // first time init: create font
62 | LOGFONT lf;
63 | GetFont()->GetObject(sizeof(lf), &lf);
64 | lf.lfUnderline = TRUE;
65 | m_font.CreateFontIndirect(&lf);
66 | }
67 |
68 | // use underline font and visited/unvisited colors
69 | pDC->SelectObject(&m_font);
70 | pDC->SetTextColor(m_bVisited ? m_colorVisited : m_colorUnvisited);
71 | pDC->SetBkMode(TRANSPARENT);
72 |
73 | // return hollow brush to preserve parent background color
74 | hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
75 | }
76 | return hbr;
77 | }
78 | /////////////////
79 | // Handle mouse click: open URL/file.
80 | //
81 | void CStaticLink::OnClicked()
82 | {
83 | if (m_link.IsEmpty()) // if URL/filename not set..
84 | GetWindowText(m_link); // ..get it from window text
85 |
86 | // Call ShellExecute to run the file.
87 | // For an URL, this means opening it in the browser.
88 | //
89 | HINSTANCE h = ShellExecute(NULL, "open", m_link, NULL, NULL, SW_SHOWNORMAL);
90 | if ((UINT)h > 32) {
91 | m_bVisited = TRUE; // (not really--might not have found link)
92 | Invalidate(); // repaint to show visited color
93 | } else {
94 | MessageBeep(0); // unable to execute file!
95 | TRACE(_T("*** WARNING: CStaticLink: unable to execute file %s\n"),
96 | (LPCTSTR)m_link);
97 | }
98 | }
99 |
100 | BOOL CStaticLink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
101 | {
102 | ASSERT(m_hHandCursor); // if running windows versons before 2000, the next couple of lines will not work,
103 | // supply a handle in the caller please.
104 | if (0== m_hHandCursor)
105 | m_hHandCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(32649));//AfxGetApp()->LoadCursor("IDC_MYHANDCURSOR"); // LoadCursor(0, MAKEINTRESOURCE(IDC_MYHANDCURSOR));//
106 | ::SetCursor(m_hHandCursor);//IDC_WAIT));
107 | return (TRUE);
108 | //return CStaticLink::OnSetCursor(pWnd, nHitTest, message);
109 | }
110 |
--------------------------------------------------------------------------------
/mylib/ColorStatic.cpp:
--------------------------------------------------------------------------------
1 | // ColorStatic.cpp : implementation file
2 | //
3 |
4 | #include "stdafx.h"
5 |
6 | #include
7 |
8 | #ifdef _DEBUG
9 | #define new DEBUG_NEW
10 | #undef THIS_FILE
11 | static char THIS_FILE[] = __FILE__;
12 | #endif
13 |
14 | /////////////////////////////////////////////////////////////////////////////
15 | // CColorStatic
16 |
17 | CColorStatic::CColorStatic()
18 | {
19 | m_color = RGB(255,0,0); //initialize to red by default, so that folks
20 | // know that we are here.
21 | }
22 |
23 | CColorStatic::~CColorStatic()
24 | {
25 | }
26 |
27 |
28 | BEGIN_MESSAGE_MAP(CColorStatic, CStatic)
29 | //{{AFX_MSG_MAP(CColorStatic)
30 | // NOTE - the ClassWizard will add and remove mapping macros here.
31 | //}}AFX_MSG_MAP
32 | ON_WM_CTLCOLOR_REFLECT()
33 | END_MESSAGE_MAP()
34 |
35 | /////////////////////////////////////////////////////////////////////////////
36 | // CColorStatic message handlers
37 |
38 | //////////////////// Handle reflected WM_CTLCOLOR to set custom control color.
39 | // For a text control, use visited/unvisited colors and underline font.
40 | // For non-text controls, do nothing.
41 | //
42 | HBRUSH CColorStatic::CtlColor(CDC* pDC, UINT nCtlColor)
43 | {
44 | ASSERT(nCtlColor == CTLCOLOR_STATIC);
45 | DWORD dwStyle = GetStyle();
46 | /*
47 | if (!(dwStyle & SS_NOTIFY)) {
48 | // Turn on notify flag to get mouse messages and STN_CLICKED.
49 | // Otherwise, I'll never get any mouse clicks!
50 | ::SetWindowLong(m_hWnd, GWL_STYLE, dwStyle | SS_NOTIFY);
51 | }
52 | */
53 | HBRUSH hbr = NULL;
54 | if ((dwStyle & 0xFF) <= SS_RIGHT)
55 | {
56 | // this is a text control: set up font and colors
57 | if (!(HFONT)m_font)
58 | {
59 | // first time init: create font
60 | LOGFONT lf;
61 | GetFont()->GetObject(sizeof(lf), &lf);
62 | m_font.CreateFontIndirect(&lf);
63 | }
64 |
65 | // use ...
66 | pDC->SelectObject(&m_font);
67 | pDC->SetTextColor(m_color);
68 | pDC->SetBkMode(TRANSPARENT);
69 |
70 | // return hollow brush to preserve parent background color
71 | hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
72 | }
73 | return hbr;
74 | }
75 |
76 |
77 | /////////////////////////////////////////////////////////////////////////////
78 | // CSampler
79 |
80 | CSampler::CSampler()
81 | {
82 | m_color = 0; // default to black
83 | }
84 |
85 | CSampler::~CSampler()
86 | {
87 | }
88 |
89 |
90 | BEGIN_MESSAGE_MAP(CSampler, CEdit)
91 | //{{AFX_MSG_MAP(CSampler)
92 | ON_WM_PAINT()
93 | //}}AFX_MSG_MAP
94 | END_MESSAGE_MAP()
95 |
96 | /////////////////////////////////////////////////////////////////////////////
97 | // CSampler message handlers
98 |
99 | // ------------------------------ OnPaint ------------------------------
100 | void CSampler::OnPaint()
101 | {
102 | RECT clientRect;
103 | CBrush backBrush;
104 |
105 | CPaintDC dc(this); // device context for painting
106 |
107 | // TODO: Add your message handler code here
108 | GetClientRect(&clientRect);
109 | backBrush.CreateSolidBrush(m_color);
110 | dc.FillRect(&clientRect, &backBrush);
111 |
112 | // Do not call CEdit::OnPaint() for painting messages
113 | } // OnPaint
114 |
115 | // ----------------------------------- SetNewColor ---------------------------
116 | //
117 | void CSampler::SetNewColor(COLORREF color)
118 | {
119 | ASSERT(m_hWnd); // window must already exist
120 | m_color = color;
121 | InvalidateRect(NULL);
122 | } // SetNewColor
123 |
124 | // -------------------------------- BrowseColor ------------------------------
125 | COLORREF CSampler::BrowseColor()
126 | {
127 | static COLORREF custColors[16];
128 |
129 | ASSERT(m_hWnd); // window must already exist
130 |
131 | // init custom colors to all white
132 | for (int i=0;i<16;i++)
133 | custColors[i] = RGB(255,255,255);
134 | custColors[0] = m_color; // set our old or existing color into the custom colors
135 |
136 | CColorDialog cc( m_color,/*CC_PREVENTFULLOPEN | */CC_RGBINIT | CC_ANYCOLOR);
137 | cc.m_cc.lpCustColors = custColors; // point to my custom colours
138 |
139 | // invoke dialog
140 | cc.DoModal();
141 |
142 | // retrieve colour from dialog into the control
143 | SetNewColor(cc.m_cc.rgbResult);
144 | return(cc.m_cc.rgbResult);
145 | }
146 |
147 |
--------------------------------------------------------------------------------
/ModRSsim2/ServerSettingsEthDlg.cpp:
--------------------------------------------------------------------------------
1 | // ServerSettingsEthDlg.cpp : implementation file
2 | //
3 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
4 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU Affero General Public License as
8 | // published by the Free Software Foundation, either version 3 of the
9 | // License, or (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Affero General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Affero General Public License
17 | // along with this program. If not, see .
18 | //
19 |
20 | #include "stdafx.h"
21 | #include "mod_RSsim.h"
22 | #include "ServerSettingsEthDlg.h"
23 | #include "mod_RSsimDlg.h"
24 |
25 | #ifdef _DEBUG
26 | #define new DEBUG_NEW
27 | #undef THIS_FILE
28 | static char THIS_FILE[] = __FILE__;
29 | #endif
30 |
31 | extern CMOD_simDlg * pGlobalDialog;
32 |
33 |
34 | /////////////////////////////////////////////////////////////////////////////
35 | // CServerSettingsEthDlg dialog
36 |
37 |
38 | CServerSettingsEthDlg::CServerSettingsEthDlg(CWnd* pParent /*=NULL*/)
39 | : CDialog(CServerSettingsEthDlg::IDD, pParent)
40 | {
41 | //{{AFX_DATA_INIT(CServerSettingsEthDlg)
42 | m_localPort = 0; // these get changed by the caller
43 | m_SockTO = 100; // 2015-01-30 by DL Changed from "m_localID = 0;"
44 | m_responseDelay = 0;
45 | m_linger = FALSE;
46 | m_numServers = 0;
47 | m_localIPStr = _T("");
48 | m_remoteIPStr = _T("");
49 | m_other = 0;
50 | m_autoLoad = FALSE; // Added 2015-07-19 by DL to show these on Eth screen
51 | m_startAsOff = FALSE; // Added 2015-07-19 by DL to show these on Eth screen
52 | m_rtuFrame = FALSE;
53 | //}}AFX_DATA_INIT
54 | }
55 |
56 |
57 | void CServerSettingsEthDlg::DoDataExchange(CDataExchange* pDX)
58 | {
59 | CDialog::DoDataExchange(pDX);
60 | //{{AFX_DATA_MAP(CServerSettingsEthDlg)
61 | DDX_Text(pDX, IDC_LOCALPORT, m_localPort);
62 | DDV_MinMaxUInt(pDX, m_localPort, 0, 9999);
63 | DDX_Text(pDX, IDC_SOCKTO, m_SockTO); // 2015-01-30 by DL Changed from IDC_LOCALID and m_localID
64 | DDV_MinMaxUInt(pDX, m_SockTO, 10, 1000); // 2015-01-30 by DL Changed from m_localID and 9999
65 | DDX_Text(pDX, IDC_RESPONSEDELAY, m_responseDelay);
66 | DDV_MinMaxUInt(pDX, m_responseDelay, 0, 10000);
67 | DDX_Check(pDX, IDC_LINGER, m_linger);
68 | DDX_Text(pDX, IDC_NUMSERVERS, m_numServers);
69 | DDV_MinMaxUInt(pDX, m_numServers, 1, 1000);
70 | DDX_Text(pDX, IDC_LOCALIP, m_localIPStr);
71 | DDX_Text(pDX, IDC_REMOTEIP, m_remoteIPStr);
72 | DDX_Text(pDX, IDC_LOCALPORT2, m_other);
73 | DDV_MinMaxDWord(pDX, m_other, 0, 65535);
74 | DDX_Check(pDX, IDC_AUTOLOAD, m_autoLoad); // 2015-07-19 by DL to Show and Set Autoload Status
75 | DDX_Check(pDX, IDC_STARTOFF, m_startAsOff); // 2015-07-19 by DL to Show and Set Start All Stations Off
76 | DDX_Check(pDX, IDC_RTUFRAME, m_rtuFrame);
77 | //}}AFX_DATA_MAP
78 | }
79 |
80 |
81 | BEGIN_MESSAGE_MAP(CServerSettingsEthDlg, CDialog)
82 | //{{AFX_MSG_MAP(CServerSettingsEthDlg)
83 | //}}AFX_MSG_MAP
84 | END_MESSAGE_MAP()
85 |
86 | /////////////////////////////////////////////////////////////////////////////
87 | // CServerSettingsEthDlg message handlers
88 |
89 | void CServerSettingsEthDlg::OnOK()
90 | {
91 | // TODO: Add extra validation here
92 |
93 | CDialog::OnOK();
94 | }
95 |
96 | // ----------------------------- OnInitDialog -------------------------------
97 | BOOL CServerSettingsEthDlg::OnInitDialog()
98 | {
99 | CString format;
100 | CString result;
101 |
102 | CDialog::OnInitDialog();
103 | m_topic.SetHelpTopic("Ethernet Setup");
104 |
105 | if (!pGlobalDialog->m_pServerSockArray) // offline
106 | result = "offline (not listening)";
107 | else
108 | {
109 | GetDlgItemText(IDC_SERVERLINE, format);
110 |
111 | result.Format(format, pGlobalDialog->m_numServers);
112 | }
113 | SetDlgItemText(IDC_SERVERLINE, result);
114 |
115 | return TRUE; // return TRUE unless you set the focus to a control
116 | // EXCEPTION: OCX Property Pages should return FALSE
117 | }
118 |
--------------------------------------------------------------------------------
/ModRSsim2/RS232Noise.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE : RS232Noise.h: headder file
4 | //
5 | // See _README.CPP
6 | //
7 | // Interface for the CRS232Noise class.
8 | // The class takes a parameter to a 232 port, and a telegram, and attempts
9 | // to corrupt it, thereby simulating real-world noise. there are currently
10 | // 6 types of noise:
11 | // inserts : Adds additional characters anywhere into the transmission
12 | // removes : Removes characters from anywhere
13 | // misframes : Simulate bad line noise, by changing the port parity and baud rate
14 | // corrupts : Replaces any character with another random character
15 | // ignore : does not respond at all
16 | // slowness/delays : simulates the act of thinking.
17 | //
18 | // The chances of an error being injected for any 1 transmission is based on
19 | // its length and the frequency parameter passed to the class. A frequency of
20 | // zero injects no errors.
21 | //
22 | /////////////////////////////////////////////////////////////////////////////
23 |
24 | #if !defined(AFX_RS232NOISE_H__211E2031_B4D1_424C_BDC8_8E6ED6B307B2__INCLUDED_)
25 | #define AFX_RS232NOISE_H__211E2031_B4D1_424C_BDC8_8E6ED6B307B2__INCLUDED_
26 |
27 | #if _MSC_VER > 1000
28 | #pragma once
29 | #endif // _MSC_VER > 1000
30 |
31 | class CRS232Port;
32 | #define MAXERRORFREQUENCY 100
33 |
34 | class CRS232Noise : public CObject
35 | {
36 | public:
37 | CRS232Noise();
38 | virtual ~CRS232Noise();
39 | void Inject(); // now
40 |
41 | // SET methods
42 | void SetErrorTypes(BOOL enable,
43 | LONG freq,
44 | LONG period = 1000,
45 | BOOL inserts = TRUE,
46 | BOOL removes = TRUE,
47 | BOOL misFrames = FALSE,
48 | BOOL corrupts = TRUE,
49 | BOOL ignore = TRUE,
50 | BOOL parityFaults = TRUE,
51 | BOOL beep = TRUE
52 | );
53 | // overload
54 | void SetErrorTypes(CRS232Noise *pOther);
55 | LONG InjectErrors(CRS232Port *pPort,
56 | const BYTE *transmitBuffer,
57 | int writeLength,
58 | char *pDebugStr);
59 |
60 | void ReportError(LPCTSTR descr);
61 |
62 | // GET methods
63 | LONG MaxErrorFreQ() { return(MAXERRORFREQUENCY);};
64 | void GetErrorTypes(BOOL * enable,
65 | int *freq,
66 | int *period, // delays by (0=disable)
67 | BOOL *inserts,
68 | BOOL *removes,
69 | BOOL *misFrames,
70 | BOOL *corrupts,
71 | BOOL *ignore,
72 | BOOL *parity,
73 | BOOL *beep
74 | );
75 | // get and clear the error counter
76 | LONG NumErrors() {LONG e = m_errorsInjected; \
77 | m_errorsInjected=0; return(e); };
78 | LONG ErrorsEnabled() { return(m_enableFaults);};
79 |
80 | BOOL NukePort();
81 | BOOL NukeParity();
82 | BOOL UnNukePort();
83 |
84 | protected:
85 | BOOL m_nowInject;
86 | // data members that contain types of noise we could apply to the comms
87 | BOOL m_enableFaults; // Y/N flag
88 |
89 | BOOL m_insertCharacters;
90 | BOOL m_removeCharacters;
91 | BOOL m_corruptFraming; // change com port settings to corrupt the data.
92 | BOOL m_modifyCharacters; // overwrite some characters
93 | LONG m_errorFrequency; //
94 | LONG m_errorsInjected; // errors so far
95 | BOOL m_parityFaults;
96 |
97 | LONG m_delaysPeriod; //
98 | BOOL m_ignoreReq; // ignore the req (don't send anything)
99 | BOOL m_beep; // beep afterwards
100 |
101 | BOOL m_nukedPort; // nuked Y/N flag
102 | // DWORD m_oldBaud;
103 | DWORD reserved;
104 | CRS232Port *m_pPort;
105 | public:
106 | CDDKSrvSocket* m_pSocketObj;
107 | };
108 |
109 |
110 | class CEthernetNoise : public CRS232Noise
111 | {
112 | public:
113 | CEthernetNoise();
114 |
115 | LONG InjectErrors(CDDKSrvSocket *pSock,
116 | SOCKET openSock,
117 | const BYTE *transmitBuffer,
118 | int writeLength,
119 | char *pDebugStr);
120 |
121 | };
122 |
123 | #endif // !defined(AFX_RS232NOISE_H__211E2031_B4D1_424C_BDC8_8E6ED6B307B2__INCLUDED_)
124 |
--------------------------------------------------------------------------------
/ModRSsim2/util.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | // FILE: UTIL.h
3 | //
4 | // Purpose: utility stuff and some constants.
5 | // This file is basically declaring all the stuff I ripped out of
6 | // my personal libraries.
7 | // Function and class implementations are in UTIL.CPP
8 | //
9 | /////////////////////////////////////////////////////////////////////////////
10 |
11 | #ifndef SIMUL_UTIL_H_INCLUDED
12 | #define SIMUL_UTIL_H_INCLUDED
13 |
14 | /////////////////////////////////////////////////////////////////////////////
15 | // GLOBAL Constants
16 | //
17 | // The program stores its settings here in the registry.
18 | //
19 | #define APPREGISTRY_SETTINGSKEY "SOFTWARE\\Adroit Technologies\\Adroit\\Simulators\\ModbusRTUSim"
20 |
21 | #define TRUE 1
22 | #define FALSE 0
23 | #define SUCCESS 0
24 | /*
25 | #ifdef FAILED
26 | #undef FAILED
27 | #endif
28 |
29 | #define FAILED -1
30 | */
31 | #undef FAILED
32 | #define FAILED(Status) ((HRESULT)(Status)<0)
33 | #define aFAILED -1
34 |
35 | #define SEVENDATABITS 7 // used in the Serial-port Combo-box
36 | #define EIGHTDATABITS 8
37 |
38 | #define MAX_COMPORT_NAME 256 // serial port names may not be longer than this
39 | #define MAX_VALUE_NAME 256 // ditto
40 | #define MAX_DEBUG_STR_LEN 256 //
41 |
42 | #define BITS_IN_WORD 16
43 |
44 | #define MAX_MOD_MEMWORDS 65536 //9999 // PLC RAM size per PLC register/type Area
45 |
46 | // indexes for PLCMemory
47 | #define MODBUS_MEM_OUTPUTS 0
48 | #define MODBUS_MEM_INPUTS 1
49 | #define MODBUS_MEM_ANALOGS 2
50 | #define MODBUS_MEM_REGISTERS 3
51 | #define MODBUS_MEM_EXTREGISTERS 4
52 | #define MAX_MOD_MEMTYPES 6 // PLC RAM areas MAX
53 | // This parameter should probably rightly be 5, but in CMOD_simDlg::FillComboBox it looks for
54 | // a blank string ("") which is at PLCMemoryTypes[5] for finding the end of its entries.
55 |
56 | #define STATIONTICKBOXESMAX 256 // Total Station Count & max Station Number + 1 (0 - 255 decimal)
57 |
58 | //#define STATIONTICKBOXESCOUNTSTART 5 // LEDs stay on for 5 timer ticks
59 |
60 |
61 | /////////////////////////////////////////////////////////////////////////////
62 | // Utility functions implemented in UTIL.CPP
63 | //
64 |
65 | WORD UnPackField(BYTE **pBuffer, WORD length);
66 | WORD UnPackASCIIField(BYTE **pBuffer, WORD length, BOOL &);
67 |
68 | WORD SwapBytes(WORD wrd);
69 |
70 |
71 | LONG RegDelete( HKEY hParentKey, // handle of open key
72 | LPCTSTR lpSubKey // address of name of subkey to delete
73 | );
74 |
75 | LONG EnumerateSerialPorts (char *deviceName, //port name
76 | DWORD maxLen, //length of above string
77 | DWORD index); // index, called in a loop (0...) until this fails
78 |
79 | BOOL PortAvailable(LPCTSTR portName);
80 |
81 | void GetFirstFreePort(LPSTR freePortName);
82 |
83 | /////////////////////////////////////////////////////////////////////
84 | // Dialog-box functions
85 |
86 | void FillCharCBox(CComboBox * cBox, // ptr to the CComboBox
87 | DWORD * table, // array of DWORDS for item data
88 | char ** strTable, // array for strings for items
89 | WORD tableLen, // # items in the arrays
90 | DWORD currentsetting // current selection item in the box
91 | );
92 |
93 | void FillDWordCBox(CComboBox * cBox, // ptr to the CComboBox
94 | DWORD * table, // array of DWORD values
95 | WORD tableLen, // # items in the arrays
96 | DWORD currentsetting // current selection item in the box
97 | );
98 |
99 | BOOL PortInUse(LPCTSTR portName); // return TRUE/FALSE if port is in use
100 |
101 | // Show using a "*" which ports are currently in use
102 | void FillSerialCBoxUsedResources(CComboBox * cBox, // ptr to the CComboBox
103 | LPCTSTR currentselection // current sel.
104 | );
105 |
106 | void ClearPortUseMark(LPSTR name); // remove the "*" if present from the port name
107 |
108 | BOOL LoadDATAResource(int resourceID, char **pBuffer, DWORD* resSize);
109 |
110 | BOOL FindFragment(const BYTE * buffer, DWORD length,
111 | const BYTE *pSearchBuff, DWORD mSearchLength,
112 | DWORD *pos);
113 |
114 | #endif //SIMUL_UTIL_H_INCLUDED
115 |
--------------------------------------------------------------------------------
/ModRSsim2/MemoryEditorList.h:
--------------------------------------------------------------------------------
1 | #if !defined(AFX_MEMORYEDITORLIST_H__4B373BFC_B08A_4D3C_8400_6F3BFED68E95__INCLUDED_)
2 | #define AFX_MEMORYEDITORLIST_H__4B373BFC_B08A_4D3C_8400_6F3BFED68E95__INCLUDED_
3 |
4 | #if _MSC_VER > 1000
5 | #pragma once
6 | #endif // _MSC_VER > 1000
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // FILE: MemoryEditorList.h : headder file
10 | //
11 | //
12 | // See _README.CPP
13 | //
14 | /////////////////////////////////////////////////////////////////////////////
15 |
16 | // List-Control columns are laid out as :
17 | // Address | item0..9 (registers)
18 | // Address | bit 0..15 | total (digitals)
19 | //
20 | #define NUMBER_LISTCOLS 18 // max # columns including the left-index
21 | // Moved two items below inside programm to be able to dynamically change them based on Windows version by DL on 2015-01-05
22 | // Moved third item below inside program to be able to dynamically change it based on Windows version by DL on 2015-07-15
23 | //#define WIDTH_LISTCOL1 100 // index col width (was 86 but changed for 6-digit addresses on 2014-12-29 by DL)
24 | //#define WIDTH_LISTCOLS 53 // other cols width
25 | //#define WIDTH_LISTCOLBIT 42 // if col is a bit, make it narrower (was 33 DL 2014-12-29)
26 | #define WIDTH_LISTCOLTOTAL 65 // bit "total" col width
27 |
28 |
29 | /////////////////////////////////////////////////////////////////////////////
30 | // CMemoryEditorList window
31 |
32 | class CMemoryEditorList : public CListCtrl
33 | {
34 | // Construction
35 | public:
36 | CMemoryEditorList();
37 |
38 | LRESULT GetListViewDISPINFO(LPARAM lParam);
39 |
40 | enum ListViewFormats_ {
41 | VIEWFORMAT_DECIMAL =1,
42 | VIEWFORMAT_HEX,
43 | VIEWFORMAT_WORD,
44 | VIEWFORMAT_DWORD,
45 | VIEWFORMAT_LONG,
46 | VIEWFORMAT_FLOAT, // 6 "%f"
47 | VIEWFORMAT_CHAR // text-mode
48 | };
49 |
50 | void SetupColumns(LONG width, BOOL cloneAddressing, INT ScreenWidth); // Added ScreenWidth on 2016-08-14 by DL
51 | int GetColumnCount() {return(GetHeaderCtrl()->GetItemCount());};
52 | int GetDataColumnCount();
53 |
54 | // helpers
55 | static void Format(DWORD memoryValue, ListViewFormats_ format, CString& text);
56 | static void Convert(DWORD memoryValue, ListViewFormats_ format, CString& text);
57 | static BOOL Is32BitFormat(ListViewFormats_ format);
58 |
59 | // Attributes
60 | LONG GetAreaDisplayed() {return (m_memAreaDisplayed);};
61 | WORD GetDisplayedWidth() {return (m_displayableWidth);};
62 | void SetViewFormat(ListViewFormats_ fmt) {m_viewFormat = fmt;};
63 | ListViewFormats_ GetViewFormat();
64 | LPCTSTR GetViewFormatString();
65 | LPCTSTR GetFormatName();
66 |
67 | void SetAddressFormatHex(BOOL formatHEX = TRUE) {m_addressFormatHEX = formatHEX;};
68 | BOOL IsAddressFormatHex() {return m_addressFormatHEX;};
69 | LPCTSTR GetAddressFormat() { return (m_addressFormatHEX?"%04X":"%ld");};
70 |
71 | // custom draw
72 | afx_msg void OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult );
73 |
74 | // Operations
75 | LONG SetAreaDisplayed(LONG PLCArea);
76 | WORD SetDisplayedWidth(WORD width) {m_displayableWidth=width;return (m_displayableWidth);};
77 | ListViewFormats_ SetDataViewFormat(ListViewFormats_ fmt, BOOL invalidate = TRUE) {m_viewFormat=fmt;\
78 | if ((invalidate)&&(m_hWnd)) InvalidateRect(NULL); return (m_viewFormat);};
79 |
80 | LONG m_selectedListPos[255/*MAX_MOD_MEMTYPES*/];
81 | COLORREF m_backSysColor;
82 | COLORREF m_backSysColorFade;
83 |
84 | public:
85 | // Overrides
86 | // ClassWizard generated virtual function overrides
87 | //{{AFX_VIRTUAL(CMemoryEditorList)
88 | //}}AFX_VIRTUAL
89 |
90 | // Implementation
91 | public:
92 | virtual ~CMemoryEditorList();
93 |
94 | // Generated message map functions
95 | protected:
96 | //{{AFX_MSG(CMemoryEditorList)
97 | afx_msg void OnDblclk(NMHDR* pNMHDR, LRESULT* pResult);
98 | afx_msg void OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult);
99 | //}}AFX_MSG
100 |
101 | private:
102 | LONG m_memAreaDisplayed; // index for current simulated type
103 | WORD m_displayableWidth; // # columns with data in them+ the index column
104 | ListViewFormats_ m_viewFormat;// data display format
105 | BOOL m_addressFormatHEX; // PLC addresses in Hex/Decimal?
106 | BOOL m_cloneAddressing;
107 |
108 | DECLARE_MESSAGE_MAP()
109 | };
110 |
111 | /////////////////////////////////////////////////////////////////////////////
112 |
113 | //{{AFX_INSERT_LOCATION}}
114 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
115 |
116 | #endif // !defined(AFX_MEMORYEDITORLIST_H__4B373BFC_B08A_4D3C_8400_6F3BFED68E95__INCLUDED_)
117 |
--------------------------------------------------------------------------------
/ModRSsim2/RS232Port.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: RS232Port.cpp : headder file
4 | //
5 | // See _README.CPP
6 | //
7 | // interface for the CRS232Port class.
8 | // Requires MFC headder
9 | /////////////////////////////////////////////////////////////////////////////
10 |
11 | #if !defined(AFX_RS232PORT_H__19C837A9_9EB1_408D_83F7_6D85FDEF9739__INCLUDED_)
12 | #define AFX_RS232PORT_H__19C837A9_9EB1_408D_83F7_6D85FDEF9739__INCLUDED_
13 |
14 | #if _MSC_VER > 1000
15 | #pragma once
16 | #endif // _MSC_VER > 1000
17 |
18 | extern CHAR * GetLongComPortName(LPCTSTR portName, LPSTR newName);
19 | extern CHAR * FixComPortName(CHAR *portName);
20 |
21 |
22 | #define RSPORTCURRENTLY_VOID 0
23 | #define RSPORTCURRENTLY_READING 1
24 | #define RSPORTCURRENTLY_WRITTING 2
25 | #define RSPORTCURRENTLY_CLOSING 3
26 | #define RSPORTCURRENTLY_OPENING 4
27 | #define RSPORTCURRENTLY_IDLE 5
28 |
29 |
30 | // server thread states
31 | #define RS232_EX_PENDING 0
32 | #define RS232_EX_SUSPENDED 1
33 | #define RS232_EX_RUNNING 2
34 | #define RS232_EX_TERMINATE 3
35 | #define RS232_EX_TERMINATED 4
36 |
37 |
38 | // # milliseconds to wait before discarding buffer contents
39 | #define PORT_MAX_IDLETIME 2000 //after 2 seconds, kill all chars in the buffer // 2015-01-25 by DL Changed from 10
40 |
41 | extern char commsParityStr[]; //NOPARITY ODDPARITY EVENPARITY MARKPARITY SPACEPARITY
42 | extern char commsStopStr[][4];
43 | extern char commsRTSStr[][6]; // Changed from 5 by D. Lyons on 2016-07-26
44 |
45 | extern BOOL m_SaveDebugToFile; // Save Debug Output to file flag by DL on 2015-01-10
46 | extern BOOL m_CommsTimeShow; // Added 2015-01-12 by DL to allow m_commsTimes to be used in RS232Port.cpp
47 | //extern BOOL m_CommsDecodeShow; // Added 2016-12-28 by DL to allow use here
48 | extern DWORD m_noiseLength; // 2015-02-01 by DL to know we have data for Discarding Data on Timeout
49 | extern BOOL m_longTimeouts; // 2016-10-15 by DL to get long timeout value
50 |
51 | class CRS232Port : public CObject
52 | {
53 | public:
54 |
55 | DECLARE_DYNAMIC(CRS232Port)
56 |
57 | CRS232Port();
58 | virtual ~CRS232Port();
59 |
60 | BOOL OpenPort(LPCTSTR oPortName);
61 | BOOL ConfigurePort(DWORD baud,
62 | DWORD byteSize,
63 | DWORD parity,
64 | DWORD stopBits,
65 | DWORD rts,
66 | DWORD checkParity=TRUE,
67 | DWORD longTimeout=FALSE);
68 | BOOL ClosePort();
69 |
70 | BOOL Purge();
71 | LONG Receive(DWORD *numberOfBytesRead, CHAR* bufferPtr, CHAR* debugStrPtr);
72 | LONG Send(int numberOfBytestoWrite, const BYTE* bufferPtr, CHAR* debugStrPtr);
73 | void UpdateModemStatus();
74 |
75 | // user must derive from this class and override this method.
76 | // virtual BOOL ProcessData(const CHAR *pBuffer, DWORD numBytes) = NULL;
77 | virtual void OnHWError(DWORD dwCommError);
78 | virtual BOOL OnProcessData(const CHAR *pBuffer, DWORD numBytes, BOOL *discardData) = NULL;
79 |
80 | // overridable notification functions
81 | virtual void RSStateChanged(DWORD state);
82 | virtual void RSDataDebugger(const BYTE * buffer, LONG length, BOOL transmit) = NULL;
83 | virtual void RSDataMessage(LPCTSTR msg) = NULL;
84 | virtual void RSModemStatus(DWORD status) = NULL;
85 |
86 | void Poll(CHAR * debugStr);
87 | UINT friend AsyncFriend(LPVOID pParam);
88 |
89 | // static members which implement some debugger Ceneric methods
90 | static void GenDataDebugger(const BYTE * buffer, LONG length, BOOL transmit);
91 | static bool CRS232Port::WriteToFile(CString str);
92 |
93 | BOOL ReConfigurePort();
94 |
95 | // diagnostic
96 | #ifdef _DEBUG
97 | VOID Dump(CDumpContext& dc) const;
98 | #endif
99 |
100 | public:
101 | CString portNameS; // short (display) port name
102 | CEvent m_threadStartupEvent;
103 | CEvent m_threadDeadEvent;
104 | CWinThread * m_pWorkerThread;
105 |
106 | DWORD m_debuggerStep;
107 | HANDLE h232Port; // a handle
108 | DWORD m_listenThreadStatus;
109 | BOOL m_masterHasWork; // if TRUE, then do not RX
110 | BOOL keepPolling;
111 | DWORD m_lastCharIncommingtime;
112 |
113 | private:
114 | CRITICAL_SECTION critSec; //sync object for this class
115 | CString portName; // long port name
116 | DCB dcb; // settings Device context block
117 | DWORD m_lastModemStatus;
118 |
119 | BYTE rxBuffer[1024]; //keep space for up to 2 messages
120 | DWORD rxBufferIndex; // index to past last usable byte (is also the length)
121 | };
122 |
123 |
124 |
125 | #endif // !defined(AFX_RS232PORT_H__19C837A9_9EB1_408D_83F7_6D85FDEF9739__INCLUDED_)
126 |
--------------------------------------------------------------------------------
/ModRSsim2/MicroTick.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: MicroTick.h : headder file
4 | //
5 | // See _README.CPP
6 | //
7 | // Defines a class derieved from CButton, it is a specialized check-box
8 | // that uses colours and displays "text" inside the tick area, making it
9 | // smaller that a check-box. This is great if you have screen real-estate
10 | // limitations.
11 | // Works almost exactly like a tick-box.
12 | //
13 | // Fixes: Border box drawn correctly (and within client rect)
14 | // colors change-able
15 | // There are 6 colors to supply:
16 | //
17 | // background text border
18 | // +---------------+-------------------+-----------------------+-------------------+
19 | // | tick marked | SetCheckedColor | SetTextColor | |
20 | // | tick cleared | SetUncheckedColor | SetUncheckedTextColor | |
21 | // | activity | | | SetActiveColor |
22 | // | no activity | | | SetInactiveColor |
23 | // +---------------+-------------------+-----------------------+-------------------+
24 | // The border is a non-user accessible GUI driver by the program to show internal
25 | // status, in our case to show activity.
26 | //
27 | /////////////////////////////////////////////////////////////////////////////
28 | #if !defined(AFX_MICROTICK_H__51526765_6F63_11D3_B17D_00A0248E2104__INCLUDED_)
29 | #define AFX_MICROTICK_H__51526765_6F63_11D3_B17D_00A0248E2104__INCLUDED_
30 |
31 | #if _MSC_VER >= 1000
32 | #pragma once
33 | #endif // _MSC_VER >= 1000
34 |
35 | /////////////////////////////////////////////////////////////////////////////
36 | // CMicroTick window
37 |
38 | class CMicroTick : public CButton
39 | {
40 | // Construction
41 | public:
42 | CMicroTick();
43 | virtual ~CMicroTick();
44 |
45 | // Operations
46 | public:
47 | ////////////////////////////////////////////////////////////
48 | // text color
49 | void SetTextColor(COLORREF color) {m_textColor=color;};
50 | void SetUnCheckedTextColor(COLORREF color) {m_uncheckedTextColor=color;};
51 | // border
52 | void SetBorderWidth(int width) { m_borderWidth=width;};
53 | void SetBorderState(BOOL active) {m_backgroundState = active;};
54 | BOOL GetBorderState() {return(m_backgroundState);};
55 |
56 | // check-box state members
57 | void SetCheck(int nCheck);
58 | void SetCheckedColor(COLORREF color) {m_checked=color;\
59 | InvalidateRect(NULL);};
60 | void SetUnCheckedColor(COLORREF color) {m_unchecked=color;\
61 | InvalidateRect(NULL);};
62 | int GetCheck();
63 | COLORREF GetCheckedColor() {return(m_checked);};
64 | COLORREF GetUnCheckedColor() {return(m_unchecked);};
65 |
66 | // background members
67 | void SetActiveColor(COLORREF color) {m_backgroundActive=color;\
68 | InvalidateRect(NULL);};
69 | void SetInactiveColor(COLORREF color) {m_backgroundInActive=color;\
70 | InvalidateRect(NULL);};
71 |
72 | COLORREF GetActiveColor() {return(m_backgroundActive);};
73 | COLORREF GetInactiveColor() {return(m_backgroundInActive);};
74 |
75 | private:
76 | // tick-box members
77 | DWORD m_microTickState; // checked state
78 | COLORREF m_unchecked; // unchecked color
79 | COLORREF m_checked; // checked color
80 |
81 | // border members
82 | DWORD m_borderWidth; // border width
83 | DWORD m_backgroundState; // border on/off
84 | COLORREF m_backgroundInActive; // idle color
85 | COLORREF m_backgroundActive; // active color
86 |
87 | // text colors
88 | COLORREF m_textColor; // normal text color
89 | COLORREF m_uncheckedTextColor; // text color for in un-checked state
90 |
91 | // Overrides
92 | // ClassWizard generated virtual function overrides
93 | //{{AFX_VIRTUAL(CMicroTick)
94 | public:
95 | virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
96 | protected:
97 | virtual void PreSubclassWindow();
98 | //}}AFX_VIRTUAL
99 | private:
100 | CFont *m_pFont;
101 |
102 | // Generated message map functions
103 | protected:
104 | //{{AFX_MSG(CMicroTick)
105 | afx_msg void OnPaint();
106 | afx_msg BOOL OnEraseBkgnd(CDC* pDC);
107 | afx_msg void OnClicked();
108 | afx_msg void OnSetFocus(CWnd* pOldWnd);
109 | //}}AFX_MSG
110 |
111 | DECLARE_MESSAGE_MAP()
112 | };
113 |
114 | /////////////////////////////////////////////////////////////////////////////
115 |
116 | //{{AFX_INSERT_LOCATION}}
117 | // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
118 |
119 | #endif // !defined(AFX_MICROTICK_H__51526765_6F63_11D3_B17D_00A0248E2104__INCLUDED_)
120 |
--------------------------------------------------------------------------------
/mylib/MicroTick.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: MicroTick.h : headder file
4 | //
5 | // See _README.CPP
6 | //
7 | // Defines a class derieved from CButton, it is a specialized check-box
8 | // that uses colours and displays "text" inside the tick area, making it
9 | // smaller that a check-box. This is great if you have screen real-estate
10 | // limitations.
11 | // Works almost exactly like a tick-box.
12 | //
13 | // Fixes: Border box drawn correctly (and within client rect)
14 | // colors change-able
15 | // There are 6 colors to supply:
16 | //
17 | // background text border
18 | // +---------------+-------------------+-----------------------+-------------------+
19 | // | tick marked | SetCheckedColor | SetTextColor | |
20 | // | tick cleared | SetUncheckedColor | SetUncheckedTextColor | |
21 | // | activity | | | SetActiveColor |
22 | // | no activity | | | SetInactiveColor |
23 | // +---------------+-------------------+-----------------------+-------------------+
24 | // The border is a non-user accessible GUI driver by the program to show internal
25 | // status, in our case to show activity.
26 | //
27 | /////////////////////////////////////////////////////////////////////////////
28 | #if !defined(AFX_MICROTICK_H__51526765_6F63_11D3_B17D_00A0248E2104__INCLUDED_)
29 | #define AFX_MICROTICK_H__51526765_6F63_11D3_B17D_00A0248E2104__INCLUDED_
30 |
31 | #if _MSC_VER >= 1000
32 | #pragma once
33 | #endif // _MSC_VER >= 1000
34 |
35 | /////////////////////////////////////////////////////////////////////////////
36 | // CMicroTick window
37 |
38 | class CMicroTick : public CButton
39 | {
40 | // Construction
41 | public:
42 | CMicroTick();
43 | virtual ~CMicroTick();
44 |
45 | // Operations
46 | public:
47 | ////////////////////////////////////////////////////////////
48 | // text color
49 | void SetTextColor(COLORREF color) {m_textColor=color;};
50 | void SetUnCheckedTextColor(COLORREF color) {m_uncheckedTextColor=color;};
51 | // border
52 | void SetBorderWidth(int width) { m_borderWidth=width;};
53 | void SetBorderState(BOOL active) {m_backgroundState = active;};
54 | BOOL GetBorderState() {return(m_backgroundState);};
55 |
56 | // check-box state members
57 | void SetCheck(int nCheck);
58 | void SetCheckedColor(COLORREF color) {m_checked=color;\
59 | InvalidateRect(NULL);};
60 | void SetUnCheckedColor(COLORREF color) {m_unchecked=color;\
61 | InvalidateRect(NULL);};
62 | int GetCheck();
63 | COLORREF GetCheckedColor() {return(m_checked);};
64 | COLORREF GetUnCheckedColor() {return(m_unchecked);};
65 |
66 | // background members
67 | void SetActiveColor(COLORREF color) {m_backgroundActive=color;\
68 | InvalidateRect(NULL);};
69 | void SetInactiveColor(COLORREF color) {m_backgroundInActive=color;\
70 | InvalidateRect(NULL);};
71 |
72 | COLORREF GetActiveColor() {return(m_backgroundActive);};
73 | COLORREF GetInactiveColor() {return(m_backgroundInActive);};
74 |
75 | private:
76 | // tick-box members
77 | DWORD m_microTickState; // checked state
78 | COLORREF m_unchecked; // unchecked color
79 | COLORREF m_checked; // checked color
80 |
81 | // border members
82 | DWORD m_borderWidth; // border width
83 | DWORD m_backgroundState; // border on/off
84 | COLORREF m_backgroundInActive; // idle color
85 | COLORREF m_backgroundActive; // active color
86 |
87 | // text colors
88 | COLORREF m_textColor; // normal text color
89 | COLORREF m_uncheckedTextColor; // text color for in un-checked state
90 |
91 | // Overrides
92 | // ClassWizard generated virtual function overrides
93 | //{{AFX_VIRTUAL(CMicroTick)
94 | public:
95 | virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
96 | protected:
97 | virtual void PreSubclassWindow();
98 | //}}AFX_VIRTUAL
99 | private:
100 | CFont *m_pFont;
101 |
102 | // Generated message map functions
103 | protected:
104 | //{{AFX_MSG(CMicroTick)
105 | afx_msg void OnPaint();
106 | afx_msg BOOL OnEraseBkgnd(CDC* pDC);
107 | afx_msg void OnClicked();
108 | afx_msg void OnSetFocus(CWnd* pOldWnd);
109 | //}}AFX_MSG
110 |
111 | DECLARE_MESSAGE_MAP()
112 | };
113 |
114 | /////////////////////////////////////////////////////////////////////////////
115 |
116 | //{{AFX_INSERT_LOCATION}}
117 | // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
118 |
119 | #endif // !defined(AFX_MICROTICK_H__51526765_6F63_11D3_B17D_00A0248E2104__INCLUDED_)
120 |
--------------------------------------------------------------------------------
/ModRSsim2/CommsLamp.cpp:
--------------------------------------------------------------------------------
1 | // CommsLamp.cpp : implementation file
2 | //
3 |
4 | #include "stdafx.h"
5 | #include "CommsLamp.h"
6 |
7 | #ifdef _DEBUG
8 | #define new DEBUG_NEW
9 | #undef THIS_FILE
10 | static char THIS_FILE[] = __FILE__;
11 | #endif
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 | // CCommsLamp
15 |
16 | CCommsLamp::CCommsLamp()
17 | {
18 | m_state = FALSE;
19 | m_ONcolor = RGB(255,0,0);
20 | m_OFFcolor = RGB(190,0,0);
21 | m_timerDuration = 0; // no timer
22 | }
23 |
24 | CCommsLamp::~CCommsLamp()
25 | {
26 |
27 | }
28 |
29 | // ------------------------------- UpdateMyCtrl ----------------------------
30 | void CCommsLamp::UpdateMyCtrl()
31 | {
32 | // does control RECT invalidation, maybe more in future
33 | InvalidateRect(NULL);
34 | }
35 |
36 | // ---------------------------- SetupLamp --------------------------
37 | // a value of 0 kills the timer
38 | BOOL CCommsLamp::SetupLamp(DWORD onTimerDuration)
39 | {
40 | if (m_timerDuration)
41 | {
42 | // kill a timer already in existence
43 | KillTimer(m_timerID);
44 | m_timerDuration = 0;
45 | }
46 |
47 | if (onTimerDuration)
48 | {
49 | // set up a timer
50 | m_timerID = SetTimer(1, onTimerDuration, NULL);
51 | if (m_timerID)
52 | {
53 | m_timerDuration = onTimerDuration;
54 | return TRUE;
55 | }
56 | }
57 | else
58 | return TRUE;
59 | return FALSE;
60 | }
61 |
62 | BEGIN_MESSAGE_MAP(CCommsLamp, CButton)
63 | //{{AFX_MSG_MAP(CCommsLamp)
64 | ON_WM_PAINT()
65 | ON_WM_DESTROY()
66 | ON_WM_TIMER()
67 | //}}AFX_MSG_MAP
68 | END_MESSAGE_MAP()
69 |
70 | /////////////////////////////////////////////////////////////////////////////
71 | // CCommsLamp message handlers
72 |
73 | // Do not call CStatic::OnPaint() for painting messages
74 | void CCommsLamp::OnPaint()
75 | {
76 | CBrush darkBrush; // background bit
77 | CPen borderPen; // silver/gray border
78 | CBrush lightBrush; // lighter spot
79 | CPen lightPen; // light reflective area
80 | CPen boxPen;
81 |
82 | COLORREF mainColor;
83 |
84 |
85 | CPaintDC dc(this); // device context for painting
86 |
87 | // TODO: Add your message handler code here
88 | CRect rcClient;
89 | GetClientRect(&rcClient);
90 |
91 | // square off our drawing rectangle, base-
92 | // class is hopefully going to paint our background properly
93 | if (rcClient.Width() > rcClient.Height())
94 | rcClient.right = rcClient.bottom;
95 | else
96 | rcClient.bottom = rcClient.right;
97 |
98 | if (m_state)
99 | mainColor = m_ONcolor;
100 | else
101 | mainColor = m_OFFcolor;
102 | // Set up all create all pens and brushes
103 | lightPen.CreatePen(PS_SOLID,1,mainColor);
104 | boxPen.CreatePen(PS_SOLID,1, RGB(0,255,0));
105 | darkBrush.CreateSolidBrush(RGB(GetRValue(mainColor)/2, GetGValue(mainColor)/2,GetBValue(mainColor)/2));
106 | lightBrush.CreateSolidBrush(mainColor);
107 |
108 | borderPen.CreatePen(PS_SOLID,1, RGB(255,255,255));
109 | //borderPen.CreatePen(PS_SOLID,2, RGB(0,255,0));
110 |
111 | // a debugging box
112 | //dc.SelectObject(&boxPen);
113 | //dc.Rectangle(rcClient);
114 |
115 | // start, with the darker background bit
116 | dc.SelectObject(&borderPen);
117 | dc.SelectObject(&darkBrush);
118 | dc.Ellipse(rcClient);
119 |
120 | // draw the inner shiny bit
121 | rcClient.DeflateRect(2,2);
122 | dc.SelectObject(&lightPen);
123 | dc.SelectObject(&lightBrush);
124 | dc.Ellipse(rcClient);
125 |
126 | //rcClient.DeflateRect(-3,-3);
127 |
128 | if (m_state)
129 | {
130 | // The arc function is just to add a 3D effect for the control
131 | dc.SelectStockObject(WHITE_PEN);
132 | CPoint ptStart,ptEnd;
133 | ptStart = CPoint(rcClient.Width()/2,rcClient.bottom);
134 | ptEnd = CPoint(rcClient.right,rcClient.top);
135 |
136 | dc.MoveTo(ptStart);
137 | dc.Arc(rcClient,ptStart,ptEnd);
138 | }
139 | // select old object back into the DC
140 | //dc.SelectObject(pOldPen);
141 |
142 | }
143 |
144 | void CCommsLamp::OnDestroy()
145 | {
146 | CButton::OnDestroy();
147 |
148 | // TODO: Add your message handler code here
149 | if (m_hWnd && m_timerDuration)
150 | {
151 | KillTimer(m_timerID);
152 | }
153 | }
154 |
155 | // ---------------------------- OnTimer ------------------------------
156 | void CCommsLamp::OnTimer(UINT nIDEvent)
157 | {
158 | // TODO: Add your message handler code here and/or call default
159 | if (m_timerDuration && (m_timerID==nIDEvent))
160 | {
161 | // turn LED off
162 | if (m_state)
163 | SetState(FALSE);
164 | }
165 |
166 | CButton::OnTimer(nIDEvent);
167 | }
168 |
169 | // ---------------------------- SetState --------------------------------
170 | void CCommsLamp::SetState(BOOL state)
171 | {
172 | if (state != m_state)
173 | {
174 | m_state = state;
175 | UpdateMyCtrl();
176 | }
177 | }
178 |
179 |
180 | void CCommsLamp::PreSubclassWindow()
181 | {
182 | // TODO: Add your specialized code here and/or call the base class
183 | SetButtonStyle(GetButtonStyle() | BS_OWNERDRAW | BS_AUTOCHECKBOX);
184 |
185 | CButton::PreSubclassWindow();
186 | }
187 |
188 | void CCommsLamp::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
189 | {
190 | // TODO: Add your code to draw the specified item
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/mylib/CommsLamp.cpp:
--------------------------------------------------------------------------------
1 | // CommsLamp.cpp : implementation file
2 | //
3 |
4 | #include "stdafx.h"
5 | //#include "CommsLamp.h"
6 |
7 | #ifdef _DEBUG
8 | #define new DEBUG_NEW
9 | #undef THIS_FILE
10 | static char THIS_FILE[] = __FILE__;
11 | #endif
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 | // CCommsLamp
15 |
16 | CCommsLamp::CCommsLamp()
17 | {
18 | m_state = FALSE;
19 | m_ONcolor = RGB(255,0,0);
20 | m_OFFcolor = RGB(190,0,0);
21 | m_timerDuration = 0; // no timer
22 | }
23 |
24 | CCommsLamp::~CCommsLamp()
25 | {
26 |
27 | }
28 |
29 | // ------------------------------- UpdateMyCtrl ----------------------------
30 | void CCommsLamp::UpdateMyCtrl()
31 | {
32 | // does control RECT invalidation, maybe more in future
33 | InvalidateRect(NULL);
34 | }
35 |
36 | // ---------------------------- SetupLamp --------------------------
37 | // a value of 0 kills the timer
38 | BOOL CCommsLamp::SetupLamp(DWORD onTimerDuration)
39 | {
40 | if (m_timerDuration)
41 | {
42 | // kill a timer already in existence
43 | KillTimer(m_timerID);
44 | m_timerDuration = 0;
45 | }
46 |
47 | if (onTimerDuration)
48 | {
49 | // set up a timer
50 | m_timerID = SetTimer(1, onTimerDuration, NULL);
51 | if (m_timerID)
52 | {
53 | m_timerDuration = onTimerDuration;
54 | return TRUE;
55 | }
56 | }
57 | else
58 | return TRUE;
59 | return FALSE;
60 | }
61 |
62 | BEGIN_MESSAGE_MAP(CCommsLamp, CButton)
63 | //{{AFX_MSG_MAP(CCommsLamp)
64 | ON_WM_PAINT()
65 | ON_WM_DESTROY()
66 | ON_WM_TIMER()
67 | //}}AFX_MSG_MAP
68 | END_MESSAGE_MAP()
69 |
70 | /////////////////////////////////////////////////////////////////////////////
71 | // CCommsLamp message handlers
72 |
73 | // Do not call CStatic::OnPaint() for painting messages
74 | void CCommsLamp::OnPaint()
75 | {
76 | CBrush darkBrush; // background bit
77 | CPen borderPen; // silver/gray border
78 | CBrush lightBrush; // lighter spot
79 | CPen lightPen; // light reflective area
80 | CPen boxPen;
81 |
82 | COLORREF mainColor;
83 |
84 |
85 | CPaintDC dc(this); // device context for painting
86 |
87 | // TODO: Add your message handler code here
88 | CRect rcClient;
89 | GetClientRect(&rcClient);
90 |
91 | // square off our drawing rectangle, base-
92 | // class is hopefully going to paint our background properly
93 | if (rcClient.Width() > rcClient.Height())
94 | rcClient.right = rcClient.bottom;
95 | else
96 | rcClient.bottom = rcClient.right;
97 |
98 | if (m_state)
99 | mainColor = m_ONcolor;
100 | else
101 | mainColor = m_OFFcolor;
102 | // Set up all create all pens and brushes
103 | lightPen.CreatePen(PS_SOLID,1,mainColor);
104 | boxPen.CreatePen(PS_SOLID,1, RGB(0,255,0));
105 | darkBrush.CreateSolidBrush(RGB(GetRValue(mainColor)/2, GetGValue(mainColor)/2,GetBValue(mainColor)/2));
106 | lightBrush.CreateSolidBrush(mainColor);
107 |
108 | borderPen.CreatePen(PS_SOLID,1, RGB(255,255,255));
109 | //borderPen.CreatePen(PS_SOLID,2, RGB(0,255,0));
110 |
111 | // a debugging box
112 | //dc.SelectObject(&boxPen);
113 | //dc.Rectangle(rcClient);
114 |
115 | // start, with the darker background bit
116 | dc.SelectObject(&borderPen);
117 | dc.SelectObject(&darkBrush);
118 | dc.Ellipse(rcClient);
119 |
120 | // draw the inner shiny bit
121 | rcClient.DeflateRect(2,2);
122 | dc.SelectObject(&lightPen);
123 | dc.SelectObject(&lightBrush);
124 | dc.Ellipse(rcClient);
125 |
126 | //rcClient.DeflateRect(-3,-3);
127 |
128 | if (m_state)
129 | {
130 | // The arc function is just to add a 3D effect for the control
131 | dc.SelectStockObject(WHITE_PEN);
132 | CPoint ptStart,ptEnd;
133 | ptStart = CPoint(rcClient.Width()/2,rcClient.bottom);
134 | ptEnd = CPoint(rcClient.right,rcClient.top);
135 |
136 | dc.MoveTo(ptStart);
137 | dc.Arc(rcClient,ptStart,ptEnd);
138 | }
139 | // select old object back into the DC
140 | //dc.SelectObject(pOldPen);
141 |
142 | }
143 |
144 | void CCommsLamp::OnDestroy()
145 | {
146 | CButton::OnDestroy();
147 |
148 | // TODO: Add your message handler code here
149 | if (m_hWnd && m_timerDuration)
150 | {
151 | KillTimer(m_timerID);
152 | }
153 | }
154 |
155 | // ---------------------------- OnTimer ------------------------------
156 | void CCommsLamp::OnTimer(UINT nIDEvent)
157 | {
158 | // TODO: Add your message handler code here and/or call default
159 | if (m_timerDuration && (m_timerID==nIDEvent))
160 | {
161 | // turn LED off
162 | if (m_state)
163 | SetState(FALSE);
164 | }
165 |
166 | CButton::OnTimer(nIDEvent);
167 | }
168 |
169 | // ---------------------------- SetState --------------------------------
170 | void CCommsLamp::SetState(BOOL state)
171 | {
172 | if (state != m_state)
173 | {
174 | m_state = state;
175 | UpdateMyCtrl();
176 | }
177 | }
178 |
179 | // ------------------------ PreSubclassWindow --------------------------
180 | void CCommsLamp::PreSubclassWindow()
181 | {
182 | // TODO: Add your specialized code here and/or call the base class
183 | SetButtonStyle(GetButtonStyle() | BS_OWNERDRAW | BS_AUTOCHECKBOX);
184 |
185 | CButton::PreSubclassWindow();
186 | }
187 |
188 | // -------------------------- DrawItem ---------------------------------
189 | void CCommsLamp::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
190 | {
191 | // TODO: Add your code to draw the specified item
192 |
193 | // do nothing, we have to do this.
194 | }
195 |
--------------------------------------------------------------------------------
/ModRSsim2/SimCmdLine.cpp:
--------------------------------------------------------------------------------
1 | // SimCmdLine.cpp: implementation of the CSimCmdLine class.
2 | //
3 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
4 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU Affero General Public License as
8 | // published by the Free Software Foundation, either version 3 of the
9 | // License, or (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Affero General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Affero General Public License
17 | // along with this program. If not, see .
18 | //
19 | //////////////////////////////////////////////////////////////////////
20 |
21 | #include "stdafx.h"
22 | #include "mod_rssim.h"
23 | #include "SimCmdLine.h"
24 |
25 | #ifdef _DEBUG
26 | #undef THIS_FILE
27 | static char THIS_FILE[]=__FILE__;
28 | #define new DEBUG_NEW
29 | #endif
30 |
31 | //////////////////////////////////////////////////////////////////////
32 | // Construction/Destruction
33 | //////////////////////////////////////////////////////////////////////
34 |
35 | CSimCmdLine::CSimCmdLine()
36 | {
37 | // m_parity =-1;
38 | // m_byte = 0;
39 | // m_stop = -1;
40 | // m_rts = -1;
41 | m_baud = 0;
42 | m_protocol = -1;
43 | m_ipPort = -1;
44 | m_SerialControls = FALSE;
45 | }
46 |
47 | CSimCmdLine::~CSimCmdLine()
48 | {
49 |
50 | }
51 |
52 |
53 | void CSimCmdLine::ParseParam( LPCTSTR lpszParam, BOOL bFlag, BOOL bLast )
54 | {
55 | CString paramUp(lpszParam);
56 | CString dcbTok[] = {
57 | "BAUD",
58 | "PARITY",
59 | "DATA",
60 | "STOP",
61 | "RTS",
62 | ""
63 | };
64 |
65 | paramUp.MakeUpper(); // now check for protocol selection
66 | if (0==strncmp("MODTCP", paramUp, 6))
67 | {
68 | m_protocol = PROTOCOL_SELMODETH;
69 | sscanf_s(paramUp.Mid(7), "%d", &m_ipPort);
70 | }
71 | if (0==strcmp("MODRTU", paramUp))
72 | {
73 | m_protocol = PROTOCOL_SELMOD232;
74 | }
75 | if (0==strcmp("ABSLAVE", paramUp))
76 | {
77 | m_protocol = PROTOCOL_SELAB232;
78 | }
79 | if (0==strcmp("ABMASTER", paramUp))
80 | {
81 | m_protocol = PROTOCOL_SELABMASTER232;
82 | }
83 |
84 | // check for port name
85 | if (0==strncmp("PORT:", paramUp,5))
86 | {
87 | m_portName = paramUp.Mid(5);
88 | m_DCBParams += m_portName;
89 | m_DCBParams += ": ";
90 | }
91 |
92 | // check commDCB parameters 'baud=1200 parity=N data=8 stop=1 ' or '96,n,8,1,p' style
93 | bool dcbAdd = FALSE;
94 | int index(0);
95 | while (dcbTok[index].GetLength())
96 | {
97 | if (0==strncmp(dcbTok[index], paramUp ,dcbTok[index].GetLength()) )
98 | dcbAdd = TRUE;
99 | index++;
100 | }
101 | if (0<= paramUp.Find(',')) // the ,,,,p style
102 | dcbAdd = TRUE;
103 |
104 | if (dcbAdd)
105 | {
106 | m_SerialControls = TRUE;
107 | m_DCBParams += lpszParam;
108 | m_DCBParams += " ";
109 | }
110 |
111 | if ((bLast) && m_SerialControls)
112 | { // copy all DCB results into the parameters
113 |
114 | ASSERT( m_baud != 0); // user failed to call SetPortParams()
115 | m_dcbBlock.BaudRate = m_baud;
116 | m_dcbBlock.ByteSize = (BYTE)m_byte;
117 | m_dcbBlock.Parity = (BYTE)m_parity;
118 | m_dcbBlock.StopBits = (BYTE)m_stop;
119 | m_dcbBlock.fRtsControl = m_rts;
120 | if (!BuildCommDCB(m_DCBParams, &m_dcbBlock))
121 | {
122 | // parsing error!
123 | AfxMessageBox("Error: commandline MODE parameters were invalid");
124 | m_SerialControls = FALSE;
125 | }
126 | m_baud = m_dcbBlock.BaudRate;
127 | m_byte = m_dcbBlock.ByteSize;
128 | m_parity = m_dcbBlock.Parity;
129 | m_stop = m_dcbBlock.StopBits;
130 | m_rts = m_dcbBlock.fRtsControl;
131 | }
132 | }
133 |
134 | bool CSimCmdLine::GetPortSettings(char aPortName[MAX_COMPORT_NAME],
135 | DWORD &aBaudRate,
136 | DWORD &aByteSize,
137 | DWORD &aParity,
138 | DWORD & aStop,
139 | DWORD &aRTS)
140 | {
141 | if (m_portName.GetLength() )
142 | {
143 | strncpy_s(aPortName , MAX_COMPORT_NAME, m_portName, MAX_COMPORT_NAME);
144 | aBaudRate = m_baud;
145 | aByteSize = m_byte;
146 | aParity = m_parity;
147 | aStop = m_stop;
148 | aRTS = m_rts;
149 | return(TRUE);
150 | }
151 | return(FALSE);
152 | }
153 |
154 | bool CSimCmdLine::GetProtocol(DWORD &aProtocol)
155 | {
156 | if (m_protocol != -1)
157 | {
158 | aProtocol = m_protocol;
159 | return(TRUE);
160 | }
161 | return(FALSE);
162 | }
163 |
164 |
165 | bool CSimCmdLine::GetIPSettings(DWORD &aPort)
166 | {
167 | if (m_ipPort != -1)
168 | {
169 | aPort = m_ipPort;
170 | return(TRUE);
171 | }
172 | return(FALSE);
173 | }
174 |
175 | void CSimCmdLine::SetPortParams ( const DWORD &aBaudRate,
176 | const DWORD &aByteSize,
177 | const DWORD &aParity,
178 | const DWORD & aStop,
179 | const DWORD &aRTS)
180 | {
181 | m_baud = aBaudRate;
182 | m_byte = aByteSize;
183 | m_parity = aParity ;
184 | m_stop = aStop ;
185 | m_rts = aRTS ;
186 | }
--------------------------------------------------------------------------------
/ModRSsim2/message.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: Message.h : headder file
4 | //
5 | //
6 | /////////////////////////////////////////////////////////////////////////////
7 |
8 | #ifndef MESSAGE_H_HEADDER_FILE
9 | #define MESSAGE_H_HEADDER_FILE
10 |
11 | #define MAX_RX_MESSAGELENGTH 4096 // a big buffer
12 | #define AB_FRAME_LENGTH_MAX 236 // max bytes of data
13 |
14 | // protocol specific macros etc here
15 | #define ALLENBRADLEY_STX 0x02
16 | #define ALLENBRADLEY_ETX 0x03
17 | #define ALLENBRADLEY_SOH 0x01
18 | #define ALLENBRADLEY_ENQ 0x05
19 | #define ALLENBRADLEY_ACK 0x06
20 | #define ALLENBRADLEY_DLE 0x10
21 | #define ALLENBRADLEY_NAK 0x15 // disputed 0x0F
22 |
23 | #define SIZEOF_TAIL 2
24 | #define MIN_PLC_FILE 3 // Extended File Registers Blocks
25 | #define MAX_PLC_FILE 255
26 |
27 | #define ALLENBRADLEY_SLC_CMD 0x0F // SLC compatible command
28 | #define ALLENBRADLEY_PLC3_LOGICAL_ADDRESS_INDICATOR 0x2C // For PLC3 ascii addressing
29 | #define ALLENBRADLEY_BIT_WRITE 0x02 // Non priveleged commands
30 | #define ALLENBRADLEY_WORD_READ 0xA2 // 0x01
31 | #define ALLENBRADLEY_WORD_WRITE 0xAA // 0x00
32 | #define ALLENBRADLEY_LOGIC_ADDRESS_DELIMITER 0xFF
33 |
34 | #define AB_STS_NOERROR 0x00 //
35 | #define AB_STS_ILLEGALCMD 0x10 // all errors > 8 have EXT-STS bytes
36 |
37 | #define AB_EXTSTS_ILLEGALFIELDVALUE 0x01
38 | #define AB_EXTSTS_CANNOTEXECUTE 0x0E
39 | #define AB_EXTSTS_ILLEGALTYPE 0x11
40 |
41 | // zero-based telegram offsets for bytes in the MSG headder
42 | #define AB_SOURCEBYTEOFF 2
43 | #define AB_DESTINATIONBYTEOFF 3
44 | #define AB_COMMANDBYTEOFF 4
45 | #define AB_STATUSBYTEOFF 5
46 | #define AB_TNSBYTEOFF 6
47 | #define AB_FUNCBYTEOFF 8
48 | #define AB_LENGTHFRAMEOFF 9
49 |
50 |
51 | // Global - Global data
52 | extern BYTE txDLE_STX[SIZEOF_TAIL];
53 | extern BYTE txDLE_ACK[SIZEOF_TAIL];
54 | extern BYTE txDLE_NAK[SIZEOF_TAIL];
55 | extern BYTE txDLE_ETX[SIZEOF_TAIL];
56 | extern BYTE txDLE_ENQ[SIZEOF_TAIL];
57 |
58 | extern BYTE CalcBCC(BYTE * lrcBuffPtr, // -> pointer to buffer at start of BCC
59 | DWORD buffLen // ->
60 | );
61 |
62 | extern LONG CalcMODBUSCRC( BYTE * crcStartPtr, // ->
63 | DWORD buffLen, // ->
64 | WORD * crc // <->
65 | );
66 |
67 |
68 |
69 | // ----------------------------------------------------------------------
70 | // class CProtocolMessage declares the BASE protocol frame.
71 | //
72 | class CProtocolMessage : public CObject
73 | {
74 | public:
75 | CProtocolMessage(const BYTE * pMessageRX, DWORD len);
76 | CProtocolMessage(const CProtocolMessage & oldProtMessage); //copy constructor
77 |
78 | BOOL CRCOK() { return (crcCheckedOK);};
79 | static LONG StripDLEs(CHAR *bufferPtr, DWORD *numBytes);
80 |
81 | protected:
82 | BOOL crcCheckedOK;
83 | };
84 |
85 | // ----------------------------------------------------------------------
86 | // class CABMessage declares a Allen-Bradley Full-duplex protocol frame.
87 | //
88 | // message format is:
89 | // ===============================
90 | // DLE STX DST SRC CMD STS TNS TNS FNC SIZ FIL TYP ELE ELS DAT DAT DLE ETX CRC CRC
91 | // 10 02 05 01 0F 00 3E 00 AA 02 0A 89 00 00 3F 00 10 03 D8 0F
92 | //
93 | // FNC - A2 = typed logical read
94 | // - AA = typed logical write (3 address fields)
95 | // SIZ = size in bytes
96 | // FIL = file #
97 | // TYP - 89 = Integer file.
98 | // ELE = element
99 | // ELS = sub-element
100 | // DAT = data
101 | // DAT = data
102 | //
103 | // The correct response format is:
104 | //
105 | // DLE STX SRC DST CMD STS TNS TNS EXT-STS DLE ETX CRC CRC
106 | // 10 02 01 05 4F 00 00 AA 00 10 03 xx xx
107 | // CMD is +40H
108 | //
109 | // CRC is calculated from the SRC/DEST thru to the DLE-ETX
110 | //
111 | class CABMessage : public CProtocolMessage
112 | {
113 | public:
114 | CABMessage(const BYTE * pMessageRX, DWORD len, BOOL dataLayer = TRUE);
115 | CABMessage(const CABMessage & oldABMessage); //copy constructor to assist in building the response message!
116 |
117 | BYTE m_localStationID; // our station #
118 |
119 | BYTE stationIDSource; // MSG source station #
120 | BYTE stationIDDest; // MSG station # the message is sent to
121 | BYTE functionCode;
122 | BYTE command;
123 | BYTE transmissionStatus; // STS byte
124 | WORD transactionID;
125 | BYTE transmissionStatusEXT; // Extended STS byte
126 |
127 | WORD fileType; //
128 | WORD fileNum; // file #
129 | WORD address;
130 | WORD subElement;
131 | WORD count; // # of data words?
132 | WORD overalLen; // telegram data length
133 | WORD byteCount; // # of items, (if In/Outputs), then it is the # of bits.
134 | WORD totalLen;
135 |
136 | WORD appLength; // length of the application data (minus the ENQ, "TAIL" and CRC)
137 |
138 | CHAR buffer[MAX_RX_MESSAGELENGTH + AB_FRAME_LENGTH_MAX]; //TX/RX buffer
139 | BYTE * dataPtr;
140 |
141 | BOOL m_useBCC;
142 |
143 | // methods
144 | WORD GetValue(WORD wIndex);
145 | CHAR * BuildMessagePreamble(BOOL error=FALSE,WORD errorCode=0);
146 | CHAR * BuildMessageEnd();
147 | WORD GetAddressArea(WORD classCode);
148 |
149 | static WORD CalculateReadAheadLength(const BYTE*pBuffer, DWORD length);
150 | static BOOL Status(const BYTE*pBuffer, DWORD length);
151 | };
152 |
153 | #endif // MESSAGE_H_HEADDER_FILE
--------------------------------------------------------------------------------
/ModRSsim2/simport.cpp:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: simport.cpp : implementation file
4 | //
5 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
6 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
7 | //
8 | // This program is free software: you can redistribute it and/or modify
9 | // it under the terms of the GNU Affero General Public License as
10 | // published by the Free Software Foundation, either version 3 of the
11 | // License, or (at your option) any later version.
12 | //
13 | // This program is distributed in the hope that it will be useful,
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | // GNU Affero General Public License for more details.
17 | //
18 | // You should have received a copy of the GNU Affero General Public License
19 | // along with this program. If not, see .
20 | //
21 | // Implementation of the SimulationSerialPort wrapper class for CRS232Port.
22 | //
23 | /////////////////////////////////////////////////////////////////////////////
24 |
25 | #include "stdafx.h"
26 | #include "SimPort.h"
27 | #include "abcommsprocessor.h"
28 |
29 | #ifdef _DEBUG
30 | #undef THIS_FILE
31 | static char THIS_FILE[]=__FILE__;
32 | #define new DEBUG_NEW
33 | #endif
34 |
35 | IMPLEMENT_DYNAMIC( SimulationSerialPort, CRS232Port);
36 |
37 | //constructor
38 | SimulationSerialPort::SimulationSerialPort()
39 | {
40 |
41 | }
42 |
43 |
44 | #ifdef _DEBUG
45 | void SimulationSerialPort::Dump(CDumpContext& dc) const
46 | {
47 | // call the base class first
48 | CObject::Dump(dc);
49 |
50 | // dump our object to the debuggers output
51 | // all important members can be dumped at this stage.
52 | dc << "Simulator 232 Port: " << "\n";
53 | } // Dump
54 | #endif // _DEBUG
55 |
56 | // ----------------------------- CalculateReadAheadLength ---------------------
57 | // Calculates amount of bytes to read int order to recieve a full modbus message,
58 | // based on the 1st 6 bytes. if less than 6 bytes have been read, the function
59 | // returns the difference.
60 | //
61 | LONG SimulationSerialPort::CalculateReadAheadLength(const BYTE* rxBuffer, DWORD rxBufferIndex)
62 | {
63 | LONG raLength=0; // read-ahead length
64 | DWORD numItems; // Modbus command length
65 |
66 | if (pGlobalDialog->m_selectedProtocol == PROTOCOL_SELMOD232)
67 | {
68 | if (rxBufferIndex ==0)
69 | return(MODBUS_HEADDER_LEN);
70 | else
71 | {
72 | if (rxBufferIndex= MAX_MODBUS_MESSAGELEN)
124 | {
125 | raLength = MAX_MODBUS_MESSAGELEN;
126 | //error occured. maybe we should spit out an exception response further along?
127 | }
128 | }
129 | return (raLength);
130 | }
131 | return (MODBUS_HEADDER_LEN); // we should never get here
132 | }
133 | else
134 | {
135 | // Allen-Bradley DF1 (and JOY)
136 | CABCommsProcessor *pAB;
137 | if (pGlobalDialog->m_pServerRS232Array->GetUpperBound() == -1)
138 | return(1);
139 | pAB = (CABCommsProcessor *)(pGlobalDialog->m_pServerRS232Array->GetAt(0));
140 | if (pAB->IsKindOf(RUNTIME_CLASS(CABCommsProcessor)))
141 | {
142 | return(pAB->GetRALength());
143 | }
144 | return(18);
145 | }
146 | return(1);
147 | } // CalculateReadAheadLength
148 |
--------------------------------------------------------------------------------
/ModRSsim2/UTIL.CPP:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: util.cpp
4 | //
5 | // Mod_RSSim (c) Embedded Intelligence Ltd. 1993,2009
6 | // AUTHOR: Conrad Braam. http://www.plcsimulator.org
7 | // email:zaphodikus@hotmail.com
8 | //
9 | // This program is free software: you can redistribute it and/or modify
10 | // it under the terms of the GNU Affero General Public License as
11 | // published by the Free Software Foundation, either version 3 of the
12 | // License, or (at your option) any later version.
13 | //
14 | // This program is distributed in the hope that it will be useful,
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | // GNU Affero General Public License for more details.
18 | //
19 | // You should have received a copy of the GNU Affero General Public License
20 | // along with this program. If not, see .
21 | //
22 | /////////////////////////////////////////////////////////////////////////////
23 | //
24 | // Implementation of Utility functions
25 | // The functions and classes below are defined in "util.h"
26 | //
27 | /////////////////////////////////////////////////////////////////////////////
28 |
29 | #include "stdafx.h"
30 |
31 |
32 | // ----------------------------- PackField ----------------------------
33 | // PURPOSE: packs the value into ASCII-HEX into the telegram
34 | // NOTE:
35 | // Unused
36 | void PackField(CHAR **pBuffer, size_t buffSize, int bufferSize, WORD value, WORD length)
37 | {
38 | CHAR tempStr[80];
39 | CHAR formatStr[80];
40 |
41 | // build a format string
42 | sprintf_s(formatStr, sizeof(formatStr), "%%0%dX", length);
43 | // plonk it in
44 | sprintf_s(tempStr, sizeof(tempStr), formatStr, value);
45 | strncpy_s(*pBuffer, buffSize, tempStr, length);
46 | // increment pointer
47 | *pBuffer+=length;
48 | **pBuffer = '\0'; // add a null
49 | } // PackField
50 |
51 |
52 | // ------------------------------ SwapBytes ----------------------------
53 | // PURPOSE: Swap the HI and LO bytes of a WORD
54 | // NOTES: This could have been written as a macro, but gets messy when using
55 | // pointer de-refferencing and type casting.
56 | WORD SwapBytes(WORD wrd)
57 | {
58 | WORD result;
59 |
60 | result = ( (LOBYTE(wrd) << 8) + HIBYTE(wrd) );
61 | return(result);
62 | } // SwapBytes
63 |
64 |
65 | // -------------------------------- UnPackField --------------------------
66 | // return a WORD or BYTE (depends on length) at a pointer
67 | WORD UnPackField(BYTE **pBuffer, WORD length)
68 | {
69 | BYTE *pField = (BYTE*)(*pBuffer);
70 | WORD value=0;
71 | int i;
72 |
73 | for (i=0;i= 'A') ?
99 | // (*pField - ('A' - 10) ) : (*pField - '0') );
100 | if ((*pField >= 'A')&&(*pField <= 'F'))
101 | value += *pField - ('A' - 10);
102 | else
103 | if ((*pField >= 'a')&&(*pField <= 'f'))
104 | value += *pField - ('a' - 10);
105 | else
106 | {
107 | if ((*pField >= '0')&&(*pField <= '9'))
108 | value += *pField - '0';
109 | else
110 | error = TRUE;
111 | }
112 | pField++;
113 |
114 | }
115 | // increment pointer
116 | *pBuffer+=length;
117 | return (value);
118 | }
119 |
120 |
121 | // -------------------------------- PortAvailable ---------------------------
122 | // This func simply calls the other func
123 | BOOL PortAvailable(LPCTSTR portName)
124 | {
125 | return (!PortInUse(portName));
126 | } // PortAvailable
127 |
128 |
129 | // ----------------------------- GetFirstFreePort -----------------------------
130 | // Go thru all ports, and find the 1st unused one
131 | void GetFirstFreePort(LPSTR freePortName)
132 | {
133 | DWORD count;
134 | LONG retCode;
135 | CHAR portname[MAX_COMPORT_NAME];
136 |
137 | freePortName[0] = '\0';
138 | count = 0;
139 | while (TRUE)
140 | {
141 | retCode = EnumerateSerialPorts(portname, sizeof(portname), count);
142 | if( retCode != SUCCESS)
143 | break;
144 | if (PortAvailable(portname))
145 | {
146 | strcpy_s(freePortName, MAX_COMPORT_NAME, portname);
147 | return;
148 | }
149 | // try next port
150 | count++;
151 | }
152 | } // GetFirstFreePort
153 |
154 |
155 |
156 | // ----------------------------- LoadDATAResource -------------------------------
157 | // load a TEXT data resource into a CString
158 | BOOL LoadDATAResource(int resourceID, char **pBuffer, DWORD* resSize)
159 | {
160 | HRSRC hFound;
161 | HGLOBAL hRes;
162 | BOOL bResult;
163 | DWORD size;
164 | HMODULE hModule = AfxGetResourceHandle();
165 |
166 | hFound = FindResource(hModule, MAKEINTRESOURCE(resourceID), "HELPFILES");
167 | hRes = LoadResource(hModule, hFound);
168 | size = SizeofResource(hModule, hFound);
169 | if (size)
170 | {
171 | *pBuffer = new char[size+1];
172 | if (NULL !=*pBuffer)
173 | {
174 | memcpy(*pBuffer, LockResource(hRes), size);
175 | (*pBuffer)[size] = '\0'; // terminate the string
176 | }
177 | bResult = UnlockResource(hRes);
178 | }
179 | else
180 | return (FALSE);
181 | bResult = FreeResource(hRes);
182 | *resSize = size;
183 | return (TRUE);
184 | } // LoadDATAResource
185 |
186 |
187 | BOOL FindFragment(const BYTE * buffer, DWORD length,
188 | const BYTE *pSearchBuff, DWORD mSearchLength,
189 | DWORD *pos)
190 | {
191 | BOOL found = FALSE;
192 | DWORD idx=0;
193 |
194 | while (idx + mSearchLength <= length)
195 | {
196 | if (0 ==memcmp(&buffer[idx], pSearchBuff, mSearchLength))
197 | {
198 | *pos = idx;
199 | found = TRUE;
200 | break;
201 | }
202 | idx++;
203 | }
204 | return(found);
205 | }
--------------------------------------------------------------------------------
/ModRSsim2/Resizer.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************\
2 | $Copyright: (C)2001 Dmitry Kochin
3 | $Workfile: Resizer.h $
4 | \******************************************************************************/
5 |
6 | // Resizer.h: interface for the CResizer class.
7 | //
8 | //////////////////////////////////////////////////////////////////////
9 | // Class to correctly move child windows after parent window was resized
10 | // Created: 06/07/01 by dukei@
11 | //////////////////////////////////////////////////////////////////////
12 |
13 | //An idea:
14 | //
15 | //Each child window side (left, top, right and bottom) is connected to a side of another window,
16 | //so called relative window. It is tipically dialog window, that owns the child window.
17 | //When dialog window is resized, child window sides are moved after the relative window,
18 | //preserving the connections.
19 | //
20 | //Typical usage:
21 | //
22 | // 1. CResizer m_resizer is member variable;
23 | //
24 | // 2. Add the following code to OnInitDialog()
25 | // (replacing control IDs to your specific ones).
26 | // See array format description later in the comment
27 | //
28 | // static CResizer::CBorderInfo s_bi[] = {
29 | // {IDC_CONTROL_ID, {CResizer::eFixed, IDC_MAIN, CResizer::eLeft}, //Left side
30 | // {CResizer::eFixed, IDC_MAIN, CResizer::eTop}, //Top side
31 | // {CResizer::eFixed, IDC_MAIN, CResizer::eLeft}, //Right side
32 | // {CResizer::eFixed, IDC_MAIN, CResizer::eTop}}, //Bottom side
33 | // {IDC_STATIC_ID, {CResizer::eFixed, IDC_MAIN, CResizer::eLeft},
34 | // {CResizer::eFixed, IDC_MAIN, CResizer::eTop},
35 | // {CResizer::eFixed, IDC_MAIN, CResizer::eRight},
36 | // {CResizer::eFixed, IDC_MAIN, CResizer::eTop}},
37 | // };
38 | // const nSize = sizeof(s_bi)/sizeof(s_bi[0]);
39 | // m_resizer.Init(m_hWnd, NULL, s_bi, nSize);
40 | //
41 | // 3. Add the following code to OnSize() handler
42 | //
43 | // m_resizer.Move();
44 | //
45 | // 4. Everything should work now
46 | //
47 | // P.S. Data array format consists of one or more CBorderInfo structures, which contains
48 | // moved control ID (first field) and four CBorder structures,
49 | // for left, top, right and bottom sides of moved control accordingly.
50 | //
51 | // The main difficulty is to understand CBorder structure, which has the following format:
52 | //
53 | // {, ,
54 | // }
55 | //
56 | // CResizer::eFixed CResizer::eLeft
57 | // CResizer::eProportional IDC_MAIN CResizer::eTop
58 | // or {CResizer::eWidth , IDC_ANOTHER_CONTROL_ID , CResizer::eRight }
59 | // CResizer::eHeight CResizer::eBottom
60 | // CResizer::eXCenter
61 | // CResizer::eYCenter
62 | //
63 | // For example, {CResizer::eFixed, IDC_MAIN, CResizer::eLeft} means, that moved control side is
64 | // on the fixed distance (CResizer::eFixed) from left side (CResizer::eLeft) of dialog window (IDC_MAIN)
65 | //
66 | // Another example: {CResizer::eProportional, IDC_CONTROL_ID, CResizer::eLeft} means, that
67 | // moved control side preserves relation (proportionaly) (CResizer::eProportional)
68 | // to the width (CResizer::eLeft or CResizer::eRight) of control IDC_CONTROL_ID.
69 | //
70 | // TIP: Resizer resizes controls in the order they are defined in the array, so
71 | // should always be defined (and, therefore, moved by the resizer) before
72 | // it is used as relative window. Otherwise, resizer ASSERTs.
73 |
74 | #pragma once
75 |
76 | #define IDC_MAIN 0 //Parent dialog ID to be relative window
77 |
78 | class CResizer
79 | {
80 | public:
81 | enum EBorder{
82 | eFixed = 1, //Given distance to specified window side
83 | eProportional, //Coordinate is changed proportionally to width/height of specified window
84 | eWidth, //The width is preserved (relative window and window side are ignored)
85 | eHeight, //The height is preserved (relative window and window side are ignored)
86 | };
87 | enum ESize{
88 | eLeft = 1, //Relative to left side
89 | eTop, //Top
90 | eRight, //Right
91 | eBottom, //Bottom
92 | eXCenter, //The center of width
93 | eYCenter //The center of height
94 | };
95 | struct CBorder{
96 | EBorder eType; //Type of relation to relative control side
97 | int nRelID; //Relative control
98 | ESize eRelType; //Side of relative control
99 | };
100 | struct CBorderInfo{
101 | int nID; //Control ID
102 | CBorder left;
103 | CBorder top;
104 | CBorder right;
105 | CBorder bottom;
106 | };
107 | private:
108 | struct CControlInfo{
109 | RECT rcInitial; //initial control position;
110 | const CBorderInfo *pInfo;
111 | };
112 | struct CRectInfo{
113 | int nID; //Control ID
114 | RECT rc; //New control rect
115 | bool bVisible; //If control is visible
116 | bool bHide; //If control should be hidden because it overlaps senior control
117 | };
118 | HWND m_wndParent;
119 | RECT m_rcInitial; //Initial window client area
120 | typedef CControlInfo * TInfo;
121 | typedef CRectInfo * TRectInfo;
122 | TInfo m_vInfo;
123 | int m_nSize; //Size of m_vInfo array
124 | mutable TRectInfo m_vRectInfo;
125 | mutable int m_nCachedSize; //Size of m_vRectInfo
126 | protected:
127 | HWND GetDlgItem(int nID) const{return ::GetDlgItem(m_wndParent, nID);}
128 | void GetDlgItemRect(int nID, RECT &rc) const;
129 | void GetCachedDlgItemRect(int nID, RECT &rc) const;
130 | void GetInitialDlgItemRect(int nID, RECT &rc) const;
131 | void Move(int nIndex) const;
132 | int GetCoordinate(ESize eType, const RECT &rcInitial, const CBorder &border, const RECT &rc) const;
133 | static int GetRectCoord(ESize eType, const RECT &rc);
134 | static int GetRectSize(ESize eType, const RECT &rc);
135 | int GetRelativeCoord(const CBorder &border) const;
136 | int Find(int nID) const;
137 | int FindCached(int nID) const;
138 | void MoveAndHideOverlapped() const;
139 | void Clear();
140 | public:
141 | //Initializes resizer
142 | bool Init(HWND hWndParent, LPCRECT rcInitial, const CBorderInfo *pBorders, int nSize);
143 | //Performs moving of controls
144 | void Move() const;
145 | //Just constructor
146 | CResizer();
147 | //Just destructor
148 | ~CResizer();
149 | };
150 |
151 |
--------------------------------------------------------------------------------
/mylib/MicroTick.cpp:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // FILE: MicroTick.cpp : implementation file
4 | //
5 | // See _README.CPP
6 | //
7 | // Implements the CMicroTick class
8 | //
9 | // Fixes: See H file
10 | //
11 | /////////////////////////////////////////////////////////////////////////////
12 |
13 | #include "stdafx.h"
14 |
15 | #ifdef _DEBUG
16 | #define new DEBUG_NEW
17 | #undef THIS_FILE
18 | static char THIS_FILE[] = __FILE__;
19 | #endif
20 |
21 | /////////////////////////////////////////////////////////////////////////////
22 | //
23 |
24 | CMicroTick::CMicroTick()
25 | {
26 | m_unchecked = RGB(255,70,90); // red unchecked colour
27 | m_checked = RGB(0,255,0); // green checked colour
28 | // background
29 | m_backgroundInActive = RGB(127,127,127);
30 | m_backgroundActive = RGB(241,241,0);
31 | m_borderWidth = 1; // default width
32 | m_backgroundState = 0; //inactive
33 |
34 | m_textColor = RGB(0,0,0); // black
35 | // m_microTickState will be the tick-box state as set in the dialog template
36 | // or whatever the parent window has set up.
37 | m_pFont = NULL;
38 | }
39 |
40 | CMicroTick::~CMicroTick()
41 | {
42 | if (NULL != m_pFont)
43 | delete m_pFont;
44 | }
45 |
46 |
47 | BEGIN_MESSAGE_MAP(CMicroTick, CButton)
48 | //{{AFX_MSG_MAP(CMicroTick)
49 | ON_WM_PAINT()
50 | ON_WM_ERASEBKGND()
51 | ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
52 | ON_WM_SETFOCUS()
53 | //}}AFX_MSG_MAP
54 | END_MESSAGE_MAP()
55 |
56 | /////////////////////////////////////////////////////////////////////////////
57 | // CMicroTick message handlers
58 |
59 | // ----------------------------- OnPaint --------------------------------
60 | // By over-riding onpaint, I have gotten control of the graphical
61 | // appearance of this control
62 | void CMicroTick::OnPaint()
63 | {
64 | RECT clientRect;
65 | CBrush backBrush;
66 | CPen borderPen;
67 | COLORREF color, borderColor, textColor;
68 | CHAR buffer[80];
69 | CPen * pOldPen;
70 | CFont * pOldFont;
71 | DWORD i=9, borderWidth = m_borderWidth;
72 | BOOL drawFocus = FALSE;
73 |
74 | // TODO: Add your message handler code here
75 | CPaintDC dc(this); // device context for painting
76 | GetClientRect(&clientRect);
77 |
78 | // determine the text background color to use
79 | switch (m_microTickState)
80 | {
81 | case 0: // unselected
82 | color = m_unchecked;
83 | textColor = m_uncheckedTextColor;
84 | break;
85 | case 1:
86 | default:
87 | color = m_checked;
88 | textColor = m_textColor;
89 | break;
90 | }
91 | // determine the border color
92 | switch (m_backgroundState)
93 | {
94 | case 0: // unselected/inactive
95 | borderColor = m_backgroundInActive;
96 | break;
97 | case 1:
98 | default:
99 | borderColor = m_backgroundActive;
100 | break;
101 | }
102 |
103 | backBrush.CreateSolidBrush(color);
104 | dc.FillRect(&clientRect, &backBrush);
105 |
106 | //////////////////////////////////////////////////////////////////
107 | // Draw the border
108 | if (GetFocus()==this)
109 | {
110 | borderWidth++;
111 | drawFocus = TRUE;
112 | }
113 | borderPen.CreatePen(PS_SOLID, 1, borderColor);
114 | pOldPen = (CPen*)dc.SelectObject(&borderPen);
115 | pOldFont = (CFont*)dc.SelectObject(m_pFont);
116 | // I used a loop here, since geometric pens are difficult to use
117 | for (i=0;i < borderWidth; i++)
118 | {
119 | // draw a thick border if wanted.
120 | dc.MoveTo(i,i);
121 | dc.LineTo(clientRect.right-i-1, i); // TOP
122 | dc.LineTo(clientRect.right-i-1, clientRect.bottom-i-1);// RIGHT
123 | dc.LineTo(clientRect.left+i, clientRect.bottom-i-1); // BOTTOM
124 | dc.LineTo(clientRect.left+i, i); // LEFT side
125 | if (drawFocus && (i== borderWidth-2))
126 | dc.SelectStockObject(BLACK_PEN);
127 | }
128 |
129 | ///////////////////////////////////////////////////////////////////
130 | // Display the text
131 | buffer[0] = '\0';
132 | GetWindowText(buffer, sizeof(buffer));
133 | dc.SetBkColor(color);
134 | // dc.TextOut(); does not work so well, so we did it this way
135 | clientRect.bottom -=m_borderWidth; // clip
136 | clientRect.top +=m_borderWidth; // make sure we move text away from the borders
137 | clientRect.right -=m_borderWidth; // clip
138 | clientRect.left +=m_borderWidth+1; // move away
139 |
140 | dc.SetBkMode(TRANSPARENT);
141 | dc.SetTextColor(textColor);
142 | dc.DrawText(buffer, strlen(buffer), &clientRect, DT_VCENTER |DT_CENTER);
143 |
144 | // select old pen back into DC, not required in a dialog actually
145 | //dc.SelectObject(pOldPen);
146 |
147 | // Do not call CButton::OnPaint() for painting messages
148 | }
149 |
150 |
151 | // ------------------------ OnEraseBkgnd -----------------------------
152 | BOOL CMicroTick::OnEraseBkgnd(CDC* pDC)
153 | {
154 | return (1);
155 | } // OnEraseBkgnd
156 |
157 | // --------------------------- OnClicked --------------------------------
158 | //
159 | void CMicroTick::OnClicked()
160 | {
161 | // TODO: Add your control notification handler code here
162 | if (m_microTickState )
163 | m_microTickState = 0;
164 | else
165 | m_microTickState = 1;
166 | InvalidateRect(NULL);
167 | } // OnClicked
168 |
169 | // ------------------------- PreSubclassWindow ---------------------------
170 | //
171 | void CMicroTick::PreSubclassWindow()
172 | {
173 | // TODO: Add your specialized code here and/or call the base class
174 | m_microTickState = CButton::GetCheck();
175 |
176 | SetButtonStyle(GetButtonStyle() | BS_OWNERDRAW | BS_AUTOCHECKBOX);
177 | // find a font size
178 | CFont * pFont = GetFont();
179 | LOGFONT logFont;
180 |
181 | pFont->GetLogFont(&logFont);
182 | logFont.lfWidth=0;
183 | logFont.lfHeight=-10; // Changed -9 to -10 (3-digit stations truncated slightly) by DL on 2016-08-14
184 | strcpy_s(logFont.lfFaceName, sizeof(logFont.lfFaceName), "Terminal");
185 | m_pFont = new CFont;
186 | m_pFont->CreateFontIndirect(&logFont);
187 | CButton::PreSubclassWindow();
188 | } // PreSubclassWindow
189 |
190 | // --------------------------- SetCheck -------------------------------
191 | void CMicroTick::SetCheck(int nCheck)
192 | {
193 | m_microTickState = nCheck;
194 |
195 | InvalidateRect(NULL); // force a re-paint
196 | } // SetCheck
197 |
198 | // --------------------------- GetCheck -------------------------------
199 | int CMicroTick::GetCheck()
200 | {
201 | return (m_microTickState? 1 : 0);
202 | } // GetCheck
203 |
204 |
205 | void CMicroTick::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
206 | {
207 | // TODO: Add your code to draw the specified item
208 |
209 | // do nothing, we have to do this.
210 | }
211 |
212 | void CMicroTick::OnSetFocus(CWnd* pOldWnd)
213 | {
214 | CButton::OnSetFocus(pOldWnd);
215 |
216 | // TODO: Add your message handler code here
217 | InvalidateRect(NULL);
218 | }
219 |
--------------------------------------------------------------------------------