📄 stickslipview.cpp
字号:
MessageBox("图片已存入指定路径?","成功", MB_OK);
///////////////
}
void CStickSlipView::OnStop()
{
// TODO: Add your control notification handler code here
STOPa=TRUE;
DP_OutpB(0x30B,0x30);
DP_OutpB(0x30B,0x70);//
DP_OutpB(0x307,0x00);
DP_OutpB(0x307,0x02);//04.4.3 锁存???
timeKillEvent( timerID);
timeEndPeriod(wTimerRes);
InitialCtrl();
}
void CStickSlipView::CreateDisplay()
{
/////////////////////////////////
CRect m_ForceWave;
CRect m_DisplaceWave;
CWnd *pPosWnd1 = GetDlgItem(IDC_DISPLAY1);
pPosWnd1->GetWindowRect(m_DisplaceWave);
ScreenToClient(m_DisplaceWave);
CInspector *pIns = CInspector::Instance();
pIns->X_length=XLength;
pIns->X_Unit=XUnit;
pIns->X_Scale=XScale;
pIns->FY_length=FYLength;
pIns->FY_Unit=FYUnit;
pIns->FY_Scale=FYScale;
pIns->DY_length=DYLength;
pIns->DY_Unit=DYUnit;
pIns->DY_Scale=DYScale;
pIns->CreateDisplaceWaveDisplay(m_DisplaceWave,this);
CWnd *pPosWnd2 = GetDlgItem(IDC_DISPLAY2);
pPosWnd2->GetWindowRect(m_ForceWave);
ScreenToClient(m_ForceWave);
pIns->CreateForceWaveDisplay(m_ForceWave,this);//CreateCirDisplay(m_CirPos,this);
}
void CStickSlipView::OnReadData()
{
// TODO: Add your control notification handler code here
CString m_dataPath;
ifstream dfile;
const int NUM = 7200;
DataArray.RemoveAll();
//DataTxtPath="..\\Displace.txt";
//////////////////////////////////////////////////////////////////////////
// char szFileFilter[]=
// "txt(*.txt)|*.txt|"
// "All File(*.*)|*.*||";
//CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFileFilter);
// if(dlg.DoModal()==IDOK)
// {
CInputdataDlg idlg;
idlg.DoModal();
if ( idlg.m_dispPath.GetLength()<=0|| idlg.m_forcPath.GetLength()<=0||
idlg.m_timPath.GetLength()<=0)
{
return;
}
// double ForceData[DNUMBERS];//力数据
// double DisplaceData[DNUMBERS];//位移数据
// double TimeData[DNUMBERS];//时间数据
m_dataPath=idlg.m_timPath;
dfile.open(m_dataPath);
int j = 0;
double idata;
Index=0;
while(!dfile.eof())
{
dfile >> idata;
m_PointData.displace=0.0;
m_PointData.force=0.0;
m_PointData.pointtime=idata;
DataArray.SetAtGrow(j,m_PointData);
//Index++;
//DisplaceData[j] = idata;
j++;
}
dfile.close();
//DataArray.Get
DataArray.RemoveAt(j-1);
//////////////////////////////////////////////////////////////////////////
int mLength=DataArray.GetSize();
m_dataPath=idlg.m_forcPath;
dfile.open(m_dataPath);
j = 0;
idata=0;
while(!dfile.eof())
{
dfile >> idata;
if (j<mLength)
{
DataArray[j].force=idata;
}
j++;
}
dfile.close();
/////////////////////////////////////////////
m_dataPath=idlg.m_dispPath;
dfile.open(m_dataPath);
j = 0;
idata=0;
while(!dfile.eof())
{
dfile >> idata;
if (j<DataArray.GetSize())
{
DataArray[j].displace=idata;
}
j++;
}
dfile.close();
//CString PathName
//m_dataPath +=".txt";
// ASSERT( j == NUM + 1);
//////////////////////////////////
//CString temp,temp1;
//转速
//m_rpm.GetLBText(m_rpm.GetCurSel(),temp);
//m_displace.GetLBText(m_displace.GetCurSel(),temp1);
//double m_time;
//m_time=atof(temp1)/(atof(temp)*4/60);
///////////////////////////////////
//PointNum=((int)m_time)*1000/PERIOD;
GetDlgItem(IDC_SHOW_GRAPH)->EnableWindow(TRUE);
//}
}
void CStickSlipView::WriteData(CString PathName)
{
CStdioFile dfile;
CString strPath=PathName;
int pos=strPath.Find(".txt",strPath.GetLength()-5);//strPath.ReverseFind();
if (pos!=-1)
{
strPath=strPath.Left(pos);
}
dfile.Open(strPath+".displace.txt",CFile::modeCreate |
CFile::modeWrite | CFile::shareDenyWrite);
CString dstr;
for(int j = 0;j <DataArray.GetSize();j++)
{
dstr.Format("%f \n",DataArray[j].displace);//DATA[j]
dfile.WriteString(dstr);
}//写数据到文件
dfile.Close();
//
dfile.Open(strPath+".force.txt",CFile::modeCreate |
CFile::modeWrite | CFile::shareDenyWrite);
//CString dstr;
for( j = 0;j <DataArray.GetSize();j++)
{
dstr.Format("%f \n",DataArray[j].force );//DATA[j]
dfile.WriteString(dstr);
}//写数据到文件
dfile.Close();
//
dfile.Open(strPath+".time.txt",CFile::modeCreate |
CFile::modeWrite | CFile::shareDenyWrite);
// CString dstr;
for( j = 0;j <DataArray.GetSize();j++)
{
dstr.Format("%f \n",(double)DataArray[j].pointtime);//DATA[j]
dfile.WriteString(dstr);
}//写数据到文件
dfile.Close();
}
LRESULT CStickSlipView::OnTimerMessage(WPARAM wParam,LPARAM lParam)
{
//delay(100); //修改于5.20
if (duqu8253_1()==0)
{
m+=1;
DP_OutpB(0x30B,0x30); //控制字
DP_OutpB(0x308,0xFF);
DP_OutpB(0x308,0xFF); //高位低位都要送初始值 //
}
else
{
}
m_PointData.displace=(65535-duqu8253_1())*0.00008; //(m*(65535-(duqu8253_1()))-(65535-(duqu8253_0())))*0.00008;//
// m_PointData.displace=((m-1)*65535+(65535-duqu8253_0()))*0.00008; //某一方向的位移,修改于5.24
m_PointData.force=(65535-duqu8253_0())*0.00008;//duquAD(); //duquAD()为电压信号,须转化为力信号。
m_PointData.pointtime=(Index);
DataArray.SetAtGrow(Index,m_PointData);
Index++;
if (Index>(PointNum-1))
{
timeKillEvent( timerID);
timeEndPeriod(wTimerRes);
}
/*
static short i=0;
i++;
account+=1;
CClientDC dc(this);
CPen pen(PS_SOLID,5,RGB(255,0,0));
CPen *pOldpen =dc.SelectObject(&pen);
dc.MoveTo(30,30);
dc.LineTo(100,100+i);
char temp[128];
itoa(account,temp,10);
dc.TextOut(140,140,temp);
dc.SelectObject(pOldpen);
*/
static short i=0;
i++;
m_runProgress.SetPos(i);
if (i>=100)
{
i=0;
}
return 0;
}
void CALLBACK Proc(UINT timerID,UINT msg,
DWORD dwUser,DWORD dw1,DWORD dw2)
{
/*
POSITION pos=AfxGetApp()->GetFirstDocTemplatePosition();
CDocTemplate *pDocTemplate =AfxGetApp()->GetNextDocTemplate(pos);
pos=pDocTemplate->GetFirstDocPosition();
CDocument *pDoc=pDocTemplate->GetNextDoc(pos);
pos=pDoc->GetFirstViewPosition();
CMtimerExampView *pView=
(CMtimerExampView*)pDoc->GetNextView(pos);
pView->OnMyMessage(1,1);
*/
//CUpInsDataDlg *pDlg=(CUpInsDataDlg *)AfxGetApp()->GetMainWnd();
//pDlg->OnTimerMessage(2,3);
CMainFrame * pMain=NULL;
CStickSlipView* pView=NULL;
pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;
pView=(CStickSlipView*)pMain->GetActiveView();
pView->OnTimerMessage(2,3);
}
void CStickSlipView::DestroyStop()
{
OnStop();
}
void CStickSlipView::chushihua()
{
//初始化8255
DP_OutpB(0x307,0x80); //控制字对c口的操作是通过向控制字写数据实现的
DP_OutpB(0x307,0x01);
DP_OutpB(0x307,0x03);
DP_OutpB(0x307,0x05);
DP_OutpB(0x307,0x07);
DP_OutpB(0x307,0x0B);
DP_OutpB(0x307,0x0C);
DP_OutpB(0x307,0x0F);
// DP_OutpB(0x307,0x09); //改动2004-5-19
UpdateData(TRUE);
if (m_movedir==1)
DP_OutpB(0x307,0x08);
else
DP_OutpB(0x307,0x09);
//初始化8253计数器
DP_OutpB(0x30B,0x30); //控制字
// DP_OutpB(0x30B,0x34); //自装载初始值5.26
DP_OutpB(0x308,0xFF); //设置通道0的初值
DP_OutpB(0x308,0xFF);
DP_OutpB(0x30B,0x70);
// DP_OutpB(0x30B,0x74); //自装载初始值5.26
DP_OutpB(0x309,0xFF); //设置通道1的初值
DP_OutpB(0x309,0xFF);
DP_OutpB(0x30B,0x96);
DP_OutpB(0x30A,0x04); //设置通道2的初值
//初始化AD采集卡
int basea;
basea=0x280; //板基地址0X280,选通AD转换卡1通道
DP_OutpB(0x280,0x01);
}
long int CStickSlipView::duqu8253_0()
{
//读 8253 计数器通道0
long int x,xl,xh; //修改04.4.3给定初始条件
DP_OutpB(0x30B,0x00);//
xl=_inp(0X308);
xh=_inp(0X308);
x=256*xh+xl;
return(x);
}
long int CStickSlipView::duqu8253_1()
{
//读 8253 计数器通道1
long int y,yl,yh;
DP_OutpB(0x30B,0x40);
yl=_inp(0X309);
yh=_inp(0X309);
y=256*yh+yl;
return(y);
}
float CStickSlipView::duquAD()
{
//读取AD卡转换的力数据
int dbyte;
float Fvalue;
DP_OutpB(0x280,0x01);
do
;
while (!(_inp(0x285)&0x80)); //可以将basea=0x280,转换成地址值
dbyte=_inp(0x281)|((_inp(0x282)&0x0F)<<8);
Fvalue=(float)(dbyte-2047)*10/4096;
Fvalue=(Fvalue-0.009569)/0.197019;
//待处理
//已修改5.24//
return(Fvalue);
}
void CStickSlipView::ChuSH8253F()
{
CString temp,temp1;
//转速
m_rpm.GetLBText(m_rpm.GetCurSel(),temp1);
m_displace.GetLBText(m_displace.GetCurSel(),temp);
//double m_time;
long int sz,sy,f0;
sz=((int)atof(temp))/5; //(m_displace)/5,5表示螺距;
sy=10000; //+((int)atof(temp)-5*(sz))*10000/5;
f0=3000/((int)atof(temp1));
/* int intemp=(int)atof(temp);
int intemp1=(int)atof(temp1);
if(intemp==120&&intemp1==300)
{sz=20;
sy=10000;
f0=10;
}
else
{}
*/
long int AL,AH,FL,FH;
DP_OutpB(0x313,0x11); //设置通道0为模式0
DP_OutpB(0x310,sz); //设置通道0的初值
//change 5.24
DP_OutpB(0x313,0x74); //设置通道1为模式2
AH=sy/256;
AL=sy-256*AH;
DP_OutpB(0x311,AL);
DP_OutpB(0x311,AH); //设置通道1的初值
DP_OutpB(0x313,0xB5); //设置通道2为模式2 DP_OutpB(0x313,0xB4);FH=f0/256; FL=f0-256*FH;
FH=f0/100;
FL=f0-100*FH;
DP_OutpB(0x312,FL);
DP_OutpB(0x312,FH); //设置通道2的初值
}
void CStickSlipView::OnMoveLdir()
{
// TODO: Add your control notification handler code here
}
void CStickSlipView::OnMoveRdir()
{
// TODO: Add your control notification handler code here
}
void CStickSlipView::testlib()
{
/* int t=4;
set_base_address(0x340); //设置HIT6503的基地址为0x340
reset(); //HIT6503复位
set_1(); //设置当前轴为1轴
clr_status(); //清除状态字
set_smpl_time(t); //设置采样时间为400微妙
mtr_on(); //允许闭环伺服控制
axis_on(); //当前轴使能
lmts_off(); //限位开关功能关断
set_output_dac16(); //设定输出为DAC16方式
set_kp(8); //设定KP 为8
set_ki(0); //设定KI 为0
set_kd(0); //设定KD 为0
set_i_lm(0x0608); //建立积分限为0x0608
set_kvff(0); //设定KVFF 为0
set_pos_err(30000); //建立位置误差限为30000
set_prfl_vel(); //建立运动轨迹为速度模式
set_vel(65536*5); //设置速度为65536*5/65536个脉冲/采样周期
set_acc(800); //设置加速度为800/65536个脉冲/采样周期/采样周期
update(); //启动运行
return;
get_pos();
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -