📄 agvmonitordlg.cpp
字号:
// AGVMonitorDlg.cpp : implementation file
//
#include "stdafx.h"
#include "AGVMonitor.h"
#include "AGVMonitorDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAGVMonitorDlg dialog
byte gbAGVNowStation=0;
const char gbAGVStopMode[MaxAGVStopMode][32]={"到站停靠(自动离站)","到站停靠(手动离站)","终点停靠"};
const char gbRollerRollingMode[MaxRollerRollingMode][32]={"无运送","左向运送","右向运送"};
SOCKET gbAGVSocket;
#define WM_Connected WM_USER+1
#define WM_ReadData WM_USER+2
bool gbAGVConnected;
bool gbAGVConnecting=false;
CByteArray gbAGVACKData;
CAGVMonitorDlg::CAGVMonitorDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAGVMonitorDlg::IDD, pParent),m_AGVPathList(AGVPathList_Cols)
{
//{{AFX_DATA_INIT(CAGVMonitorDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAGVMonitorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAGVMonitorDlg)
DDX_Control(pDX, IDC_AGVPathList, m_AGVPathList);//列表框,显示AGV的路径信息
DDX_Control(pDX, IDC_ANIMATE_GOOGOL, m_animate_googol);//Animate控件
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_Station11_LED, m_Station_LED[0]);
DDX_Control(pDX, IDC_Station12_LED, m_Station_LED[1]);
DDX_Control(pDX, IDC_Station13_LED, m_Station_LED[2]);
DDX_Control(pDX, IDC_Station14_LED, m_Station_LED[3]);
DDX_Control(pDX, IDC_Station15_LED, m_Station_LED[4]);
DDX_Control(pDX, IDC_Station16_LED, m_Station_LED[5]);
DDX_Control(pDX, IDC_Station17_LED, m_Station_LED[6]);
DDX_Control(pDX, IDC_Station18_LED, m_Station_LED[7]);
DDX_Control(pDX, IDC_Station19_LED, m_Station_LED[8]);
DDX_Control(pDX, IDC_Station20_LED, m_Station_LED[9]);
DDX_Control(pDX, IDC_Station21_LED, m_Station_LED[10]);
DDX_Control(pDX, IDC_Station22_LED, m_Station_LED[11]);
DDX_Control(pDX, IDC_AGVOnline_LED, m_AGVOnline_LED);
DDX_Control(pDX, IDC_AGVWorking_LED, m_AGVWorking_LED);
}
BEGIN_MESSAGE_MAP(CAGVMonitorDlg, CDialog)
//{{AFX_MSG_MAP(CAGVMonitorDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ModifyAGVIP, OnModifyAGVIP)
ON_BN_CLICKED(IDC_SaveAGVIP, OnSaveAGVIP)
ON_BN_CLICKED(IDC_SettingAGVNowStation, OnSettingAGVNowStation)
ON_CBN_SELCHANGE(IDC_AGVStopMode, OnSelchangeAGVStopMode)
ON_CBN_SELCHANGE(IDC_DestinationStation, OnSelchangeDestinationStation)
ON_BN_CLICKED(IDC_EmptyAGVPathList, OnEmptyAGVPathList)
ON_BN_CLICKED(IDC_AddDestinationStation, OnAddDestinationStation)
ON_BN_CLICKED(IDC_AGVGoCarbarn, OnAGVGoCarbarn)
ON_BN_CLICKED(IDC_AGVInGoodsTransport, OnAGVInGoodsTransport)
ON_BN_CLICKED(IDC_AGVOutGoodsTransport, OnAGVOutGoodsTransport)
ON_BN_CLICKED(IDC_AGVSupplyTransport, OnAGVSupplyTransport)
ON_BN_CLICKED(IDC_AGVConnect, OnAGVConnect)
ON_BN_CLICKED(IDC_AGVDisconnect, OnAGVDisconnect)
ON_WM_CLOSE()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_ExecutePathList, OnExecutePathList)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_Connected,OnConnected)
ON_MESSAGE(WM_ReadData,OnReadData)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAGVMonitorDlg message handlers
BOOL CAGVMonitorDlg::OnInitDialog()
{
int i;
CStringArray Head;
CByteArray Cols;
CDialog::OnInitDialog();
// 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_animate_googol.Open(IDR_AVI_GOOGOL);
GetDlgItem(IDC_AGVIP)->EnableWindow(FALSE);
LoadAGVIPSetting();
Head.Add("起始站");
Head.Add("目的站");
Head.Add("停靠模式");
Head.Add("滚筒运送模式");
Cols.Add(15);Cols.Add(15);
Cols.Add(40);Cols.Add(30);
m_AGVPathList.InitCtrl(&Head, &Cols);
m_AGVPathList.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)LVS_EX_FULLROWSELECT);
for(i=0;i<MaxAGVStopMode;i++)
((CComboBox *)GetDlgItem(IDC_AGVStopMode))->AddString(gbAGVStopMode[i]);
SetTimer(1,100,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CAGVMonitorDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CAGVMonitorDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAGVMonitorDlg::OnModifyAGVIP()
{
GetDlgItem(IDC_AGVIP)->EnableWindow(TRUE);
GetDlgItem(IDC_SaveAGVIP)->EnableWindow(TRUE);
GetDlgItem(IDC_AGVConnect)->EnableWindow(FALSE);
}
void CAGVMonitorDlg::OnSaveAGVIP()
{
SaveAGVIPSetting();
GetDlgItem(IDC_AGVIP)->EnableWindow(FALSE);
GetDlgItem(IDC_SaveAGVIP)->EnableWindow(FALSE);
GetDlgItem(IDC_AGVConnect)->EnableWindow(TRUE);
}
void CAGVMonitorDlg::SaveAGVIPSetting()
{
TCHAR IniFullPath[MAX_PATH]="";
const char IniName[]="\\System.ini";
CString IniFullName,strIPAddress;
GetCurrentDirectory(sizeof(IniFullPath),IniFullPath);
IniFullName.Format("%s%s",IniFullPath,IniName);
GetDlgItem(IDC_AGVIP)->GetWindowText(strIPAddress);
WritePrivateProfileString ("TCP/IP", "AGVIP",strIPAddress,IniFullName);
}
void CAGVMonitorDlg::LoadAGVIPSetting()
{
TCHAR IniFullPath[MAX_PATH]="";
const char IniName[]="\\System.ini";
char _StrIni[MAX_PATH]="";
CString StrIni;
CString IniFullName;
GetCurrentDirectory(sizeof(IniFullPath),IniFullPath);
IniFullName.Format("%s%s",IniFullPath,IniName);
GetPrivateProfileString ("TCP/IP", "AGVIP","",_StrIni,sizeof(_StrIni),IniFullName);
StrIni.Format("%s",_StrIni);
GetDlgItem(IDC_AGVIP)->SetWindowText(StrIni);
}
void CAGVMonitorDlg::OnSettingAGVNowStation()
{
int index;
index=((CComboBox *)GetDlgItem(IDC_AGVNowStation))->GetCurSel();
if(index<0)
{
AfxMessageBox("请选择AGV初始位置!");
return;
}
else
{
gbAGVNowStation=index+MinAGVStationID;
ChangeStationLED(gbAGVNowStation);
m_AGVPathList.DeleteAllItems();
}
}
void CAGVMonitorDlg::ChangeStationLED(byte TurnOnStaition)
{
int i;
for(i=0;i<MaxAGVStation;i++)
if(m_Station_LED[i].IsLEDOn()==TRUE)
m_Station_LED[i].TurnOn(FALSE);
m_Station_LED[TurnOnStaition-MinAGVStationID].TurnOn(TRUE);
}
void CAGVMonitorDlg::OnSelchangeAGVStopMode()
{
int index;
index=((CComboBox *)GetDlgItem(IDC_AGVStopMode))->GetCurSel();
switch(index)
{
case StopAuto://到站停靠(自动离站)
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->ResetContent();
GetDlgItem(IDC_RollerRollingMode)->EnableWindow(TRUE);
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->AddString(gbRollerRollingMode[RollingLeft]);
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->AddString(gbRollerRollingMode[RollingRight]);
break;
case StopManual://到站停靠(手动离站)
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->ResetContent();
GetDlgItem(IDC_RollerRollingMode)->EnableWindow(FALSE);
break;
case StopEnd://终点停靠
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->ResetContent();
GetDlgItem(IDC_RollerRollingMode)->EnableWindow(TRUE);
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->AddString(gbRollerRollingMode[RollingNot]);
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->AddString(gbRollerRollingMode[RollingLeft]);
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->AddString(gbRollerRollingMode[RollingRight]);
break;
default:
((CComboBox *)GetDlgItem(IDC_RollerRollingMode))->ResetContent();
GetDlgItem(IDC_RollerRollingMode)->EnableWindow(FALSE);
break;
}
}
void CAGVMonitorDlg::OnSelchangeDestinationStation()
{
int index;
index=((CComboBox *)GetDlgItem(IDC_DestinationStation))->GetCurSel();
if(index>=0)
GetDlgItem(IDC_AGVStopMode)->EnableWindow(TRUE);
}
BOOL CAGVMonitorDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam==VK_ESCAPE)
return true;
if(pMsg->wParam==VK_RETURN)
return true;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CAGVMonitorDlg::OnEmptyAGVPathList()
{
if(MessageBox("是否清空AGV路线表?","删除",MB_YESNO|MB_ICONQUESTION)==IDYES)
m_AGVPathList.DeleteAllItems();
}
void CAGVMonitorDlg::OnAGVGoCarbarn()
{
CStringArray NewPath;
CString strItem;
byte SourceStation;
if(gbAGVNowStation==AGVCarbarnID)
{
AfxMessageBox("AGV已在车库位置!");
return;
}
if(gbAGVNowStation<MinAGVStationID)
{
AfxMessageBox("无法获知当前AGV位置,请进行AGV初始位置设置!");
return;
}
if(m_AGVPathList.GetItemCount()>0)
if(MessageBox("此操作将会清空路线表内信息,是否继续?","AGV回车库",MB_YESNO|MB_ICONQUESTION)==IDNO)
return;
m_AGVPathList.DeleteAllItems();
SourceStation=gbAGVNowStation;
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",AGVCarbarnID);
NewPath.Add(strItem);
NewPath.Add(gbAGVStopMode[StopEnd]);
NewPath.Add(gbRollerRollingMode[RollingNot]);
m_AGVPathList.AddItem(&NewPath);
}
void CAGVMonitorDlg::OnAGVInGoodsTransport()
{
CStringArray NewPath;
CString strItem;
byte SourceStation;
bool AutoMode=false;
if(gbAGVNowStation<MinAGVStationID)
{
AfxMessageBox("无法获知当前AGV位置,请进行AGV初始位置设置!");
return;
}
if(m_AGVPathList.GetItemCount()>0)
if(MessageBox("此操作将会清空路线表内信息,是否继续?","AGV入货运送",MB_YESNO|MB_ICONQUESTION)==IDNO)
return;
if(MessageBox("是否采用滚筒自动货物运送模式?","AGV入货运送",MB_YESNO|MB_ICONQUESTION)==IDYES)
AutoMode=true;
m_AGVPathList.DeleteAllItems();
SourceStation=gbAGVNowStation;
if(gbAGVNowStation!=AGVMaterielAreaID)
{
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",AGVMaterielAreaID);
NewPath.Add(strItem);
NewPath.Add(gbAGVStopMode[StopManual]);
NewPath.Add(gbRollerRollingMode[RollingNot]);
SourceStation=AGVMaterielAreaID;
m_AGVPathList.AddItem(&NewPath);
}
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",AGVInGoodsAreaID);
NewPath.Add(strItem);
NewPath.Add(gbAGVStopMode[StopEnd]);
if(AutoMode==true)
NewPath.Add(gbRollerRollingMode[RollingRight]);
else
NewPath.Add(gbRollerRollingMode[RollingNot]);
m_AGVPathList.AddItem(&NewPath);
}
void CAGVMonitorDlg::OnAGVOutGoodsTransport()
{
CStringArray NewPath;
CString strItem;
byte SourceStation;
bool AutoMode=false;
if(gbAGVNowStation<MinAGVStationID)
{
AfxMessageBox("无法获知当前AGV位置,请进行AGV初始位置设置!");
return;
}
if(m_AGVPathList.GetItemCount()>0)
if(MessageBox("此操作将会清空路线表内信息,是否继续?","AGV出货运送",MB_YESNO|MB_ICONQUESTION)==IDNO)
return;
if(MessageBox("是否采用滚筒自动货物运送模式?","AGV出货运送",MB_YESNO|MB_ICONQUESTION)==IDYES)
AutoMode=true;
m_AGVPathList.DeleteAllItems();
SourceStation=gbAGVNowStation;
if(gbAGVNowStation!=AGVOutGoodsAreaID)
{
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",AGVOutGoodsAreaID);
NewPath.Add(strItem);
if(AutoMode==true)
{
NewPath.Add(gbAGVStopMode[StopAuto]);
NewPath.Add(gbRollerRollingMode[RollingLeft]);
}
else
{
NewPath.Add(gbAGVStopMode[StopManual]);
NewPath.Add(gbRollerRollingMode[RollingNot]);
}
SourceStation=AGVOutGoodsAreaID;
m_AGVPathList.AddItem(&NewPath);
}
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",AGVMaterielAreaID);
NewPath.Add(strItem);
NewPath.Add(gbAGVStopMode[StopEnd]);
NewPath.Add(gbRollerRollingMode[RollingNot]);
m_AGVPathList.AddItem(&NewPath);
}
void CAGVMonitorDlg::OnAGVSupplyTransport()
{
byte i;
CStringArray NewPath;
CString strItem;
byte SourceStation;
if(gbAGVNowStation<MinAGVStationID)
{
AfxMessageBox("无法获知当前AGV位置,请进行AGV初始位置设置!");
return;
}
if(m_AGVPathList.GetItemCount()>0)
if(MessageBox("此操作将会清空路线表内信息,是否继续?","AGV补料运送",MB_YESNO|MB_ICONQUESTION)==IDNO)
return;
m_AGVPathList.DeleteAllItems();
SourceStation=gbAGVNowStation;
if(gbAGVNowStation!=AGVMaterielAreaID)
{
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",AGVMaterielAreaID);
NewPath.Add(strItem);
NewPath.Add(gbAGVStopMode[StopManual]);
NewPath.Add(gbRollerRollingMode[RollingNot]);
SourceStation=AGVMaterielAreaID;
m_AGVPathList.AddItem(&NewPath);
}
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",RollerStation01ID);
NewPath.Add(strItem);
NewPath.Add(gbAGVStopMode[StopManual]);
NewPath.Add(gbRollerRollingMode[RollingNot]);
SourceStation=RollerStation01ID;
m_AGVPathList.AddItem(&NewPath);
for(i=0;i<3;i++)
{
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",SourceStation+1);
NewPath.Add(strItem);
NewPath.Add(gbAGVStopMode[StopManual]);
NewPath.Add(gbRollerRollingMode[RollingNot]);
SourceStation++;
m_AGVPathList.AddItem(&NewPath);
}
NewPath.RemoveAll();
strItem.Format("%d",SourceStation);
NewPath.Add(strItem);
strItem.Format("%d",ChainStation01ID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -