修改RS232通信

This commit is contained in:
TAO Cheng
2013-07-01 16:23:02 +08:00
parent 61a49df5ee
commit 46fb8ed7b2
11 changed files with 123 additions and 255 deletions
@@ -1501,3 +1501,33 @@ Init:Open device succeed .
Destruct Cso7_Proto.
Construct Cso7_Proto.
Init:Open device succeed .
_start_machine
Exit: Exit_SO7Usb
Init:Open device succeed .
_start_machine
Construct Cso7_Proto.
Init:Open device succeed .
_start_machine
Exit: Exit_SO7Usb
Init:Open device succeed .
_start_machine
Exit: Exit_SO7Usb
Destruct Cso7_Proto.
Construct Cso7_Proto.
Init:Open device succeed .
_start_machine
Exit: Exit_SO7Usb
@@ -4,6 +4,7 @@
#include "afxdialogex.h"
#include "..\..\..\SevenOcean\CMMIO_SERIAL.H"
#include "..\..\..\SevenOcean\SO7_Proto.h"
#include "..\..\..\SevenOcean\CAutoZoom.h"
#include "ProcessButton.h"
#include "DrawGraph.h"
#include "SO7_Send_Parameter.h"
@@ -27,7 +28,7 @@ extern CPSerial* m_pSO7_PCDSerial;
extern CSO7_Proto* m_pSO7_Proto;
CLogger* g_pLoggerDebug=NULL;
CSO7_VolComp* g_pVolComp=NULL;
CAutoZoom* m_pSO7_AutoZoom=NULL;
IMPLEMENT_DYNAMIC(CSO7_UtilDlg, CDialog)
CSO7_UtilDlg::CSO7_UtilDlg(CWnd* pParent /*=NULL*/)
@@ -984,17 +985,17 @@ void CSO7_UtilDlg::OnBnClickedButtonLoadSo7config()
void CSO7_UtilDlg::OnBnClickedButtonSetupSo7config()
{
KillTimer(1);
if (!m_pSO7_PCDSerial)
m_pSO7_PCDSerial = new CPSerial();
if (!m_pSO7_AutoZoom)
m_pSO7_AutoZoom = new CAutoZoom();
CSetup_so7config* pSetup_so7config=new CSetup_so7config;
pSetup_so7config->DoModal();
delete pSetup_so7config;
if (m_pSO7_PCDSerial)
if (m_pSO7_AutoZoom)
{
delete m_pSO7_PCDSerial;
m_pSO7_PCDSerial=NULL;
delete m_pSO7_AutoZoom;
m_pSO7_AutoZoom=NULL;
}
SetTimer(1,150,NULL);
}
@@ -7,11 +7,10 @@
#include <math.h>
#include "ProcessButton.h"
#include "..\..\..\SevenOcean\SO7_Proto.h"
#include "..\..\..\SevenOcean\CMMIO_SERIAL.H"
#include "..\..\..\SevenOcean\CAutoZoom.h"
#include "Setup_so7config.h"
extern CPSerial* m_pSO7_PCDSerial;
extern CAutoZoom* m_pSO7_AutoZoom;
extern CSO7_Proto* m_pSO7_Proto;
#define PI 3.1415926535897932384626433
// CSetup_so7config dialog
@@ -96,9 +95,9 @@ BOOL CSetup_so7config::OnInitDialog()
m_pSO7_Proto->g_machine.zm._Move_Speed_Gear=2;
((CButton *)GetDlgItem(IDC_RADIO_SO7CONFIG_ZOOM_MOVE_FAST))->SetCheck(true);
if (m_pSO7_PCDSerial)
if (m_pSO7_AutoZoom)
{
if(m_pSO7_PCDSerial->Open())
if(m_pSO7_AutoZoom->Initialization(false))
{
ChangGUIWithStep(m_nStep);
m_csMsg.Format(_T("串口打开正常!"));
@@ -377,209 +376,6 @@ void CSetup_so7config::OnTimer(UINT_PTR nIDEvent)
}
//===============================================
double CSetup_so7config::ReadZoomAngle()
{
if (_bReading)
{
return -2;
}
else
{
_bReading=true;
double dZoomAngle(-1);
char sendData[6]={'A','D',':','0',13,10};
DWORD iWriteByte=m_pSO7_PCDSerial->Send(sendData,6);
INT iRetrys(0);
while(!m_pSO7_PCDSerial->m_iRecvState && iRetrys<20 && iWriteByte==6)
{
iRetrys++;
Sleep(10);
}
if (m_pSO7_PCDSerial->m_iRecvState)
{
if(m_pSO7_PCDSerial->m_RecvData[0]==0)
Sleep(40);//200
char *token = NULL;
char cTemp[20]={0};
char seps[] = "$AD:";
token = strtok(m_pSO7_PCDSerial->m_RecvData,seps);
if (token)
{
memcpy(cTemp,token,8);
dZoomAngle=atof(cTemp);
dZoomAngle=dZoomAngle*180/PI;
};
token=NULL;
m_pSO7_PCDSerial->m_iRecvState=FALSE;
_bReading=false;
return dZoomAngle;
}
else
{
_bReading=false;
return -2;
}
}
}
//===============================================
double CSetup_so7config::GetZoomCurPos()
{
double dZoomPos(0),dZoomAng(0),dZoomPreAng(0);
INT iCnt2(0);
INT iRetryCount(0);
dZoomAng=ReadZoomAngle();
while(iCnt2<3 && iRetryCount<20)
{
Sleep(60);
dZoomPreAng=dZoomAng;
dZoomAng=ReadZoomAngle();
INT iRetrys(0);
while ((dZoomAng==-1 || dZoomAng==-2 || dZoomAng==0 )&&iRetrys<2)
{
iRetrys++;
Sleep(60);
dZoomAng=ReadZoomAngle();
}
if(dZoomAng!=-1 && dZoomAng!=-2 && dZoomAng!=0)
{
if ((dZoomAng-dZoomPreAng)<1 && (dZoomPreAng-dZoomAng)<1)
{
dZoomPos+=dZoomAng;
iCnt2++;
}
}
iRetryCount++;
}
if (iCnt2==0)
{
dZoomPos=-2;
}
else
{
dZoomPos=dZoomPos/(iCnt2);
}
return dZoomPos;
}
//===============================================
BOOL CSetup_so7config::CalibrateEncoder()
{
char sendDataI[12]={'U','P',':','1','1','1','1','1','1','1',13,10};
char sendDataII[6]={'S','C',':','1',13,10};
char sendDataIII[6]={'R','F',':','1',13,10};
CString csRightRecv;
csRightRecv.Format(_T("@OK\r\n"));
CStringA m_csRecv("");
INT iRetrys(0);
DWORD iWriteByte(0);
m_pSO7_PCDSerial->m_iRecvState=FALSE;
//Phase I
iWriteByte=m_pSO7_PCDSerial->Send(sendDataI,12);
while(!m_pSO7_PCDSerial->m_iRecvState && iRetrys<20 && iWriteByte==12)
{
iRetrys++;
Sleep(50);
}
if (m_pSO7_PCDSerial->m_iRecvState)
{
if(m_pSO7_PCDSerial->m_RecvData[0]==0)
Sleep(100);
m_csRecv.Format(("%s"),m_pSO7_PCDSerial->m_RecvData);
if((CString)m_csRecv==csRightRecv)
{
m_pSO7_PCDSerial->m_iRecvState=FALSE;
iRetrys=0;
iWriteByte=0;
//Phase II
iWriteByte=m_pSO7_PCDSerial->Send(sendDataII,6);
while(!m_pSO7_PCDSerial->m_iRecvState && iRetrys<20 && iWriteByte==6)
{
iRetrys++;
Sleep(100);
}
if(m_pSO7_PCDSerial->m_iRecvState)
{
if(m_pSO7_PCDSerial->m_RecvData[0]==0)
Sleep(100);
m_csRecv.Format(("%s"),m_pSO7_PCDSerial->m_RecvData);
if((CString)m_csRecv==csRightRecv)
{
m_pSO7_PCDSerial->m_iRecvState=FALSE;
iRetrys=0;
iWriteByte=0;
//Phase III
iWriteByte=m_pSO7_PCDSerial->Send(sendDataIII,6);
while(!m_pSO7_PCDSerial->m_iRecvState && iRetrys<20 && iWriteByte==6)
{
iRetrys++;
Sleep(100);
}
if(m_pSO7_PCDSerial->m_iRecvState)
{
if(m_pSO7_PCDSerial->m_RecvData[0]==0)
Sleep(100);
m_csRecv.Format(("%s"),m_pSO7_PCDSerial->m_RecvData);
if((CString)m_csRecv==csRightRecv)
{
m_pSO7_PCDSerial->m_iRecvState=FALSE;
iRetrys=0;
iWriteByte=0;
return TRUE;
}
else
{
m_pSO7_PCDSerial->m_iRecvState=FALSE;
return FALSE;
}
}
else
{
return FALSE;
}
}
else
{
m_pSO7_PCDSerial->m_iRecvState=FALSE;
return FALSE;
}
}
else
{
return FALSE;
}
}
else
{
m_pSO7_PCDSerial->m_iRecvState=FALSE;
return FALSE;
}
}
else
{
return FALSE;
}
}
//===============================================
void CSetup_so7config::ChangGUIWithStep(int _step)
{
@@ -650,6 +446,21 @@ void CSetup_so7config::OnBnClickedCancel()
KillTimer(1);
CDialog::OnCancel();
}
//===============================================
double CSetup_so7config::ReadZoomAngle()
{
return m_pSO7_AutoZoom->ReadZoomAngle();
}
//===============================================
double CSetup_so7config::GetZoomCurPos()
{
return m_pSO7_AutoZoom->GetZoomCurPos();
}
//===============================================
BOOL CSetup_so7config::CalibrateEncoder()
{
return m_pSO7_AutoZoom->CalibrateEncoder();
}
@@ -306,6 +306,7 @@
<ClCompile Include="..\..\..\MicroVu\Mv_Proto.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\..\ThirdParty\UsbSupport\LibUsb_Win\Include</AdditionalIncludeDirectories>
</ClCompile>
<ClCompile Include="..\..\..\SevenOcean\CAutoZoom.cpp" />
<ClCompile Include="..\..\..\SevenOcean\CMMIO_BASE.CPP" />
<ClCompile Include="..\..\..\SevenOcean\CMMIO_SERIAL.CPP" />
<ClCompile Include="..\..\..\SevenOcean\EF8000_Interface.cpp" />
@@ -363,6 +364,7 @@
<ClInclude Include="..\..\..\Keyence\Keyence_Proto.h" />
<ClInclude Include="..\..\..\Keyence\LKIFCommonDefine.h" />
<ClInclude Include="..\..\..\MicroVu\Mv_Proto.h" />
<ClInclude Include="..\..\..\SevenOcean\CAutoZoom.h" />
<ClInclude Include="..\..\..\SevenOcean\CMD_H.h" />
<ClInclude Include="..\..\..\SevenOcean\CMMIO_BASE.H" />
<ClInclude Include="..\..\..\SevenOcean\CMMIO_SERIAL.H" />
@@ -136,6 +136,9 @@
<ClCompile Include="Videocard_SV4000E.cpp">
<Filter>Sources Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\SevenOcean\CAutoZoom.cpp">
<Filter>Sources Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CaptureDataDlg.h">
@@ -303,6 +306,9 @@
<ClInclude Include="Videocard_SV4000E.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\SevenOcean\CAutoZoom.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
@@ -5,4 +5,20 @@
#include "stdafx.h"
CString GetAppPath(void)
{
CWinApp* pApp=AfxGetApp();
if(pApp==0)
return _T("");
TCHAR buf[256];
GetModuleFileName(0,buf,256);
CString sAppPath(buf);
int nPos=sAppPath.ReverseFind('\\');
if(nPos)
sAppPath=sAppPath.Left(nPos);
return sAppPath;
}
@@ -49,19 +49,6 @@
#endif
#endif
static CString GetAppPath()
{
CWinApp* pApp=AfxGetApp();
if(pApp==0)
return _T("");
CString GetAppPath(void);
TCHAR buf[256];
GetModuleFileName(0,buf,256);
CString sAppPath(buf);
int nPos=sAppPath.ReverseFind('\\');
if(nPos)
sAppPath=sAppPath.Left(nPos);
return sAppPath;
}