?? mastercontroldlg.cpp
字號:
// MasterControlDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MasterControl.h"
#include "MasterControlDlg.h"
#include "speeds.h"
#include "pinouts.h"
#include "propaux.h"
#include "pulses.h"
#include "homeconf.h"
#include "Feeds.h"
#include "translation.h"
#include "conio.h"
#include "Ports.h"
#include "math.h"
#include "interpolate.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define BASE 0x270
#define DA BASE+0
#define DB BASE+1
#define DC BASE+2
#define DCW BASE+3
#define PA BASE+4
#define PB BASE+5
#define PC BASE+6
#define PCW BASE+7
#define StopDelay 250
#define MinDist 100
char cPortToUse='1'; /* set it for '1'=LPT1, '2'=LPT2, '3'=LPT3 */
char cOutData; /* use this byte to get data from Ports */
char cInData; /* use this byte to get data from Ports */
HANDLE hDevice;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMasterControlDlg dialog
CMasterControlDlg::CMasterControlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMasterControlDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMasterControlDlg)
m_JogDist = 5.5;
m_XGotoVar = 0.0;
m_YGotoVar = 0.0;
m_ZGotoVar = 0.0;
m_XLocVar = 0.0;
m_YLocVar = 0.0;
m_ZLocVar = 0.0;
m_CurLineInt = 0;
m_Estimate = _T("");
m_TimeLeft = _T("");
m_Linear = 0.0;
m_ZMin = 0.0;
m_ZMax = 0.0;
m_YMin = 0.0;
m_YMax = 0.0;
m_XMin = 0.0;
m_XMax = 0.0;
m_YLimit = 0.0;
m_XLimit = 0.0;
m_ZLimit = 0.0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMasterControlDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMasterControlDlg)
DDX_Control(pDX, IDC_AUTOEMERG, m_AutoButton);
DDX_Control(pDX, IDC_ALLLIMIT, m_AllLimitButton);
DDX_Control(pDX, IDC_ZLIMIT, m_ZLimitButton);
DDX_Control(pDX, IDC_YLIMIT, m_YLimitButton);
DDX_Control(pDX, IDC_XLIMIT, m_XLimitButton);
DDX_Control(pDX, IDC_ROUTER, m_Router);
DDX_Control(pDX, IDC_ENABLELED, m_EnableLed);
DDX_Control(pDX, IDC_AUXLED3, m_AuxLed3);
DDX_Control(pDX, IDC_AUXLED2, m_AuxLed2);
DDX_Control(pDX, IDC_AUXLED1, m_AuxLed1);
DDX_Control(pDX, IDC_LENGTH, m_LinearEd);
DDX_Control(pDX, IDC_DISPLAY, m_Display);
DDX_Control(pDX, IDC_RUNNING, m_Running);
DDX_Control(pDX, IDC_DISPONLED, m_DispOnLed);
DDX_Control(pDX, IDC_DISPOFFLED, m_DispOffLed);
DDX_Control(pDX, IDC_CURRENT, m_CurLine);
DDX_Control(pDX, IDC_FILENAME, m_PathName);
DDX_Control(pDX, IDC_REMAINING, m_Remaining);
DDX_Control(pDX, IDC_STARTTIME, m_StartTime);
DDX_Control(pDX, IDC_UNITS, m_Units);
DDX_Control(pDX, IDC_ZGOTO, m_ZGoTo);
DDX_Control(pDX, IDC_YGOTO, m_YGoTo);
DDX_Control(pDX, IDC_XGOTO, m_XGoTo);
DDX_Control(pDX, IDC_GO, m_Go);
DDX_Control(pDX, IDC_JOG, m_JogEdit);
DDX_Control(pDX, IDC_LEDZHOME, m_LEDZHome);
DDX_Control(pDX, IDC_LEDYHOME, m_LEDYHome);
DDX_Control(pDX, IDC_LEDXHOME, m_LEDXHome);
DDX_Control(pDX, IDC_LEDROUTE, m_LEDRoute);
DDX_Control(pDX, IDC_LEDEMERG, m_LEDEmerg);
DDX_Control(pDX, IDC_ZLOC, m_ZLoc);
DDX_Control(pDX, IDC_YLOC, m_YLoc);
DDX_Control(pDX, IDC_XLOC, m_XLoc);
DDX_Control(pDX, IDC_DOWN, m_Down);
DDX_Control(pDX, IDC_UP, m_Up);
DDX_Control(pDX, IDCANCEL, m_Cancel);
DDX_Control(pDX, IDC_YPLUS, m_YPlus);
DDX_Control(pDX, IDC_YMINUS, m_YMinus);
DDX_Control(pDX, IDC_XPLUS, m_XPlus);
DDX_Control(pDX, IDC_XMINUS, m_XMinus);
DDX_Text(pDX, IDC_JOG, m_JogDist);
DDX_Text(pDX, IDC_XGOTO, m_XGotoVar);
DDV_MinMaxDouble(pDX, m_XGotoVar, -9999., 9999.);
DDX_Text(pDX, IDC_YGOTO, m_YGotoVar);
DDX_Text(pDX, IDC_ZGOTO, m_ZGotoVar);
DDX_Text(pDX, IDC_XLOC, m_XLocVar);
DDX_Text(pDX, IDC_YLOC, m_YLocVar);
DDX_Text(pDX, IDC_ZLOC, m_ZLocVar);
DDX_Text(pDX, IDC_CURRENT, m_CurLineInt);
DDX_Text(pDX, IDC_REMAINING, m_Estimate);
DDX_Text(pDX, IDC_STARTTIME, m_TimeLeft);
DDX_Text(pDX, IDC_LENGTH, m_Linear);
DDX_Text(pDX, IDC_ZMIN, m_ZMin);
DDX_Text(pDX, IDC_ZMAX, m_ZMax);
DDX_Text(pDX, IDC_YMIN, m_YMin);
DDX_Text(pDX, IDC_YMAX, m_YMax);
DDX_Text(pDX, IDC_XMIN, m_XMin);
DDX_Text(pDX, IDC_XMAX, m_XMax);
DDX_Text(pDX, IDC_YLIMITCOOR, m_YLimit);
DDX_Text(pDX, IDC_XLIMITCOOR, m_XLimit);
DDX_Text(pDX, IDC_ZLIMITCOOR, m_ZLimit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMasterControlDlg, CDialog)
//{{AFX_MSG_MAP(CMasterControlDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_PREFS, OnPrefs)
ON_COMMAND(IDD_ABOUT, OnAbout)
ON_BN_CLICKED(IDC_XPLUS, OnXplus)
ON_BN_CLICKED(IDC_XMINUS, OnXminus)
ON_BN_CLICKED(IDC_YMINUS, OnYminus)
ON_BN_CLICKED(IDC_YPLUS, OnYplus)
ON_BN_CLICKED(IDC_UP, OnUp)
ON_BN_CLICKED(IDC_DOWN, OnDown)
ON_BN_CLICKED(IDC_GO, OnGo)
ON_BN_CLICKED(IDC_HOMEALL, OnHomeall)
ON_BN_CLICKED(IDC_HOMEX, OnHomex)
ON_BN_CLICKED(IDC_HOMEY, OnHomey)
ON_BN_CLICKED(IDC_HOMEZ, OnHomez)
ON_BN_CLICKED(IDC_SETHOME, OnSethome)
ON_WM_CREATE()
ON_COMMAND(IDD_OPEN, OnOpen)
ON_BN_CLICKED(IDC_DISPOFF, OnDispoff)
ON_BN_CLICKED(IDC_DISPON, OnDispon)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_RUN, OnRun)
ON_BN_CLICKED(IDC_PAUSE, OnPause)
ON_BN_CLICKED(IDC_SIMULATE, OnSimulate)
ON_BN_CLICKED(IDC_RESET, OnReset)
ON_BN_CLICKED(IDC_AUX1, OnAux1)
ON_BN_CLICKED(IDC_AUX2, OnAux2)
ON_BN_CLICKED(IDC_AUX3, OnAux3)
ON_BN_CLICKED(IDC_SAFETY, OnSafety)
ON_BN_CLICKED(IDC_ROUTER, OnRouter)
ON_BN_CLICKED(IDC_XLIMIT, OnXlimit)
ON_BN_CLICKED(IDC_YLIMIT, OnYlimit)
ON_BN_CLICKED(IDC_ZLIMIT, OnZlimit)
ON_BN_CLICKED(IDC_ALLLIMIT, OnAlllimit)
ON_BN_CLICKED(IDC_AUTOEMERG, OnAutoemerg)
ON_COMMAND(IDC_PREFS, OnPrefs)
ON_BN_CLICKED(IDC_FEEDS, OnFeeds)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMasterControlDlg message handlers
BOOL CMasterControlDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
OnAbout();
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
const PCHAR VxDName = "\\\\.\\PORTS.VXD";
hDevice = CreateFile(VxDName, 0,0,0,CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);
/* By now the PortIO95 VxD should be loaded - lets check */
/* if (hDevice == INVALID_HANDLE_VALUE)
{
/* Get the Last Error Value see also ] */
// int err = GetLastError();
// MessageBox( "PortIO Error",NULL, MB_OK );
/* There is one error we have to handle carefully. It implies that
* the VxD was found ok but didn't handle the dyamic
* loading properly. This error shouldn't happen. But if it
* does we cope with it here. We dynamically unload the vxd
* before we exit. NOTE there is no .VXD extension on this call
* otherwise you really do delete the VXD file rather than just
* forcing an unload. */
// if (err == ERROR_NOT_SUPPORTED) DeleteFile("\\\\.\\PORTS");
// exit(1);
// }
SwapX = AfxGetApp( )->GetProfileInt("Preferences", "SwapX" , 0 ) != 0;
SwapY = AfxGetApp( )->GetProfileInt("Preferences", "SwapY" , 0 ) != 0;
SwapZ = AfxGetApp( )->GetProfileInt("Preferences", "SwapZ" , 0 ) != 0;
LPT1 = AfxGetApp( )->GetProfileInt("Preferences", "LPT1" , 1 ) != 0;
LPT2 = AfxGetApp( )->GetProfileInt("Preferences", "LPT2" , 0 ) != 0;
LPT3 = AfxGetApp( )->GetProfileInt("Preferences", "LPT3" , 0 ) != 0;
LPT4 = AfxGetApp( )->GetProfileInt("Preferences", "LPT4" , 0 ) != 0;
if( LPT1 ) cPortToUse = '1';
if( LPT2 ) cPortToUse = '2';
if( LPT3 ) cPortToUse = '3';
if( LPT4 ) cPortToUse = '4';
if(!( LPT1 || LPT2 || LPT3 || LPT4)) cPortToUse = '1';
int retval=DeviceIoControl(hDevice, PORTIO_SETPORT, &cPortToUse, sizeof(cPortToUse), NULL, 0, &hold, NULL);
if (!retval)
{
MessageBox( "Can't find Port, Turning off Selection",NULL, MB_OK );
AfxGetApp( )->WriteProfileInt("Preferences", "LPT1" , 0 ); // turn them all off
AfxGetApp( )->WriteProfileInt("Preferences", "LPT2" , 0 );
AfxGetApp( )->WriteProfileInt("Preferences", "LPT3" , 0 );
AfxGetApp( )->WriteProfileInt("Preferences", "LPT4" , 0 );
}
retval=DeviceIoControl(hDevice, PORTIO_SET_PINS_1_14_16_17_AS_OUTPUT, NULL, 0, NULL, 0, NULL, NULL);
retval=DeviceIoControl(hDevice, PORTIO_PIN1HIGH, NULL, 0, NULL, 0, NULL, NULL);
retval=DeviceIoControl(hDevice, PORTIO_PIN14HIGH, NULL, 0, NULL, 0, NULL, NULL);
retval=DeviceIoControl(hDevice, PORTIO_PIN16HIGH, NULL, 0, NULL, 0, NULL, NULL);
retval=DeviceIoControl(hDevice, PORTIO_PIN17HIGH, NULL, 0, NULL, 0, NULL, NULL);
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_Running.SetImage( IDB_GREENLED , 15 );
m_LEDEmerg.SetImage( IDB_REDLED, 15 );
m_LEDRoute.SetImage( IDB_GREENLED, 15 );
m_LEDXHome.SetImage( IDB_GREENLED, 15 );
m_LEDYHome.SetImage( IDB_GREENLED, 15 );
m_LEDZHome.SetImage( IDB_GREENLED, 15 );
m_DispOnLed.SetImage( IDB_GREENLED, 15 );
m_DispOffLed.SetImage( IDB_REDLED, 15 );
m_AuxLed1.SetImage(IDB_GREENLED, 15 );
m_AuxLed2.SetImage(IDB_GREENLED, 15 );
m_AuxLed3.SetImage(IDB_GREENLED, 15 );
m_EnableLed.SetImage(IDB_GREENLED, 15 );
m_AuxLed1.Depress(false);
m_AuxLed2.Depress(false);
m_AuxLed3.Depress(false);
m_EnableLed.Depress(false);
m_DispOnLed.Depress( true );
m_DispOffLed.Depress( false );
m_Running.Depress( false );
m_LEDEmerg.Depress(false);
m_LEDRoute.Depress(false);
m_LEDXHome.Depress(true);
m_LEDYHome.Depress(true);
m_LEDZHome.Depress(true);
Emergency();
IO48data = 0;
if( ! QueryPerformanceFrequency( &frequency ))
{
MessageBox(" No High-Res Hardware Counter found");
exit(-1);
}
GLines.RemoveAll();
FileLoaded = FALSE;
FileLength = 0;
cGLines = 0;
TextBuffer = 0;
steps = 0;
vector = 0;
DispOn = true;
RUN = false;
Simulate = false;
Simulated = false;
Dwell = 250;
Spindle = false;
XLimit = false; YLimit = false; ZLimit = false;
EStop = false;
Enable = false;
m_XLimit = 0;
m_YLimit = 0;
m_ZLimit = 0;
Automatic = false;
while( !SetupVars());
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMasterControlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CMasterControlDlg::OnCancel()
{
GLines.RemoveAll();
if (TextBuffer)
{
free(TextBuffer);
TextBuffer = 0;
}
if( vector ) delete[] vector;
if( steps ) delete[] steps;
DeleteFile("\\\\.\\PORTS");
KillTimer(1);
int retval=DeviceIoControl(hDevice, PORTIO_UNSETPORT, NULL, 0, NULL, 0, NULL, NULL);
CDialog::OnCancel();
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMasterControlDlg::OnOpen()
{
CFileDialog *files = (CFileDialog*) new CFileDialog(TRUE,NULL,NULL,NULL,
"ArtCam Code(*.tap)|*.tap|All Files(*.*)|*.*||",
NULL); // add new file types here
files->m_ofn.lpstrInitialDir = "c:\\My Documents\\";
files->DoModal();
m_PathName.SetWindowText(files->GetFileName());
if ( !myFile.Open(files->GetPathName(), CFile::modeRead, &fileException ))
{
TRACE( "Can't open file %s, error = %u\n",
files->GetPathName(), fileException.m_cause );
return;
}
if (TextBuffer)
{
free(TextBuffer);
TextBuffer = 0;
}
FileLength = myFile.GetLength() + sizeof( char);
TextBuffer = (LPSTR)malloc (FileLength);
if( !TextBuffer)
{
AfxMessageBox(_T("Cannot allocate Memory for File"));
return;
}
myFile.Read((LPVOID) TextBuffer, FileLength);
// empty buffer array
GLines.RemoveAll();
// scan buffer for text line info
BuildStringArray();
FileLoaded = TRUE;
Invalidate(TRUE);
delete files;
m_LinearMM = 0;
if( vector ) delete[] vector;
vector = (int*) new int[cGLines];
if( steps ) delete[] steps;
steps = (int*) new int[cGLines];
QuantifyVectors();
TimeEstimate = 0;
Simulated = false;
myFile.Close();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -