?? xspview.cpp
字號:
// xspView.cpp : implementation of the CXspView class
//
#include "stdafx.h"
#include "xsp.h"
#include "xspDoc.h"
#include "xspView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define stop 0
#define moveframe 1
#define dotrun 2
#define stopdown 3
#define cutline 4
#define systest 5
#define changecolor 6
#define stopmoveframe 7
#define backhome 8
#define exitdx 9
#define getstatus 10
#define writedata 11
#define lala 6
/////////////////////////////////////////////////////////////////////////////
// CXspView
IMPLEMENT_DYNCREATE(CXspView, CFormView)
BEGIN_MESSAGE_MAP(CXspView, CFormView)
//{{AFX_MSG_MAP(CXspView)
ON_WM_CREATE()
ON_BN_CLICKED(IDC_ONE, OnOne)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_JIANSU, OnJiansu)
ON_BN_CLICKED(IDC_SHENSU, OnShensu)
ON_WM_TIMER()
ON_WM_PAINT()
ON_BN_CLICKED(IDC_TWO, OnTwo)
ON_BN_CLICKED(IDC_THREE, OnThree)
ON_BN_CLICKED(IDC_FOUR, OnFour)
ON_BN_CLICKED(IDC_FIVE, OnFive)
ON_BN_CLICKED(IDC_SIX, OnSix)
ON_BN_CLICKED(IDC_SEVEN, OnSeven)
ON_BN_CLICKED(IDC_EIGHT, OnEight)
ON_BN_CLICKED(IDC_NINE, OnNine)
ON_BN_CLICKED(IDC_LEFT, OnLeft)
ON_BN_CLICKED(IDC_RIGHT, OnRight)
ON_BN_CLICKED(IDC_UP, OnUp)
ON_BN_CLICKED(IDC_DOWN, OnDown)
ON_BN_CLICKED(IDC_SPEED, OnSpeed)
ON_BN_CLICKED(IDC_CIXIU, OnCixiu)
ON_BN_CLICKED(IDC_DOTRUN, OnDotrun)
ON_BN_CLICKED(IDC_STOPDOWN, OnStopdown)
ON_BN_CLICKED(IDC_BACKORG, OnBackorg)
ON_BN_CLICKED(IDC_JIANXIAN, OnJianxian)
ON_BN_CLICKED(IDC_JXTEST, OnJxtest)
ON_BN_CLICKED(IDC_KXTEST, OnKxtest)
ON_BN_CLICKED(IDC_GXTEST, OnGxtest)
ON_BN_CLICKED(IDC_DXCHECK, OnDxcheck)
ON_BN_CLICKED(IDC_EXITDXCHECK, OnExitdxcheck)
ON_BN_CLICKED(IDC_ZERO, OnZero)
ON_BN_CLICKED(IDC_TESTSPEED, OnTestspeed)
ON_BN_CLICKED(IDC_SHAKE, OnShake)
ON_BN_CLICKED(IDC_CHANGEPARA, OnChangepara)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXspView construction/destruction
CXspView::CXspView()
: CFormView(CXspView::IDD)
{
//{{AFX_DATA_INIT(CXspView)
m_paradata = 0;
m_paraindex = 0;
//}}AFX_DATA_INIT
// TODO: add construction code here
stepcount=0;
speed=10;
movespeed=2;
realspeed=500;
haveset=0;
systemstatus=0;
runstatus=stop;
X=0;
Y=0;
MotorInfo=0;
BHZinfo=0;
needle=1;
needleerror=0x80;
jx_status=0;
gx_status=0;
positionlimit=0;
Z=0;
breakline=0;
polestatus=0;
needlecount=0;
for(int i=0;i<10;i++)
{
Xstep[2*i]=0;Ystep[2*i]=lala;
Xstep[2*i+1]=0;Ystep[2*i+1]=0x100-lala;
}
for(i=10;i<15;i++)
{
Xstep[2*i]=0x100-lala;Ystep[2*i]=0;
Xstep[2*i+1]=lala;Ystep[2*i+1]=0;
}
for(i=15;i<25;i++)
{
Xstep[2*i]=0x100-lala;Ystep[2*i]=0x100-lala;
Xstep[2*i+1]=lala;Ystep[2*i+1]=lala;
}
for(i=25;i<30;i++)
{
Xstep[2*i]=lala;Ystep[2*i]=0x100-lala;
Xstep[2*i+1]=0x100-lala;Ystep[2*i+1]=lala;
}
}
CXspView::~CXspView()
{
}
void CXspView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXspView)
DDX_Control(pDX, IDC_RUNSTATUS, m_runstatus);
DDX_Control(pDX, IDC_SYSSTATUS, m_sysstatus);
DDX_Control(pDX, IDC_NEEDLEINDEX, m_needle);
DDX_Control(pDX, IDC_ZSTATUS, m_z);
DDX_Control(pDX, IDC_YZUOBIAO, m_y);
DDX_Control(pDX, IDC_XZUOBIAO, m_x);
DDX_Control(pDX, IDC_POSLIMIT, m_poslimit);
DDX_Control(pDX, IDC_POLESTATUS, m_polestatus);
DDX_Control(pDX, IDC_MOTORINFO, m_motorinfo);
DDX_Control(pDX, IDC_JXSTATUS, m_jxstatus);
DDX_Control(pDX, IDC_GXSTATUS, m_gxstatus);
DDX_Control(pDX, IDC_BREAKLINE, m_breakline);
DDX_Control(pDX, IDC_BHZSTATUS, m_bhzstatus);
DDX_Control(pDX, IDC_BUTTONSCREEN, m_screen);
DDX_Control(pDX, IDC_SPEEDVALUE, m_speed);
DDX_Control(pDX, IDC_MSCOMM1, m_comm);
DDX_Text(pDX, IDC_PARADATA, m_paradata);
DDV_MinMaxInt(pDX, m_paradata, 0, 1000);
DDX_Text(pDX, IDC_INDEX, m_paraindex);
DDV_MinMaxByte(pDX, m_paraindex, 0, 255);
//}}AFX_DATA_MAP
}
BOOL CXspView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CXspView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CXspView printing
BOOL CXspView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CXspView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CXspView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CXspView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CXspView diagnostics
#ifdef _DEBUG
void CXspView::AssertValid() const
{
CFormView::AssertValid();
}
void CXspView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CXspDoc* CXspView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CXspDoc)));
return (CXspDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CXspView message handlers
int CXspView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
BEGIN_EVENTSINK_MAP(CXspView, CFormView)
//{{AFX_EVENTSINK_MAP(CXspView)
ON_EVENT(CXspView, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CXspView::OnOnCommMscomm1()
{
// TODO: Add your control notification handler code here
VARIANT m_input;
int k,nEvent;
unsigned char *pBuf;
//unsigned char m_RcvData[8];
nEvent=m_comm.GetCommEvent();
switch(nEvent)
{
case 2:
k=m_comm.GetInBufferCount();
if(k>0)
{
m_input=m_comm.GetInput();
pBuf=(unsigned char*)m_input.parray->pvData;
}
ProtocolDeal(pBuf);
break;
}
}
void CXspView::SendData(unsigned char *pBuf)
{
int i;
unsigned char m_SendData[8];
unsigned int kk;
kk=0;
for(i=0;i<7;i++)
kk+=*(pBuf+i);
for(i=0;i<7;i++)
m_SendData[i]=*(pBuf+i);
m_SendData[7]=kk&0x00ff;
CByteArray m_Array;
m_Array.RemoveAll();
m_Array.SetSize(8);
for(i=0;i<8;i++)
m_Array.SetAt(i,m_SendData[i]);
m_comm.SetOutput(COleVariant(m_Array));
}
void CXspView::OnButton1()
{
// TODO: Add your control notification handler code here
CRect rect;
m_screen.GetClientRect(&rect);
m_point.x=rect.Width()*5;
m_point.y=rect.Height()*5;
m_point1=m_point;
haveset=1;
m_comm.SetCommPort(4);
m_comm.SetInputMode(1);
m_comm.SetSettings("115200,n,8,1");
m_comm.SetRThreshold(8);
m_comm.SetInputLen(0);
if(!m_comm.GetPortOpen())
{
m_comm.SetPortOpen(TRUE);
}
m_comm.GetInput();
m_speed.SetWindowText("");
m_bhzstatus.SetWindowText("");
m_x.SetWindowText("");
m_y.SetWindowText("");
m_z.SetWindowText("");
m_jxstatus.SetWindowText("");
m_gxstatus.SetWindowText("");
m_poslimit.SetWindowText("");
m_breakline.SetWindowText("");
m_polestatus.SetWindowText("");
m_motorinfo.SetWindowText("");
m_needle.SetWindowText("");
m_sysstatus.SetWindowText("");
m_runstatus.SetWindowText("串口打開");
systemstatus=0;
unsigned char hehe[8];
hehe[0]=0xcd;
hehe[1]=0x0f;
hehe[2]=0x00;
hehe[3]=0x00;
hehe[4]=0x00;
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0xdc;
SendData(hehe);
SetTimer(1,100,NULL);
}
void CXspView::ProtocolDeal(unsigned char *pBuf)
{
unsigned char i;
unsigned char hehe[8];
if(*pBuf==0xbd)
{
i=*(pBuf+1);
switch(i)
{
case 0xaa:
for(i=0;i<8;i++)
hehe[i]=*(pBuf+i);
break;
/*case 0x0b:
hehe[0]=0xcd;
hehe[1]=0xee;
hehe[2]=0;
hehe[3]=0;
hehe[4]=0;
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0x90;
SendData(hehe);
break;*/
case 0x0e:
MotorInfo= *(pBuf+2);
jx_status= ((*(pBuf+3))>>6)&0x01;
gx_status= ((*(pBuf+3))>>4)&0x01;
BHZinfo= ((*(pBuf+3))>>2)&0x01;
Z= (*(pBuf+3))&0x01;
polestatus= (*(pBuf+4))&0x0f;
needle= (*(pBuf+5))&0x0f;
needleerror=(*(pBuf+5))&0x80;
positionlimit=(*(pBuf+6));
break;
case 0x81:
speed=*(pBuf+6)*10;
stepcount++;
if(stepcount==60)
{
stepcount=0;
}
if(stepcount<=59)
{
hehe[0]=0xcd;
hehe[1]=0x01;
hehe[2]=realspeed/10;
hehe[3]=Xstep[stepcount];
hehe[4]=Ystep[stepcount];
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0x90;
SendData(hehe);
}
break;
case 0x82:
stepcount=0;
break;
case 0x83:
stepcount=0;
break;
case 0x84:
stepcount=0;
break;
case 0x85:
case 0x86:
case 0x87:
stepcount=0;
break;
case 0x88:
case 0x90:
case 0xa0:
case 0xc0:
stepcount=0;
break;
}
}
}
void CXspView::OnJiansu()
{
// TODO: Add your control notification handler code here
CString str;
if(realspeed<=80)
return;
realspeed-=50;
OnTestspeed() ;
}
void CXspView::OnShensu()
{
// TODO: Add your control notification handler code here
CString str;
if(realspeed>=1000)
return;
realspeed+=50;
OnTestspeed() ;
}
void CXspView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString str;
if(nIDEvent==1)
{
str.Format("%d/%d rpm",speed,realspeed);
m_speed.SetWindowText(str);
if(BHZinfo==0x01)
m_bhzstatus.SetWindowText("到位");
else
m_bhzstatus.SetWindowText("不到位");
str.Format("%d",X);
m_x.SetWindowText(str);
str.Format("%d",Y);
m_y.SetWindowText(str);
if(systemstatus==0)
m_sysstatus.SetWindowText("刺繡準備");
else if(systemstatus==1)
m_sysstatus.SetWindowText("刺繡確認");
else if(systemstatus==2)
m_sysstatus.SetWindowText("刺繡");
if(Z==0x01)
m_z.SetWindowText("停車到位");
else
m_z.SetWindowText("停車不到位");
if(jx_status==0x01)
m_jxstatus.SetWindowText("剪線到位");
else
m_jxstatus.SetWindowText("剪線不到位");
if(gx_status==0x01)
m_gxstatus.SetWindowText("勾線到位");
else
m_gxstatus.SetWindowText("勾線不到位");
str="";
if((positionlimit&0x01)==0x01)
str+="X+ ";
if((positionlimit&0x02)==0x02)
str+="X- ";
if((positionlimit&0x04)==0x04)
str+="Y+ ";
if((positionlimit&0x08)==0x08)
str+="Y- ";
m_poslimit.SetWindowText(str);
if(breakline==0x00)
m_breakline.SetWindowText("無斷線");
else
m_breakline.SetWindowText("斷線");
if(polestatus==0x08)
m_polestatus.SetWindowText("左拉桿");
else if(polestatus==0x02)
m_polestatus.SetWindowText("右拉桿");
else
m_polestatus.SetWindowText("無拉桿");
if(MotorInfo==0x01)
m_motorinfo.SetWindowText("主電機正常");
else
m_motorinfo.SetWindowText("主電機異常");
if(needleerror==0x80)
{
str.Format("%d",needle);
m_needle.SetWindowText(str);
}
else
{
m_needle.SetWindowText("針號異常");
}
}
CFormView::OnTimer(nIDEvent);
}
void CXspView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CFormView::OnPaint() for painting messages
}
void CXspView::OnOne()
{
// TODO: Add your control notification handler code here
unsigned char hehe[8];
unsigned char tt=0;
if(systemstatus==0)
{
hehe[0]=0xcd;
hehe[1]=0x07;
hehe[2]=0x01;
hehe[3]=0x00;
hehe[4]=0x00;
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0x94;
SendData(hehe);
}
else if(systemstatus==1)
{
hehe[0]=0xcd;
hehe[1]=0x07;
hehe[2]=0x01;
hehe[3]=0x00;
hehe[4]=0x00;
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0x94;
SendData(hehe);
}
}
void CXspView::OnTwo()
{
// TODO: Add your control notification handler code here
unsigned char hehe[8];
if(systemstatus==0)
{
hehe[0]=0xcd;
hehe[1]=0x07;
hehe[2]=0x02;
hehe[3]=0x00;
hehe[4]=0x00;
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0x95;
SendData(hehe);
}
else if(systemstatus==1)
{
hehe[0]=0xcd;
hehe[1]=0x07;
hehe[2]=0x02;
hehe[3]=0x00;
hehe[4]=0x00;
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0x95;
SendData(hehe);
}
}
void CXspView::OnThree()
{
// TODO: Add your control notification handler code here
unsigned char hehe[8];
if(systemstatus==0)
{
hehe[0]=0xcd;
hehe[1]=0x07;
hehe[2]=0x03;
hehe[3]=0x00;
hehe[4]=0x00;
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0x96;
SendData(hehe);
}
else if(systemstatus==1)
{
hehe[0]=0xcd;
hehe[1]=0x07;
hehe[2]=0x03;
hehe[3]=0x00;
hehe[4]=0x00;
hehe[5]=0x00;
hehe[6]=0x00;
hehe[7]=0x96;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -