修改RS232通信
This commit is contained in:
@@ -156,8 +156,17 @@ EXP BOOL WINAPI LKIF_GetStorobeTime(OUT LKIF_STOROBETIME *StorobeTime);
|
||||
///////////////////////////////////////////////
|
||||
// Mode Change Command
|
||||
//
|
||||
// Mode Switch
|
||||
EXP BOOL WINAPI LKIF_SetMode(IN LKIF_MODE Mode);
|
||||
///////////////////////////////////////////////
|
||||
// USB Setting Command
|
||||
//
|
||||
#define USBPORTNO_MIN 1
|
||||
#define USBPORTNO_MAX 13
|
||||
// Enumerate Port Number Function (array of 13 ports)
|
||||
EXP BOOL WINAPI LKIF_EnumPortNo(BOOL IsValidPortNo[USBPORTNO_MAX]);
|
||||
// Set Port Number Function (1 to 13)
|
||||
EXP BOOL WINAPI LKIF_SetPortNo(int PortNo);
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif // LKIF_INCLUDED
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#define MAX_OUTPUT_BUFFER_SIZE 2048
|
||||
#define MAX_RECIEVE_BUFFER_SIZE 30000
|
||||
|
||||
// TCP, serial style routines
|
||||
struct SerialList
|
||||
{
|
||||
|
||||
@@ -222,6 +222,9 @@ int CPSerial::SetPort(int Port,int Baud,char Parity,int Bits,int StopBits,int Ha
|
||||
Bits = m_Bits;
|
||||
if(StopBits == 0)
|
||||
StopBits = m_StopBits;
|
||||
if (HandShake==0)
|
||||
HandShake=m_HandShake;
|
||||
|
||||
|
||||
// If the values are ok then store them
|
||||
if( ProgramPort( Port, Baud, Parity, Bits, StopBits, HandShake ) )
|
||||
@@ -481,21 +484,16 @@ void CPSerial::OnReceive()
|
||||
{
|
||||
// Dummy OnReceieve if not used
|
||||
char s[MAX_RECIEVE_BUFFER_SIZE]={0};
|
||||
|
||||
s[1]='\0';
|
||||
CurrentPointer = 0;
|
||||
int num=0;
|
||||
num = ReadPort(s, MAX_RECIEVE_BUFFER_SIZE);
|
||||
|
||||
if (num>0)
|
||||
int num = ReadPort(s, MAX_RECIEVE_BUFFER_SIZE);
|
||||
if ((num>0) && (num<MAX_RECIEVE_BUFFER_SIZE))
|
||||
{
|
||||
memset(m_RecvData,0,MAX_RECIEVE_BUFFER_SIZE);
|
||||
memcpy(m_RecvData,s, num);
|
||||
m_iRecvBytes=num;
|
||||
|
||||
m_iRecvState=TRUE;
|
||||
m_iRecvBytes=num;
|
||||
m_iRecvState=TRUE;
|
||||
}
|
||||
|
||||
//LineReceive(s, num);
|
||||
}
|
||||
|
||||
@@ -629,14 +627,18 @@ int CPSerial::ProgramPort(int Port,int Baud,char Parity,int Bits,int StopBits,in
|
||||
SerialDCB.fDtrControl = DTR_CONTROL_ENABLE;
|
||||
break;
|
||||
case CS_HANDSHAKE_FOR_SO7:
|
||||
SerialDCB.XonChar = 17;
|
||||
SerialDCB.XoffChar = 19;
|
||||
SerialDCB.fRtsControl = RTS_CONTROL_DISABLE;
|
||||
SerialDCB.fDtrControl = DTR_CONTROL_DISABLE;
|
||||
SerialDCB.fDsrSensitivity=FALSE;
|
||||
SerialDCB.XonLim=512;
|
||||
SerialDCB.XoffLim=1;
|
||||
break;
|
||||
SerialDCB.fDsrSensitivity=FALSE;
|
||||
SerialDCB.XonChar = 17;
|
||||
SerialDCB.XoffChar = 19;
|
||||
SerialDCB.fOutX=FALSE;
|
||||
SerialDCB.fInX=FALSE;
|
||||
SerialDCB.fErrorChar=FALSE;
|
||||
SerialDCB.fRtsControl=RTS_CONTROL_ENABLE;
|
||||
SerialDCB.fDtrControl = DTR_CONTROL_ENABLE;
|
||||
SerialDCB.fOutxCtsFlow=FALSE;
|
||||
SerialDCB.fOutxDsrFlow=FALSE;
|
||||
SerialDCB.XonLim=2048;
|
||||
SerialDCB.XoffLim=512;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -689,13 +691,18 @@ int CPSerial::ProgramPort(int Port,int Baud,char Parity,int Bits,int StopBits,in
|
||||
SerialDCB.fDtrControl = DTR_CONTROL_ENABLE;
|
||||
break;
|
||||
case CS_HANDSHAKE_FOR_SO7:
|
||||
SerialDCB.XonChar = 17;
|
||||
SerialDCB.XoffChar = 19;
|
||||
SerialDCB.fRtsControl = RTS_CONTROL_DISABLE;
|
||||
SerialDCB.fDtrControl = DTR_CONTROL_DISABLE;
|
||||
SerialDCB.fDsrSensitivity=FALSE;
|
||||
SerialDCB.XonLim=512;
|
||||
SerialDCB.XoffLim=1;
|
||||
SerialDCB.fDsrSensitivity=FALSE;
|
||||
SerialDCB.XonChar = 17;
|
||||
SerialDCB.XoffChar = 19;
|
||||
SerialDCB.fOutX=FALSE;
|
||||
SerialDCB.fInX=FALSE;
|
||||
SerialDCB.fErrorChar=FALSE;
|
||||
SerialDCB.fRtsControl=RTS_CONTROL_ENABLE;
|
||||
SerialDCB.fDtrControl = DTR_CONTROL_ENABLE;
|
||||
SerialDCB.fOutxCtsFlow=FALSE;
|
||||
SerialDCB.fOutxDsrFlow=FALSE;
|
||||
SerialDCB.XonLim=2048;
|
||||
SerialDCB.XoffLim=512;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -1501,3 +1501,33 @@ Init:Open device succeed .
|
||||
_start_machine
|
||||
Exit: Exit_SO7Usb
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Init:Open device succeed .
|
||||
_start_machine
|
||||
Exit: Exit_SO7Usb
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Init:Open device succeed .
|
||||
_start_machine
|
||||
Exit: Exit_SO7Usb
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Init:Open device succeed .
|
||||
_start_machine
|
||||
Exit: Exit_SO7Usb
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Init:Open device succeed .
|
||||
_start_machine
|
||||
Exit: Exit_SO7Usb
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Destruct Cso7_Proto.
|
||||
Construct Cso7_Proto.
|
||||
Destruct Cso7_Proto.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user