增加导出DLL工程。

This commit is contained in:
TAO Cheng
2014-04-13 23:30:50 +08:00
parent a71aa9182f
commit 4bfd0a6a4c
32 changed files with 1154 additions and 146 deletions
@@ -12,7 +12,6 @@
#define BAR_CODE_WIDTH 20
#define BAR_CODE_HEIGHT 20
#ifdef EF_IMAGE_DLL
#define EXP __declspec(dllexport)
#else
@@ -1,7 +1,6 @@
#include "StdAfx.h"
#include <WinDef.h>
#include <WinBase.h>
#include <math.h>
#include "DLL.h"
#include "EF8000_Interface.h "
@@ -29,6 +28,32 @@ CEF8000_Interface::~CEF8000_Interface()
}
//******************************************************************************
void CEF8000_Interface::GetAppPath(CString &Path)
{
Path=_T(""); // Speed optimization - noticed slow in GlowCode
if (Path.IsEmpty())
{
CString tmpPath;
GetModuleFileName(NULL,tmpPath.GetBuffer(255),255);
tmpPath.ReleaseBuffer();
tmpPath.TrimRight();
int nLastSlash = tmpPath.ReverseFind('\\');
if (nLastSlash >= 0)
tmpPath = tmpPath.Left(nLastSlash);
else
tmpPath.Empty();
Path=tmpPath;
}
};
BOOL CEF8000_Interface::OpenMotorDat()
{
CString csAppPath;
GetAppPath(csAppPath);
CString csMotorDatFile =csAppPath+_T("\\motor.dat");
return OpenSpeedParameter(csMotorDatFile);
}
BOOL CEF8000_Interface::SaveSpeedParameter(CString _FileName)
{
FILE* iFileHandle=NULL;
@@ -84,7 +109,8 @@ FILE* CEF8000_Interface::FileOpen(const CString filename,const int Mode)
case fmOpenWrite: fileMode =_T("wb"); break;
case fmOpenReadWrite:fileMode =_T("wb+"); break;
}
FILE *FileStream = _tfopen(filename, fileMode);
FILE *FileStream = NULL;
_tfopen_s(&FileStream,filename, fileMode);
return FileStream;
};
@@ -9,9 +9,6 @@
#pragma once
#endif // _MSC_VER > 1000
#include "DLL.h"
#pragma pack(push)
#pragma pack(16)
/*
@@ -588,8 +585,10 @@ public:
~CEF8000_Interface();
BOOL SaveSpeedParameter(CString _FileName);
BOOL OpenSpeedParameter(CString _FileName);
BOOL OpenMotorDat();
protected:
void GetAppPath(CString &Path);
FILE* FileOpen(const CString filename,const int Mode);
int FileSeek(FILE * _Handle, long _Offset, int _Origin);
int FileRead(FILE * _Handle, void *_Buffer, int _Count);
@@ -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)
{
@@ -11,7 +11,7 @@
#include "..\Tools\UsbUtility\logger.h"
#include "CMD_H.h"
#include "..\..\..\..\..\ThirdParty\UsbSupport\LibUsb_Win\Include\lusb0_usb.h"
#include "..\MicroVu\SsiStatus.h"
#include "..\Tools\UsbUtility\MachineInterfaceDll\MachineInterfaceDll.h"
#define MAX_BUFF_SIZE 0x200
@@ -60,6 +60,16 @@
const long MAX_INTENSITY = 0x3FF;
#define MAXLIGHTVALUE 255
#define MINLIGHTVALUE 1
enum MACHINE_AXIS
{
MACHINE_AXIS_NONE = 0,
MACHINE_AXIS_X,
MACHINE_AXIS_Y,
MACHINE_AXIS_Z,
MACHINE_AXIS_ZOOM,
MACHINE_AXIS_R,
MACHINE_AXIS_ALL = 5
};
enum EMACHINETYPE
{
MACHINE_SO7_CONTROLLER,
@@ -180,6 +190,9 @@ struct s_so7_machine_interface_config
INT m_SV4000E_DenoisePara[4];
INT m_MachineType;
INT m_VideoCardType;
INT m_RotaryAxisNO;
double m_RotaryCircleDis;
double m_RotaryCirclePulse;
};
//======================
@@ -219,7 +232,8 @@ struct struct_so7_machine
bool _bZMMoving;
char _bIsZMMotionFinished;
bool _bZMHoming;
bool _bXYZZMIdle;
bool _bXYZZMIdle;
bool _bRMovins;
} s_status;
union {
struct s_lights_value
@@ -250,6 +264,7 @@ struct struct_so7_machine
BOOL IsSupportReadInterrputMsg;
double dRotaryCirclDis;
char SEQ_NUMBER;
char MotionType;
struct s_so7_axis x;
struct s_so7_axis y;
struct s_so7_axis z;
@@ -381,6 +396,9 @@ public:
SSI_STATUS_MOTION so7_motion_startup(double x_scale_resolution, double y_scale_resolution, double z_scale_resolution);
bool so7_motion_is_homed();
SSI_STATUS_MOTION so7_motion_Dcc_Home();
SSI_STATUS_MOTION so7_motion_Dcc_Home_R();
SSI_STATUS_MOTION so7_Motion_R_IsHomed(bool &bHomed);
SSI_STATUS_MOTION so7_Motion_R_IsMotionFInished(bool &bFinished);
SSI_STATUS_MOTION _start_machine();
SSI_STATUS_MOTION _shutdown_machine();
SSI_STATUS_MOTION so7_motion_probe_on_off_(bool _bOnOff);
@@ -398,7 +416,11 @@ public:
SSI_STATUS_MOTION so7_motion_set_position_xyz(double dX, double dY, double dZ, bool bWait);
SSI_STATUS_MOTION so7_motion_set_speed_xyz(double dPercentSpeed);
SSI_STATUS_MOTION so7_motion_get_speed_xyz(double &dPercentSpeed);
SSI_STATUS_MOTION so7_motion_get_3D_max_speed(double &dMaxSpeed);
SSI_STATUS_MOTION so7_motion_set_position_R(double dR,bool bWait);
SSI_STATUS_MOTION so7_motion_get_position_R(double & dR);
SSI_STATUS_MOTION so7_motion_move_R(char _SpeedGear);
SSI_STATUS_MOTION so7_motion_get_3D_max_speed(double &dMaxSpeed);
SSI_STATUS_MOTION so7_motion_is_finished(char MotionType,BOOL& IsFinished);
SSI_STATUS_MOTION _calculate_straightline_motion(double dSpeedMM);
@@ -11,7 +11,8 @@
#include "..\Tools\UsbUtility\logger.h"
#include "CMD_H.h"
#include "..\..\..\..\..\ThirdParty\UsbSupport\LibUsb_Win\Include\lusb0_usb.h"
#include "..\MicroVu\SsiStatus.h"
#include "..\Tools\UsbUtility\MachineInterfaceDll\MachineInterfaceDll.h"
#define MAX_BUFF_SIZE 0x200
#define USB_R_SEQ_NUMBER 1