增加导出DLL工程。
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <math.h>
|
||||
#include "SO7_Proto.h"
|
||||
#include "math.h"
|
||||
|
||||
|
||||
|
||||
#define MY_CONFIG 1
|
||||
#define MAX_DEVPATH_LENGTH 256
|
||||
#define ENDPOINT_TIMEOUT 500
|
||||
#define MAX_IN_BUFF_SIZE 1024
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
const DOUBLE ROTARY_MMtoScale_RESOLUTION=0.0005;
|
||||
//***** Static Data *****
|
||||
static char *outBuff = NULL;
|
||||
struct_so7_ep_buff CSO7_Proto::ep_buff[lEPSIZE];
|
||||
@@ -2631,7 +2631,10 @@ SSI_STATUS_MOTION CSO7_Proto::Load_So7_Config()
|
||||
}
|
||||
fclose(hConfigFile);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return SSI_STATUS_SO7_CONFIG_FILE_NOT_FOUND;
|
||||
}
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
|
||||
@@ -2684,7 +2687,7 @@ SSI_STATUS_MOTION CSO7_Proto::_replay_capture(CString s_replay_file)
|
||||
|
||||
_wfopen_s(&pInFile, s_replay_file, _T("r"));
|
||||
if (pInFile == NULL)
|
||||
return SSI_STATUS_MOTION_REPLAY_FILE_ERROR;
|
||||
return SSI_STATUS_UNKNOWN_ERROR;
|
||||
|
||||
char *cData = (char *)malloc(MAX_BUFF_SIZE);
|
||||
char *inBuff = (char *)malloc(MAX_BUFF_SIZE);
|
||||
@@ -2819,81 +2822,81 @@ SSI_STATUS_MOTION CSO7_Proto::Init_SO7Usb()
|
||||
//Set initial state of the machine
|
||||
g_machine.s_status._machine_running = false;
|
||||
|
||||
|
||||
SSI_STATUS_MOTION rStatus=SSI_STATUS_MOTION_NORMAL;
|
||||
|
||||
g_machine.IsOffline=FALSE;
|
||||
|
||||
int usb_status = NULL;
|
||||
usb_init(); // initialize the library
|
||||
usb_status = usb_find_busses(); // find all busses
|
||||
usb_status = usb_find_devices(); // find all connected devices
|
||||
g_dev = _open_usb_dev();
|
||||
if (!g_dev)
|
||||
{
|
||||
MessageBox(NULL, _T("Unable to open device"), _T("Message"), MB_OK|MB_ICONERROR);
|
||||
g_pLogger->SendAndFlushPerMode(_T("Unable to open device %s \r\n"), usb_strerror());
|
||||
g_machine.IsOffline=TRUE;
|
||||
rStatus= SSI_STATUS_MOTION_DATALINK_ERROR;
|
||||
g_machine.IsOffline=FALSE;
|
||||
|
||||
int usb_status = NULL;
|
||||
usb_init(); // initialize the library
|
||||
usb_status = usb_find_busses(); // find all busses
|
||||
usb_status = usb_find_devices(); // find all connected devices
|
||||
g_dev = _open_usb_dev();
|
||||
if (!g_dev)
|
||||
{
|
||||
MessageBox(NULL, _T("Unable to open device"), _T("Message"), MB_OK|MB_ICONERROR);
|
||||
g_pLogger->SendAndFlushPerMode(_T("Unable to open device %s \r\n"), usb_strerror());
|
||||
g_machine.IsOffline=TRUE;
|
||||
rStatus= SSI_STATUS_MOTION_DATALINK_ERROR;
|
||||
}
|
||||
else if (usb_set_configuration(g_dev, MY_CONFIG) < 0)
|
||||
{
|
||||
MessageBox(NULL, _T("Unable to SET CONFIGURATION"), _T("Message"), MB_OK|MB_ICONERROR);
|
||||
g_machine.IsOffline=TRUE;
|
||||
rStatus=SSI_STATUS_MOTION_DATALINK_ERROR;
|
||||
}
|
||||
else if (usb_claim_interface(g_dev, 0) < 0)
|
||||
{
|
||||
usb_close(g_dev);
|
||||
MessageBox(NULL, _T("Unable to CLAIM DEVICE"), _T("Message"), MB_OK|MB_ICONERROR);
|
||||
g_machine.IsOffline=TRUE;
|
||||
rStatus=SSI_STATUS_MOTION_DATALINK_ERROR;
|
||||
}
|
||||
|
||||
g_pLogger->SendAndFlushPerMode(_T("Init:Open device succeed .\r\n"));
|
||||
// ********************************************************************
|
||||
// This event is used to kick the Serial Usb Command process. This threading model
|
||||
// is important because the underlying library is not thread-safe.
|
||||
//
|
||||
ep_buff[EP_02_CMD_IDX]._event = CreateEvent(NULL, // default security attributes
|
||||
FALSE, // manual reset event object
|
||||
NULL, // signaled
|
||||
NULL); // unamed object
|
||||
|
||||
g_hEP02_Thread_Id = CreateThread( (LPSECURITY_ATTRIBUTES) NULL,
|
||||
0,
|
||||
(LPTHREAD_START_ROUTINE) g_EP02_Thread,
|
||||
(LPVOID) this,
|
||||
0,
|
||||
NULL);
|
||||
g_hEP02_Thread_State = THREAD_RUNNING_STATE1;
|
||||
|
||||
// ********************************************************************
|
||||
// Prepare and start EP_S07_81 Thread - Use async commit.
|
||||
//
|
||||
ep_buff[EP_82_DATA_IDX]._event = CreateEvent(NULL, // default security attributes
|
||||
FALSE, // manual reset event object
|
||||
NULL, // signaled
|
||||
NULL); // unamed object
|
||||
g_hEP8x_Thread_State = THREAD_PAUSED;
|
||||
g_hEP8x_Thread_Id = CreateThread( (LPSECURITY_ATTRIBUTES) NULL,
|
||||
0,
|
||||
(LPTHREAD_START_ROUTINE) g_EP8x_Thread,
|
||||
(LPVOID) this,
|
||||
0,
|
||||
NULL);
|
||||
g_hEP02_Serial_Mutex = CreateMutex(NULL, // default security attributes
|
||||
FALSE, // initial owner
|
||||
NULL); // name
|
||||
|
||||
|
||||
|
||||
// *********************************************************************
|
||||
g_hHomedEvent = CreateEvent(NULL, // default security attributes
|
||||
TRUE, // manual reset event object
|
||||
FALSE, // initial state is signaled
|
||||
NULL); // unamed object
|
||||
}
|
||||
else if (usb_set_configuration(g_dev, MY_CONFIG) < 0)
|
||||
{
|
||||
MessageBox(NULL, _T("Unable to SET CONFIGURATION"), _T("Message"), MB_OK|MB_ICONERROR);
|
||||
g_machine.IsOffline=TRUE;
|
||||
rStatus=SSI_STATUS_MOTION_DATALINK_ERROR;
|
||||
}
|
||||
else if (usb_claim_interface(g_dev, 0) < 0)
|
||||
{
|
||||
usb_close(g_dev);
|
||||
MessageBox(NULL, _T("Unable to CLAIM DEVICE"), _T("Message"), MB_OK|MB_ICONERROR);
|
||||
g_machine.IsOffline=TRUE;
|
||||
rStatus=SSI_STATUS_MOTION_DATALINK_ERROR;
|
||||
}
|
||||
|
||||
g_pLogger->SendAndFlushPerMode(_T("Init:Open device succeed .\r\n"));
|
||||
// ********************************************************************
|
||||
// This event is used to kick the Serial Usb Command process. This threading model
|
||||
// is important because the underlying library is not thread-safe.
|
||||
//
|
||||
ep_buff[EP_02_CMD_IDX]._event = CreateEvent(NULL, // default security attributes
|
||||
FALSE, // manual reset event object
|
||||
NULL, // signaled
|
||||
NULL); // unamed object
|
||||
|
||||
g_hEP02_Thread_Id = CreateThread( (LPSECURITY_ATTRIBUTES) NULL,
|
||||
0,
|
||||
(LPTHREAD_START_ROUTINE) g_EP02_Thread,
|
||||
(LPVOID) this,
|
||||
0,
|
||||
NULL);
|
||||
g_hEP02_Thread_State = THREAD_RUNNING_STATE1;
|
||||
|
||||
// ********************************************************************
|
||||
// Prepare and start EP_S07_81 Thread - Use async commit.
|
||||
//
|
||||
ep_buff[EP_82_DATA_IDX]._event = CreateEvent(NULL, // default security attributes
|
||||
FALSE, // manual reset event object
|
||||
NULL, // signaled
|
||||
NULL); // unamed object
|
||||
g_hEP8x_Thread_State = THREAD_PAUSED;
|
||||
g_hEP8x_Thread_Id = CreateThread( (LPSECURITY_ATTRIBUTES) NULL,
|
||||
0,
|
||||
(LPTHREAD_START_ROUTINE) g_EP8x_Thread,
|
||||
(LPVOID) this,
|
||||
0,
|
||||
NULL);
|
||||
g_hEP02_Serial_Mutex = CreateMutex(NULL, // default security attributes
|
||||
FALSE, // initial owner
|
||||
NULL); // name
|
||||
|
||||
|
||||
|
||||
// *********************************************************************
|
||||
g_hHomedEvent = CreateEvent(NULL, // default security attributes
|
||||
TRUE, // manual reset event object
|
||||
FALSE, // initial state is signaled
|
||||
NULL); // unamed object
|
||||
|
||||
|
||||
return rStatus;
|
||||
}
|
||||
@@ -3250,6 +3253,264 @@ SSI_STATUS_MOTION CSO7_Proto::so7_motion_Dcc_Home()
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_Motion_R_IsHomed(bool &bHomed)
|
||||
{
|
||||
_send_cmd_SO7_CMD_GET_RESET_FLAG();
|
||||
if (g_machine.Sys_Reset_Flag == 1)
|
||||
{
|
||||
bHomed=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bHomed=false;
|
||||
}
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_Dcc_Home_R()
|
||||
{
|
||||
//查询是否复位
|
||||
_send_cmd_SO7_CMD_GET_RESET_FLAG();
|
||||
if (g_machine.Sys_Reset_Flag == 1)
|
||||
{
|
||||
SetEvent(g_hHomedEvent);
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
m_bHomingActive = true; // Tell the world we need to home the stage
|
||||
|
||||
// Home r
|
||||
long lMoveToDis(0);
|
||||
g_machine.x._pos_fixed._long_=0;
|
||||
g_machine.y._pos_fixed._long_=0;
|
||||
g_machine.z._pos_fixed._long_=0;
|
||||
lMoveToDis=MMtoScale(2.0*g_machine.s_machine_config.motion.m_RotaryCircleDis,ROTARY_MMtoScale_RESOLUTION);
|
||||
if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_X)
|
||||
{
|
||||
g_machine.x._pos_fixed._long_=lMoveToDis;
|
||||
}
|
||||
else if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_Y)
|
||||
{
|
||||
g_machine.y._pos_fixed._long_=lMoveToDis;
|
||||
}
|
||||
else if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_Z)
|
||||
{
|
||||
g_machine.z._pos_fixed._long_=lMoveToDis;
|
||||
}
|
||||
_send_cmd_SO7_CMD_MOVE_TO_POS_XYZ(CT_MOVETOXYZ);
|
||||
|
||||
g_pLogger->SendAndFlushPerMode(_T("so7_motion_reset_worktable_lower_left.\n"));
|
||||
//========================================
|
||||
const long lSleep = 20;
|
||||
const long lMaxLoopCnt = 2000/lSleep;
|
||||
long lLoopCnt = 0;
|
||||
Sleep(lSleep);
|
||||
BOOL IsFinished(FALSE);
|
||||
do
|
||||
{
|
||||
so7_motion_is_finished(EMSG_STOPXYZ_1_MOVETOXYZ,IsFinished);
|
||||
Sleep(lSleep);
|
||||
++lLoopCnt;
|
||||
} while (!IsFinished && lLoopCnt < lMaxLoopCnt);
|
||||
m_bHomingActive = false;
|
||||
if (IsFinished)
|
||||
{
|
||||
_send_cmd_SO7_CMD_SET_RESET_FLAG();
|
||||
g_machine.cVerNumber = 3;
|
||||
_send_cmd_SO7_CMD_SET_VER_NUMBER();
|
||||
g_pLogger->SendAndFlushPerMode(_T("Home succeed.\n"));
|
||||
SetEvent(g_hHomedEvent);
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SSI_STATUS_MOTION_TIMEOUT;
|
||||
}
|
||||
}
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_get_position_R(double & dRad)
|
||||
{
|
||||
WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done
|
||||
|
||||
long lX=0, lY=0, lZ=0;
|
||||
long lX_Ref=0, lY_Ref=0, lZ_Ref=0;
|
||||
double dR(0.0);
|
||||
_send_cmd_SO7_CMD_READ_AXIS_XYZ();
|
||||
if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_X)
|
||||
{
|
||||
lX = g_machine.x._scale_pos._long_;
|
||||
_send_cmd_SO7_CMD_READ_ZSIGNAL_POS_X();
|
||||
lX_Ref=g_machine.x._ZSignal_pos._long_;
|
||||
dR=static_cast<double>(lX-lX_Ref);
|
||||
}
|
||||
else if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_Y)
|
||||
{
|
||||
lY = g_machine.y._scale_pos._long_;
|
||||
_send_cmd_SO7_CMD_READ_ZSIGNAL_POS_Y();
|
||||
lY_Ref=g_machine.y._ZSignal_pos._long_;
|
||||
dR=static_cast<double>(lY-lY_Ref);
|
||||
}
|
||||
else if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_Z)
|
||||
{
|
||||
lZ = g_machine.z._scale_pos._long_;
|
||||
_send_cmd_SO7_CMD_READ_ZSIGNAL_POS_Z();
|
||||
lZ_Ref=g_machine.z._ZSignal_pos._long_;
|
||||
dR=static_cast<double>(lZ-lZ_Ref);
|
||||
}
|
||||
bool bPlus(true);
|
||||
if (dR<-0.00001)
|
||||
{
|
||||
bPlus=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bPlus=false;
|
||||
}
|
||||
int iRetryCnts(0);
|
||||
g_machine.s_machine_config.motion.m_RotaryCirclePulse=g_machine.s_machine_config.motion.m_RotaryCircleDis/ROTARY_MMtoScale_RESOLUTION;
|
||||
if (fabs(dR)-fabs(2.0*g_machine.s_machine_config.motion.m_RotaryCirclePulse)>100)
|
||||
{
|
||||
do
|
||||
{
|
||||
iRetryCnts++;
|
||||
if (bPlus)
|
||||
{
|
||||
dR+=8388608;
|
||||
}
|
||||
else
|
||||
{
|
||||
dR-=8388608;
|
||||
}
|
||||
//m_csMessage.Format("[CONVERT RotaryY]CNTS:%d;PLUS:%d;ScaleYResult:%.4f.",iRetryCnts,bPlus,dR);
|
||||
} while ((iRetryCnts<5)&&
|
||||
(fabs(dR)-fabs(g_machine.s_machine_config.motion.m_RotaryCirclePulse)>100));
|
||||
}
|
||||
dRad = 2.0*M_PI*dR/(g_machine.s_machine_config.motion.m_RotaryCirclePulse);
|
||||
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
};
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_set_position_R(double dRad,bool bWait)
|
||||
{
|
||||
WaitForSingleObject(g_hHomedEvent, INFINITE);
|
||||
// get the current position
|
||||
double dRStart(0.0),dRMovetoDis(0.0);
|
||||
long lMoveToDis(0);
|
||||
so7_motion_get_position_R(dRStart);
|
||||
dRMovetoDis=dRad-dRStart;
|
||||
double dMod=dRMovetoDis/(2.0*M_PI);
|
||||
int iMod(0);
|
||||
if(dMod>=0.0001)
|
||||
{
|
||||
iMod=static_cast<int>(floor(dMod));
|
||||
}
|
||||
else
|
||||
{
|
||||
iMod=static_cast<int>(ceil(dMod));
|
||||
}
|
||||
dRMovetoDis=dRMovetoDis-2.0*M_PI*static_cast<double>(iMod);
|
||||
|
||||
if ((dRMovetoDis)<=-0.01)
|
||||
{
|
||||
dRMovetoDis=2.0*M_PI+dRMovetoDis;
|
||||
}
|
||||
else
|
||||
{
|
||||
dRMovetoDis=dRMovetoDis;
|
||||
}
|
||||
lMoveToDis=static_cast<long>(dRMovetoDis*(static_cast<double>(g_machine.s_machine_config.motion.m_RotaryCirclePulse))/(2.0*M_PI));
|
||||
g_machine.x._pos_fixed._long_=0;
|
||||
g_machine.y._pos_fixed._long_=0;
|
||||
g_machine.z._pos_fixed._long_=0;
|
||||
if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_X)
|
||||
{
|
||||
g_machine.x._pos_fixed._long_=lMoveToDis;
|
||||
}
|
||||
else if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_Y)
|
||||
{
|
||||
g_machine.y._pos_fixed._long_=lMoveToDis;
|
||||
}
|
||||
else if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_Z)
|
||||
{
|
||||
g_machine.z._pos_fixed._long_=lMoveToDis;
|
||||
}
|
||||
_send_cmd_SO7_CMD_MOVE_TO_POS_XYZ(CT_MOVETOXYZ);
|
||||
g_machine.MotionType=EMSG_STOPXYZ_1_MOVETOXYZ;
|
||||
|
||||
BOOL IsFinished(TRUE);
|
||||
if (bWait)
|
||||
{
|
||||
const long lSleep = 20;
|
||||
const long lMaxLoopCnt = 2000/lSleep; // use max homing time of 20 seconds
|
||||
long lLoopCnt = 0;
|
||||
Sleep(lSleep);
|
||||
do
|
||||
{
|
||||
so7_motion_is_finished(EMSG_STOPXYZ_1_MOVETOXYZ,IsFinished);
|
||||
Sleep(lSleep);
|
||||
++lLoopCnt;
|
||||
} while (!IsFinished && lLoopCnt < lMaxLoopCnt);
|
||||
}
|
||||
g_machine.MotionType=-1;
|
||||
if (IsFinished)
|
||||
{
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SSI_STATUS_MOTION_TIMEOUT;
|
||||
}
|
||||
};
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_Motion_R_IsMotionFInished(bool &bFinished)
|
||||
{
|
||||
if (g_machine.MotionType<EMSG_STOPXYZ_1_MOVETOXYZ)
|
||||
{
|
||||
bFinished=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOL IsFinished(TRUE);
|
||||
so7_motion_is_finished(g_machine.MotionType,IsFinished);
|
||||
if (IsFinished)
|
||||
{
|
||||
bFinished=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bFinished=false;
|
||||
}
|
||||
}
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_move_R(char _SpeedGear)
|
||||
{
|
||||
//4-FASTER,1-SLOWER
|
||||
if (_SpeedGear>4)
|
||||
{
|
||||
_SpeedGear=4;
|
||||
}
|
||||
if (_SpeedGear<1)
|
||||
{
|
||||
_SpeedGear=1;
|
||||
}
|
||||
if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_X)
|
||||
{
|
||||
_send_cmd_SO7_CMD_MOVE_X(_SpeedGear);
|
||||
}
|
||||
else if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_Y)
|
||||
{
|
||||
_send_cmd_SO7_CMD_MOVE_Y(_SpeedGear);
|
||||
}
|
||||
else if (g_machine.s_machine_config.motion.m_RotaryAxisNO==MACHINE_AXIS_Z)
|
||||
{
|
||||
_send_cmd_SO7_CMD_MOVE_Z(_SpeedGear);
|
||||
}
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_startup(double dScaleResolutionX, double dScaleResolutionY, double dScaleResolutionZ)
|
||||
@@ -3303,7 +3564,7 @@ SSI_STATUS_MOTION CSO7_Proto::so7_motion_get_position_xyz(double & dX, double &
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_set_position_xyz(double dX, double dY, double dZ, bool bWait)
|
||||
{
|
||||
//WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done
|
||||
WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done
|
||||
|
||||
if (g_machine.IsOffline)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user