Machine Interface Utility:VER1.0
This commit is contained in:
@@ -0,0 +1,350 @@
|
||||
enum FUN_CMD
|
||||
{
|
||||
|
||||
CT_FUN,
|
||||
CT_MOTOR,
|
||||
CT_SCALE,
|
||||
CT_LIGHT,
|
||||
CT_INT,
|
||||
CT_DATA
|
||||
|
||||
};
|
||||
|
||||
enum MOTOR_CMD
|
||||
{
|
||||
|
||||
CT_MOVEX,
|
||||
|
||||
CT_MOVEY,
|
||||
|
||||
CT_MOVEZ,
|
||||
|
||||
|
||||
CT_MOVETOX,
|
||||
CT_MOVETOY,
|
||||
CT_MOVETOZ,
|
||||
|
||||
CT_MOVETOFX,
|
||||
CT_MOVETOFY,
|
||||
CT_MOVETOFZ,
|
||||
|
||||
CT_MOVETOSX,
|
||||
CT_MOVETOSY,
|
||||
CT_MOVETOSZ,
|
||||
|
||||
CT_MOVETOAX,
|
||||
CT_MOVETOAY,
|
||||
CT_MOVETOAZ,
|
||||
|
||||
CT_MOVETOASX,
|
||||
CT_MOVETOASY,
|
||||
CT_MOVETOASZ,
|
||||
|
||||
CT_MOVETOAFX,
|
||||
CT_MOVETOAFY,
|
||||
CT_MOVETOAFZ,
|
||||
|
||||
CT_RESETXYZ,
|
||||
CT_RESETX,
|
||||
CT_RESETY,
|
||||
CT_RESETZ,
|
||||
|
||||
CT_STOPA,
|
||||
CT_STOPX,
|
||||
CT_STOPY,
|
||||
CT_STOPZ,
|
||||
|
||||
CT_STOPFA,
|
||||
CT_STOPFX,
|
||||
CT_STOPFY,
|
||||
CT_STOPFZ,
|
||||
|
||||
CT_SET_SPEEDX,
|
||||
|
||||
|
||||
CT_SET_SPEEDY,
|
||||
|
||||
|
||||
CT_SET_SPEEDZ,
|
||||
|
||||
CT_READ_SPEEDX,
|
||||
CT_READ_SPEEDY,
|
||||
CT_READ_SPEEDZ,
|
||||
|
||||
CT_SET_PRECISIONX,
|
||||
CT_SET_PRECISIONY,
|
||||
CT_SET_PRECISIONZ,
|
||||
|
||||
CT_SET_DEFAULTX,
|
||||
CT_SET_DEFAULTY,
|
||||
CT_SET_DEFAULTZ,
|
||||
|
||||
CT_READ_PRECISIONX,
|
||||
CT_READ_PRECISIONY,
|
||||
CT_READ_PRECISIONZ,
|
||||
CT_RESET,
|
||||
|
||||
CT_MOVEV,
|
||||
CT_MOVETOV,
|
||||
CT_RESETV,
|
||||
CT_STOPV,
|
||||
CT_SET_SPEEDV,
|
||||
CT_READ_SPEEDV,
|
||||
CT_SET_DEFAULTV,
|
||||
CT_TESTV,
|
||||
CT_TSTOPV,
|
||||
CT_TEST_STOP,
|
||||
CT_READ_V,
|
||||
|
||||
CT_M_SPEED,
|
||||
CT_M_DIS,
|
||||
CT_M_FRESH,
|
||||
CT_M_CMD,
|
||||
CT_M_READ_DAT,
|
||||
CT_SET_MOTOR_CAL,
|
||||
|
||||
CT_M_SWITCH_START,
|
||||
CT_M_SWITCH_CLOSE,
|
||||
CT_M_SWITCH_TOP,
|
||||
CT_M_SWITCH_BOM,
|
||||
CT_M_SWITCH_RESET,
|
||||
CT_M_SWITCH_VALUE,
|
||||
CT_M_RESET_LEFT,
|
||||
CT_M_RESET_RIGHT,
|
||||
|
||||
CT_LASE_TIMMER_ON,
|
||||
CT_LASE_TIMMER_OFF,
|
||||
CT_M_PROBE_ON,
|
||||
CT_M_PROBE_OFF,
|
||||
CT_MOVETOXYZ,
|
||||
CT_MOVETOXYZ_LASE,
|
||||
CT_GET_LASE,
|
||||
CT_MOVETOXYZV,
|
||||
CT_M_LASE_ON,
|
||||
CT_M_LASE_OFF,
|
||||
CT_M_BCL_ON,
|
||||
CT_M_BCL_OFF,
|
||||
CT_MOVETOXYZ_JM,
|
||||
CT_READ_MOTOR_CAL,
|
||||
CT_END
|
||||
|
||||
};
|
||||
|
||||
enum SCALE_CMD
|
||||
{
|
||||
|
||||
CT_SEC_FLAG,
|
||||
|
||||
CT_SCALEX,
|
||||
CT_SCALEY,
|
||||
CT_SCALEZ,
|
||||
|
||||
CT_SECTIONX,
|
||||
CT_SECTIONY,
|
||||
CT_SECTIONZ,
|
||||
|
||||
CT_SET_AXISX,
|
||||
CT_SET_AXISY,
|
||||
CT_SET_AXISZ,
|
||||
|
||||
CT_SET_SECTIONX,
|
||||
CT_SET_SECTIONY,
|
||||
CT_SET_SECTIONZ,
|
||||
|
||||
CT_X_BEGIN,
|
||||
CT_Y_BEGIN,
|
||||
CT_Z_BEGIN,
|
||||
|
||||
CT_X_SECTION_END,
|
||||
CT_Y_SECTION_END,
|
||||
CT_Z_SECTION_END,
|
||||
|
||||
CT_X_SECTION_DEC,
|
||||
CT_Y_SECTION_DEC,
|
||||
CT_Z_SECTION_DEC,
|
||||
|
||||
CT_SET_SECTION_X,
|
||||
CT_SET_SECTION_Y,
|
||||
CT_SET_SECTION_Z,
|
||||
|
||||
CT_PROBE_FLAG,
|
||||
CT_SET_LINE_X,
|
||||
CT_SET_LINE_Y,
|
||||
CT_SET_LINE_Z,
|
||||
|
||||
CT_SET_PROBE_LINE,
|
||||
CT_SET_PROBE_SECTION,
|
||||
CT_SET_VERNO,
|
||||
CT_SET_RESET_FLAG,
|
||||
CT_GET_RESET_FLAG
|
||||
|
||||
};
|
||||
|
||||
enum LIGHT_CMD
|
||||
{
|
||||
|
||||
CT_LIGHT1_SIZE,
|
||||
CT_LIGHT2_SIZE,
|
||||
CT_LIGHT3_SIZE,
|
||||
CT_LIGHT4_SIZE,
|
||||
|
||||
CT_LIGHT1_SWITCH,
|
||||
CT_LIGHT2_SWITCH,
|
||||
CT_LIGHT3_SWITCH,
|
||||
CT_LIGHT4_SWITCH,
|
||||
CT_LIGHT5_SWITCH,
|
||||
CT_LIGHT_CMD
|
||||
|
||||
};
|
||||
|
||||
enum INT_CMD
|
||||
{
|
||||
|
||||
CT_STOPMX,
|
||||
CT_STOPMY,
|
||||
CT_STOPMZ,
|
||||
CT_STOPXYZ,
|
||||
|
||||
CT_ENDXYZ,
|
||||
|
||||
CT_SWITCHX,
|
||||
CT_SWITCHY,
|
||||
CT_SWITCHZ,
|
||||
|
||||
CT_PROBE,
|
||||
CT_PROBE_SWITCH,
|
||||
CT_XYZLASE,
|
||||
CT_SEND_XYZLASE,
|
||||
CT_END1
|
||||
|
||||
};
|
||||
|
||||
enum PRO_DATA
|
||||
{
|
||||
CT_READ_AXISXYZ,
|
||||
CT_READ_AXISX,
|
||||
CT_READ_AXISY,
|
||||
CT_READ_AXISZ,
|
||||
|
||||
CT_READ_PROBEXYZ,
|
||||
CT_READ_PROBEX,
|
||||
CT_READ_PROBEY,
|
||||
CT_READ_PROBEZ,
|
||||
|
||||
CT_SAVE_MOTORX1,
|
||||
CT_SAVE_MOTORX2,
|
||||
CT_SAVE_MOTORX3,
|
||||
CT_SAVE_MOTORX4,
|
||||
CT_SAVE_MOTORX5,
|
||||
|
||||
CT_SAVE_MOTORY1,
|
||||
CT_SAVE_MOTORY2,
|
||||
CT_SAVE_MOTORY3,
|
||||
CT_SAVE_MOTORY4,
|
||||
CT_SAVE_MOTORY5,
|
||||
|
||||
CT_SAVE_MOTORZ1,
|
||||
CT_SAVE_MOTORZ2,
|
||||
CT_SAVE_MOTORZ3,
|
||||
CT_SAVE_MOTORZ4,
|
||||
CT_SAVE_MOTORZ5,
|
||||
|
||||
CT_READ_MOTORX1,
|
||||
CT_READ_MOTORX2,
|
||||
CT_READ_MOTORX3,
|
||||
CT_READ_MOTORX4,
|
||||
CT_READ_MOTORX5,
|
||||
|
||||
CT_READ_MOTORY1,
|
||||
CT_READ_MOTORY2,
|
||||
CT_READ_MOTORY3,
|
||||
CT_READ_MOTORY4,
|
||||
CT_READ_MOTORY5,
|
||||
|
||||
CT_READ_MOTORZ1,
|
||||
CT_READ_MOTORZ2,
|
||||
CT_READ_MOTORZ3,
|
||||
CT_READ_MOTORZ4,
|
||||
CT_READ_MOTORZ5,
|
||||
|
||||
CT_SAVE_SCALEX,
|
||||
CT_SAVE_SCALEY,
|
||||
CT_SAVE_SCALEZ,
|
||||
|
||||
CT_READ_SCALEX,
|
||||
CT_READ_SCALEY,
|
||||
CT_READ_SCALEZ,
|
||||
|
||||
CT_SAVE_SECTION_FLAGX,
|
||||
CT_SAVE_SECTION_FLAGY,
|
||||
CT_SAVE_SECTION_FLAGZ,
|
||||
|
||||
CT_READ_SECTION_FLAGX,
|
||||
CT_READ_SECTION_FLAGY,
|
||||
CT_READ_SECTION_FLAGZ,
|
||||
|
||||
CT_SAVE_PROBE,
|
||||
CT_READ_PROBE,
|
||||
|
||||
CT_SAVE_SEC_REALX,
|
||||
CT_SAVE_SEC_INTX,
|
||||
CT_SAVE_SEC_SCALEX,
|
||||
|
||||
CT_SAVE_SEC_REALY,
|
||||
CT_SAVE_SEC_INTY,
|
||||
CT_SAVE_SEC_SCALEY,
|
||||
|
||||
CT_SAVE_SEC_REALZ,
|
||||
CT_SAVE_SEC_INTZ,
|
||||
CT_SAVE_SEC_SCALEZ,
|
||||
|
||||
CT_READ_SEC_REALX,
|
||||
CT_READ_SEC_INTX,
|
||||
CT_READ_SEC_SCALEX,
|
||||
|
||||
CT_READ_SEC_REALY,
|
||||
CT_READ_SEC_INTY,
|
||||
CT_READ_SEC_SCALEY,
|
||||
|
||||
CT_READ_SEC_REALZ,
|
||||
CT_READ_SEC_INTZ,
|
||||
CT_READ_SEC_SCALEZ,
|
||||
|
||||
CT_READ_SYSTEM,
|
||||
CT_READ_XSECTION_INT,
|
||||
CT_READ_XSECTION_REAL,
|
||||
CT_READ_XSECTION_SCALE,
|
||||
|
||||
CT_READ_YSECTION_INT,
|
||||
CT_READ_YSECTION_REAL,
|
||||
CT_READ_YSECTION_SCALE,
|
||||
|
||||
CT_READ_ZSECTION_INT,
|
||||
CT_READ_ZSECTION_REAL,
|
||||
CT_READ_ZSECTION_SCALE,
|
||||
|
||||
|
||||
CT_WRITE_SYSTEM,
|
||||
CT_WRITE_XSECTION_INT,
|
||||
CT_WRITE_XSECTION_REAL,
|
||||
CT_WRITE_XSECTION_SCALE,
|
||||
|
||||
CT_WRITE_YSECTION_INT,
|
||||
CT_WRITE_YSECTION_REAL,
|
||||
CT_WRITE_YSECTION_SCALE,
|
||||
|
||||
CT_WRITE_ZSECTION_INT,
|
||||
CT_WRITE_ZSECTION_REAL,
|
||||
CT_WRITE_ZSECTION_SCALE,
|
||||
|
||||
CT_READ_AXISV,
|
||||
CT_READ_ADC,
|
||||
CT_READ_ADC_INDEX,
|
||||
|
||||
CT_PRO_DAT_END,
|
||||
CT_CLEAR_PROBE_FLAG,
|
||||
|
||||
CT_READ_IO_DAT,
|
||||
CT_WRITE_IO_DAT
|
||||
|
||||
};
|
||||
@@ -0,0 +1,272 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "cmmio_base.h"
|
||||
#ifdef _WIN64
|
||||
#include "..\..\..\WAI64bit\WAI64bit.h"
|
||||
#endif
|
||||
|
||||
// added notifying feature to base class CMMIO [7/30/2004] /MP
|
||||
// - SetCallback(ptr) to establish the feedback path
|
||||
// then AddReceived will notify if such a ptr was set
|
||||
// caller receive function is prototyped as function(CString), i.e. Recieved(CString sWhat)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void CMMIO::Init()
|
||||
{
|
||||
m_RXTempPtr = NULL;
|
||||
m_RXHead=NULL;
|
||||
m_RXTail=NULL;
|
||||
m_SXTempPtr = NULL;
|
||||
m_SXHead=NULL;
|
||||
m_SXTail=NULL;
|
||||
CurrentPointer=0;
|
||||
m_iNbMsgWaiting=0;
|
||||
m_terminator='\0';
|
||||
m_usesTerminator=FALSE;
|
||||
m_pReceiveNotify = NULL;
|
||||
}
|
||||
|
||||
void CMMIO::SetCallback(CMMIO::p_fstr ptr)
|
||||
{
|
||||
m_pReceiveNotify = ptr;
|
||||
}
|
||||
|
||||
DWORD CMMIO::Send(CString buffer, BOOL needsResponse/*=FALSE*/)
|
||||
{
|
||||
//ZH 12-12-05 EnterCriticalSection(&m_QueueLock); //ZH-122904
|
||||
|
||||
char LocBuffer[MAX_OUTPUT_BUFFER_SIZE];
|
||||
int length = buffer.GetLength ();
|
||||
if (length >MAX_OUTPUT_BUFFER_SIZE)
|
||||
{
|
||||
length = MAX_OUTPUT_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
unsigned short* ptr = (unsigned short*)buffer.GetBuffer (MAX_OUTPUT_BUFFER_SIZE);
|
||||
|
||||
for (int i=0;i<length;i++)
|
||||
{
|
||||
LocBuffer[i] = (char)(ptr[i] & 0xff);
|
||||
}
|
||||
DWORD res = Send(LocBuffer,length, needsResponse);
|
||||
|
||||
//ZH 12-12-05 LeaveCriticalSection( &m_QueueLock ); //ZH-122904
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// GetNextReceived() : Helper function, rreturns receives messages placed in the queue
|
||||
// by LineReceive()
|
||||
//
|
||||
int CMMIO::GetNextReceived(char *inputBuf)
|
||||
{
|
||||
struct SerialList *Free;
|
||||
int cnt=0;
|
||||
|
||||
// If there is a previous block then delete it
|
||||
if (NULL != m_RXTempPtr)
|
||||
delete[] m_RXTempPtr;
|
||||
m_RXTempPtr = NULL;
|
||||
|
||||
// We are messing with pointers so use the CriticalSection
|
||||
// EnterCriticalSection(&m_QueueLock);
|
||||
|
||||
// If there any more to return
|
||||
if( m_RXHead )
|
||||
{
|
||||
Free = m_RXHead;
|
||||
m_RXHead = m_RXHead->Next;
|
||||
|
||||
// Point the temp pointer at the block
|
||||
m_RXTempPtr = Free->Buffer;
|
||||
cnt = Free->Bytes;
|
||||
// delete the list entry
|
||||
delete Free;
|
||||
--m_iNbMsgWaiting; // mp
|
||||
|
||||
// move over the data to the user's buffer
|
||||
if (NULL != inputBuf)
|
||||
memcpy (inputBuf, m_RXTempPtr, cnt);
|
||||
}
|
||||
|
||||
if( m_RXHead == NULL )
|
||||
m_RXTail = NULL;
|
||||
|
||||
// All done so out of the CriticalSection
|
||||
// LeaveCriticalSection( &m_QueueLock );
|
||||
|
||||
return(cnt);
|
||||
}
|
||||
|
||||
int CMMIO::AddReceived( const char *Buffer,DWORD Bytes)
|
||||
{
|
||||
DWORD index = 0; //primary buffer index
|
||||
struct SerialList *Ptr;
|
||||
static char Buffer2[MAX_RECIEVE_BUFFER_SIZE]; // result buffer
|
||||
static char* pBuffer2 = &Buffer2[0];
|
||||
unsigned char c;
|
||||
bool bArmed;
|
||||
/************************************************************************/
|
||||
/* Greg Guilbeau - 2011/08/23 */
|
||||
/* The following line(s) have been modified to handle x64 conversion */
|
||||
/************************************************************************/
|
||||
/* int count; */
|
||||
INT_PTR count;
|
||||
static int escape = 0;
|
||||
static int tilde = 0;
|
||||
static int tildeseqcount = 0;
|
||||
|
||||
bool bDone = false;
|
||||
bool bEventRequest = false;
|
||||
|
||||
//TRACE(_T("AddReceived> pBuffer2 = %x\n"),pBuffer2);
|
||||
// TRACE(_T("Content %s\n"),Buffer);
|
||||
if (FALSE /*Bytes==0*/)
|
||||
{
|
||||
TRACE(_T("CMMIO> Exiting , no real input"));
|
||||
return TRUE;
|
||||
}
|
||||
do
|
||||
{
|
||||
bArmed = false;
|
||||
|
||||
for (;index<Bytes;index++)
|
||||
{
|
||||
c=Buffer[index] & 0xff;
|
||||
//TRACE(_T("== %02x% ==\n"),c); //copy char one by one
|
||||
*(pBuffer2++) = c ; //copy char one by one
|
||||
|
||||
// check for end of packet. ignore if this is the last char anyways
|
||||
if (m_usesTerminator && c == m_terminator && (index < Bytes - 1))
|
||||
{
|
||||
bArmed = TRUE;
|
||||
index++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == Bytes)
|
||||
bArmed = bDone = true;
|
||||
|
||||
// We are messing with pointers so use the CriticalSection
|
||||
if (bArmed )
|
||||
{
|
||||
// EnterCriticalSection(&m_QueueLock);
|
||||
//Allocate a new list and add it in
|
||||
count = pBuffer2-(&Buffer2[0]);
|
||||
if (m_pReceiveNotify)
|
||||
{ // send a string to callback or,
|
||||
char* pLocalBuffer = new char[count+1];
|
||||
if (pLocalBuffer)
|
||||
{
|
||||
memcpy (pLocalBuffer,Buffer2,count);
|
||||
pLocalBuffer[count] = 0;
|
||||
CString LocalStr(pLocalBuffer);
|
||||
(*m_pReceiveNotify)(LocalStr);
|
||||
delete pLocalBuffer;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // add it as before to received data ....
|
||||
Ptr = new struct SerialList;
|
||||
Ptr->Buffer = new char[count + 1 ];
|
||||
/************************************************************************/
|
||||
/* Greg Guilbeau - 2011/08/23 */
|
||||
/* The following line(s) have been modified to handle x64 conversion */
|
||||
/************************************************************************/
|
||||
/* Ptr->Bytes = count; */
|
||||
#ifdef _WIN64
|
||||
Ptr->Bytes = WAI64bit::to32bit(count,__FILE__,__LINE__);
|
||||
#else
|
||||
Ptr->Bytes = count,__FILE__,__LINE__;
|
||||
#endif
|
||||
Ptr->Next = NULL;
|
||||
memcpy( Ptr->Buffer, Buffer2, count );
|
||||
Ptr->Buffer[count] = 0;
|
||||
|
||||
memcpy(m_sLastMessage,Buffer2,count); //copy to last message
|
||||
m_sLastMessage[count]=0;
|
||||
|
||||
if( m_RXTail )
|
||||
m_RXTail->Next = Ptr;
|
||||
else
|
||||
m_RXHead = Ptr;
|
||||
m_RXTail = Ptr;
|
||||
|
||||
// All done so out of the CriticalSection
|
||||
++m_iNbMsgWaiting;
|
||||
}
|
||||
// LeaveCriticalSection( &m_QueueLock );
|
||||
pBuffer2=&Buffer2[0]; // reset out buffer
|
||||
count = 0;
|
||||
bEventRequest = true;
|
||||
}
|
||||
}
|
||||
while (!bDone);
|
||||
//TRACE (_T("CMMIO> Done\n"));
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
void CMMIO::LineReceive(char* s, int nbCharAvail, BOOL ignoreDelimiter /*= FALSE*/)
|
||||
{
|
||||
if (nbCharAvail != -1)
|
||||
{
|
||||
//TRACE(_T("LineReceive got %d chars \n"),nbCharAvail);
|
||||
char c;
|
||||
for (int i=0 ; i<nbCharAvail ; i++ )
|
||||
{
|
||||
c=s[i];
|
||||
m_InputBuffer[CurrentPointer++] = c;
|
||||
|
||||
// only add a packet if we have a delimiter
|
||||
if ((!m_usesTerminator && i == nbCharAvail -1) || (m_usesTerminator && c == m_terminator) || ignoreDelimiter)
|
||||
{
|
||||
m_InputBuffer[CurrentPointer] = '\0';
|
||||
AddReceived(m_InputBuffer, CurrentPointer);
|
||||
CurrentPointer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
DWORD CMMIO::Close()
|
||||
{
|
||||
struct SerialList *Free;
|
||||
|
||||
// Delete the contents of the temp rx pointer if any
|
||||
delete[] m_RXTempPtr;
|
||||
m_RXTempPtr = NULL;
|
||||
|
||||
// Clear down all internal lists
|
||||
// EnterCriticalSection( &m_QueueLock );
|
||||
while( m_RXHead )
|
||||
{
|
||||
Free = m_RXHead;
|
||||
m_RXHead = m_RXHead->Next;
|
||||
delete[] Free->Buffer;
|
||||
delete Free;
|
||||
}
|
||||
m_RXHead = NULL;
|
||||
|
||||
// for now we are not using the Transmit list
|
||||
#if 0
|
||||
|
||||
while( m_TXHead )
|
||||
{
|
||||
Free = m_TXHead;
|
||||
m_TXHead = m_TXHead->Next;
|
||||
delete[] Free->Buffer;
|
||||
delete Free;
|
||||
}
|
||||
m_TXHead = NULL;
|
||||
#endif
|
||||
// LeaveCriticalSection( &m_QueueLock );
|
||||
return(TRUE);
|
||||
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// END OF BASE CLASS CMMIO
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
#ifndef CMMIO_BASE_H
|
||||
#define CMMIO_BASE_H
|
||||
|
||||
#include <WinBase.h>
|
||||
#include <WinDef.h>
|
||||
|
||||
|
||||
#define MAX_OUTPUT_BUFFER_SIZE 2048
|
||||
#define MAX_RECIEVE_BUFFER_SIZE 16000
|
||||
|
||||
// TCP, serial style routines
|
||||
struct SerialList
|
||||
{
|
||||
struct SerialList *Next;
|
||||
DWORD Bytes;
|
||||
int Item;
|
||||
char *Buffer;
|
||||
};
|
||||
|
||||
class CMMIO
|
||||
{
|
||||
private:
|
||||
// For now we are not using the transmit list
|
||||
// struct SerialList *m_TXHead;
|
||||
char m_terminator;
|
||||
BOOL m_usesTerminator;
|
||||
char m_InputBuffer[MAX_RECIEVE_BUFFER_SIZE];
|
||||
int CurrentPointer;
|
||||
char m_sLastMessage[MAX_RECIEVE_BUFFER_SIZE];
|
||||
|
||||
struct SerialList *m_RXHead;
|
||||
struct SerialList *m_RXTail;
|
||||
char *m_RXTempPtr;
|
||||
CString m_LastError;
|
||||
BOOL m_hasError;
|
||||
|
||||
protected:
|
||||
CString m_lastErrMsg;
|
||||
int m_iNbMsgWaiting;
|
||||
BOOL m_UseBuffferedSend;
|
||||
CRITICAL_SECTION m_QueueLock;
|
||||
CRITICAL_SECTION m_ReadLock;
|
||||
CRITICAL_SECTION m_WriteLock;
|
||||
|
||||
struct SerialList *m_SXHead;
|
||||
struct SerialList *m_SXTail;
|
||||
char *m_SXTempPtr;
|
||||
|
||||
protected:
|
||||
virtual void Init();
|
||||
int AddReceived( const char *Buffer,DWORD Bytes); // [7/30/2004]
|
||||
void Error(CString sErr) {
|
||||
TRACE(sErr);
|
||||
m_LastError = sErr;
|
||||
m_hasError = TRUE;
|
||||
}
|
||||
|
||||
virtual DWORD Close();
|
||||
|
||||
public:
|
||||
CMMIO()
|
||||
{
|
||||
InitializeCriticalSection( &m_QueueLock ); // Sean Flynn mutex needs to be initialized prior to attempting to lock otherwise it will core
|
||||
InitializeCriticalSection( &m_ReadLock ); // initializing here will ensure the mutex is always initialized
|
||||
InitializeCriticalSection( &m_WriteLock );
|
||||
Init();
|
||||
};
|
||||
|
||||
virtual ~CMMIO()
|
||||
{
|
||||
DeleteCriticalSection( &m_QueueLock ); // Clean up the mutexes resources when the destructor is called.
|
||||
DeleteCriticalSection( &m_ReadLock );
|
||||
DeleteCriticalSection( &m_WriteLock );
|
||||
};
|
||||
|
||||
virtual DWORD Open() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL getError(CString& sErr) {
|
||||
BOOL hasError = m_hasError;
|
||||
if (m_hasError)
|
||||
{
|
||||
sErr = m_LastError;
|
||||
m_hasError = FALSE;
|
||||
}
|
||||
return (hasError);
|
||||
}
|
||||
|
||||
virtual int GetNextReceived(char *inputBuf=NULL);
|
||||
|
||||
virtual int HasNextReceived(void) {
|
||||
return (m_RXHead ? m_RXHead->Bytes : FALSE);
|
||||
}
|
||||
virtual void SetTerminateChar(char ch) {
|
||||
m_terminator=ch;
|
||||
m_usesTerminator=TRUE;
|
||||
}
|
||||
virtual void LineReceive(char* s, int nbCharAvail, BOOL ignoreDelimiter = FALSE);
|
||||
virtual CString GetLastErrStr() {
|
||||
return m_lastErrMsg;
|
||||
}
|
||||
|
||||
typedef void(*p_fstr)(CString);
|
||||
void SetCallback(p_fstr);
|
||||
|
||||
virtual DWORD Send(LPCSTR buffer, int l, BOOL needsResponse=FALSE) = 0; // [8/11/2004]
|
||||
virtual DWORD Send(CString buffer, BOOL needsResponse=FALSE); // [8/11/2004]
|
||||
|
||||
virtual bool IsValid() = 0; // pure virtual function
|
||||
protected:
|
||||
p_fstr m_pReceiveNotify;
|
||||
};
|
||||
|
||||
|
||||
#endif // CMMIO_BASE_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,192 @@
|
||||
#ifndef CMMIO_SERIAL_H
|
||||
#define CMMIO_SERIAL_H
|
||||
|
||||
#include <WinBase.h>
|
||||
#include <WinDef.h>
|
||||
#include "CMMIO_BASE.H "
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
*$!!***************************************************************************
|
||||
*$!! MODULE NAME
|
||||
*$!! Serial.h
|
||||
*$!!
|
||||
*$!! DESCRIPTION
|
||||
*$!! Header file for CSerial.
|
||||
*$!!
|
||||
*$!! AUTHOR
|
||||
*$!! M.J.S.Gooder.
|
||||
*$!!
|
||||
*$!! HISTORY
|
||||
*$!! $Log: /Plugins/BPI/Serial.h $
|
||||
*$!!
|
||||
*$!! 28 19/03/98 14:04 Mgooder
|
||||
*$!!***************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Function for starting serial monitor thread
|
||||
unsigned int WINAPI CSerialTask(LPVOID CSerialPtr);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Useful serial codes
|
||||
const char CS_NUL = 0;
|
||||
const char CS_SOH = 1;
|
||||
const char CS_STX = 2;
|
||||
const char CS_ETX = 3;
|
||||
const char CS_EOT = 4;
|
||||
const char CS_ENQ = 5;
|
||||
const char CS_ACK = 6;
|
||||
const char CS_BEL = 7;
|
||||
const char CS_LF = 10;
|
||||
const char CS_DLE = 16;
|
||||
const char CS_X_ON = 17;
|
||||
const char CS_X_OFF = 19;
|
||||
const char CS_NAK = 21;
|
||||
const char CS_ETB = 23;
|
||||
const char CS_CAN = 24;
|
||||
const char CS_ESC = 27;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Handshake settings
|
||||
const int CS_HANDSHAKE_RTSCTS = 1;
|
||||
const int CS_HANDSHAKE_XONXOFF = 2;
|
||||
const int CS_HANDSHAKE_NONE = 3;
|
||||
const int CS_HANDSHAKE_RTSCTS_DTRDSR = 4;
|
||||
const int CS_HANDSHAKE_FOR_SO7 = 5;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Debug constants
|
||||
const int CS_DEBUG_SIZE = 1024;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Timeouts (ms)
|
||||
const int CS_DEFAULT_RX_TIMEOUT = 25;
|
||||
const int CS_DEFAULT_TX_TIMEOUT = 1000;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// The CSerial class
|
||||
|
||||
class CSerial : public CMMIO
|
||||
{
|
||||
// Construction
|
||||
public:
|
||||
CSerial();
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual ~CSerial();
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
|
||||
// Operations
|
||||
public:
|
||||
// Open the serial port ( if possible ) using the parameters set by SetPort()
|
||||
DWORD Open();
|
||||
// Setup the serial port prior to opening it
|
||||
int SetPort( int Port, int Baud = 0, char Parity = 0, int Bits = 0,
|
||||
int StopBits = 0, int HandShake = 0 );
|
||||
// Set up the port timeouts
|
||||
void SetTimeouts( int RXTimeout = CS_DEFAULT_RX_TIMEOUT,
|
||||
int TXTimeout = CS_DEFAULT_TX_TIMEOUT );
|
||||
// Get the serial port settings
|
||||
void GetPortData( int *Port, int *Baud, char *Parity, int *Bits,
|
||||
int *StopBits, int *HandShake );
|
||||
// Test if the serial port is open
|
||||
bool IsValid() {
|
||||
return IsOpen()!=0;
|
||||
}
|
||||
int IsOpen( void );
|
||||
// Close the serial port
|
||||
DWORD Close( void );
|
||||
// Flush all data in any serial port buffers
|
||||
int FlushPort( void );
|
||||
// Attempt to read the specified number of bytes
|
||||
DWORD ReadPort( char *Buffer, DWORD Bytes );
|
||||
DWORD ReadPort( CString &Buffer, DWORD Bytes );
|
||||
// Attempt to write the specified number of bytes
|
||||
DWORD WritePort( const char *Buffer, DWORD Bytes );
|
||||
// Send the specifed number of bytes out when possible
|
||||
int Transmit( const char *Buffer, DWORD Bytes );
|
||||
// Add a block of data to the internal list of receieved blocks
|
||||
int AddReceived( const char *Buffer, DWORD Bytes );
|
||||
// Get the next block of data added with AddReceived()
|
||||
// char *GetNextReceived( void );
|
||||
// Find the maximum port number available
|
||||
int MaxPort( void );
|
||||
// Add text to the debug output
|
||||
void AddToDebug( const char *Ptr, DWORD BytesToCopy, int State );
|
||||
// Attach this serial port to a debug window
|
||||
//CSerialRaw *AttachWnd( CWnd *Wnd );
|
||||
// Convert ascii hex into an int
|
||||
int HexToInt( char *Data, int Bytes );
|
||||
|
||||
virtual DWORD Send(LPCSTR buffer, int l, BOOL needsResponse=FALSE);
|
||||
//virtual DWORD Send(CString what);
|
||||
|
||||
// Called when data is received on the serial port
|
||||
virtual void OnReceive( void );
|
||||
// Called when data has been sent using the Transmit() function
|
||||
virtual void OnTransmit( int Item, DWORD Error );
|
||||
|
||||
private:
|
||||
// Private so no comment :-)
|
||||
void RegisterDebugWindow(void);
|
||||
void SendBuffer(int Next);
|
||||
void ReceiveTask(void);
|
||||
int ProgramPort(int Port,int Baud,char Parity,int Bits,int StopBits,int HandShake);
|
||||
|
||||
// Attributes
|
||||
protected:
|
||||
int m_RXTimeout;
|
||||
int m_TXTimeout;
|
||||
|
||||
// Attributes
|
||||
private:
|
||||
char m_Parity;
|
||||
// char m_DebugData[CS_DEBUG_SIZE];
|
||||
// char m_DebugState[CS_DEBUG_SIZE];
|
||||
// char *m_RXTempPtr;
|
||||
int m_Port;
|
||||
int m_Baud;
|
||||
int m_Bits;
|
||||
int m_StopBits;
|
||||
int m_HandShake;
|
||||
int m_MaxTXRetries;
|
||||
int m_DebugInPtr;
|
||||
int m_DebugCount;
|
||||
int m_Item;
|
||||
// struct SerialList *m_TXHead;
|
||||
// struct SerialList *m_TXTail;
|
||||
// struct SerialList *m_RXHead;
|
||||
// struct SerialList *m_RXTail;
|
||||
OVERLAPPED m_ReceiveOLap;
|
||||
OVERLAPPED m_TransmitOLap;
|
||||
OVERLAPPED m_ReadOLap;
|
||||
OVERLAPPED m_WriteOLap;
|
||||
HANDLE m_PortHandle;
|
||||
HANDLE m_ThreadHandle;
|
||||
HANDLE m_ReceiveTaskEvent;
|
||||
|
||||
private:
|
||||
friend unsigned int WINAPI CSerialTask(LPVOID CSerialPtr);
|
||||
|
||||
//Buffer for incomming commands:
|
||||
int CurrentPointer;
|
||||
public:
|
||||
HANDLE m_hWaitCMMResponse;
|
||||
HANDLE m_hNewRx;
|
||||
|
||||
// BV Nov 2001: Made public
|
||||
// CRITICAL_SECTION m_QueueLock;
|
||||
BOOL m_iRecvState;
|
||||
CString m_csRecv;
|
||||
INT m_iRecvByte;
|
||||
};
|
||||
|
||||
#endif // CMMIO_SERIAL_H
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 484 KiB |
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,433 @@
|
||||
// protocol for control SevenOcean's Machine
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifndef AFX_SO7_Proto_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
#define AFX_SO7_Proto_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "..\Tools\UsbUtility\logger.h"
|
||||
#include "CMD_H.h"
|
||||
#include "..\..\..\..\..\ThirdParty\UsbSupport\LibUsb_Win\Include\lusb0_usb.h"
|
||||
#include "..\MicroVu\SsiStatus.h"
|
||||
|
||||
#define MAX_BUFF_SIZE 0x200
|
||||
|
||||
#define USB_ENDPOINT_TYPE_CONTROL 0
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
|
||||
#define USB_ENDPOINT_TYPE_BULK 2
|
||||
#define USB_ENDPOINT_TYPE_INTERRUPT 3
|
||||
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 1
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
|
||||
|
||||
#define THREAD_RUNNING_STATE1 0
|
||||
#define THREAD_RUNNING_STATE2 2
|
||||
#define THREAD_PAUSED 1
|
||||
#define THREAD_EXIT -1
|
||||
|
||||
// Device configuration and interface id.
|
||||
#define SO7_USB_CONFIG 1
|
||||
#define SO7_USB_INTF 0
|
||||
|
||||
|
||||
|
||||
#define EP_S07_01 0x01
|
||||
#define EP_S07_02 0x02
|
||||
#define EP_S07_03 0x03
|
||||
#define EP_S07_81 0x81
|
||||
#define EP_S07_82 0x82
|
||||
#define EP_S07_84 0x84
|
||||
|
||||
#define EP_01_CMD_IDX 0 // index to usb buffers
|
||||
#define EP_81_DATA_IDX 1 //
|
||||
#define EP_02_CMD_IDX 2 //
|
||||
#define EP_82_DATA_IDX 3 //
|
||||
#define EP_03_CMD_IDX 4 //
|
||||
#define EP_84_DATA_IDX 5 //
|
||||
|
||||
#define lEPSIZE 6
|
||||
#define MAXRINGS 5 // for MicroVu Vertex 220
|
||||
#define MAXSEGS 8
|
||||
|
||||
#define TWO_RINGS 2
|
||||
#define EIGHT_SEGS 8
|
||||
#define FIVE_RINGS 5
|
||||
|
||||
const long MAX_INTENSITY = 0x3FF;
|
||||
#define MAXLIGHTVALUE 256
|
||||
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
//****************************************************************************************************
|
||||
// Set the _status to Idle after reply data has been received.
|
||||
// How to recover? In order to send data, _status must be Idle. If the system is not available
|
||||
// for 1 second, assume something wrong and treat it as "TimeOut".
|
||||
// Another way to do this is to lock this structure is to use a mutex to ensure single-threaded
|
||||
// access.
|
||||
//****************************************************************************************************
|
||||
//====================================================================================================
|
||||
|
||||
typedef struct s_so7_axis // axis parameters
|
||||
{
|
||||
char _Move_Speed_Gear;
|
||||
union
|
||||
{
|
||||
long _long_;
|
||||
char _char_[4];
|
||||
}_pos_fixed;
|
||||
union
|
||||
{
|
||||
long _long_;
|
||||
char _char_[4];
|
||||
}_scale_pos;
|
||||
double _d_cur_pos_;
|
||||
long _scale_probe;
|
||||
double _dSet_Zero_Pos;
|
||||
long _lSet_Zero_Pos;
|
||||
} SO7AXIS;
|
||||
struct s_so7_axis_config // axis configuration
|
||||
{
|
||||
double _motor_precision;//set precision
|
||||
double _motor_wheelbase;//set wheelbase
|
||||
|
||||
char _speed_base[5];
|
||||
char _speed_fresh[5];
|
||||
char _speed_start[5];
|
||||
char _speed_max[5];
|
||||
double _speed_slow_dis[5];
|
||||
|
||||
long _scale_range;
|
||||
double _neg_working_limit;
|
||||
double _pos_working_limit;
|
||||
|
||||
double _scale_resolution;
|
||||
bool _bhomed;
|
||||
};
|
||||
struct s_so7_zm_axis_config // zm configuration
|
||||
{
|
||||
int _ComPort;
|
||||
double _StartDegree;
|
||||
double _EndDegree;
|
||||
double _RelativeZeroDegree;
|
||||
double _Deadband;
|
||||
int _ReadingInterval;
|
||||
double _PulseScale;
|
||||
short _SpeedFast;
|
||||
short _SpeedSlow;
|
||||
CString _ProductID;
|
||||
long _neg_working_limit;
|
||||
long _pos_working_limit;
|
||||
double _neg_deg_working_limit; // within the limits
|
||||
double _pos_deg_working_limit;
|
||||
|
||||
union
|
||||
{
|
||||
short _short_;
|
||||
char _char_[2];
|
||||
}_speed;
|
||||
};
|
||||
struct s_so7_machine_interface_config
|
||||
{
|
||||
BOOL _EnCloseLoop;
|
||||
int _RetryTimes;
|
||||
double _ShiftPositionX;
|
||||
double _ShiftPositionY;
|
||||
double _ShiftPositionZ;
|
||||
};
|
||||
|
||||
//======================
|
||||
typedef struct s_so7_xyzzm
|
||||
{
|
||||
bool bFast;
|
||||
long from;
|
||||
long to;
|
||||
long speed;
|
||||
long acc;
|
||||
long dec;
|
||||
double dFromMM;
|
||||
double dToMM;
|
||||
} SO7AXISMOVE;
|
||||
//--------------------------------------------------------------------
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
struct struct_so7_machine
|
||||
{ // g_machine structure
|
||||
struct s_machine_config
|
||||
{
|
||||
double _dXYZSpeed;
|
||||
|
||||
struct s_so7_axis_config x_axis;
|
||||
struct s_so7_axis_config y_axis;
|
||||
struct s_so7_axis_config z_axis;
|
||||
struct s_so7_zm_axis_config zm_axis;
|
||||
struct s_so7_machine_interface_config motion;
|
||||
} s_machine_config;
|
||||
struct s_status
|
||||
{
|
||||
bool _homed;
|
||||
bool _machine_running;
|
||||
bool _bXMoving;
|
||||
bool _bYMoving;
|
||||
bool _bZMoving;
|
||||
bool _bZMMoving;
|
||||
char _bIsZMMotionFinished;
|
||||
bool _bZMHoming;
|
||||
bool _bXYZZMIdle;
|
||||
} s_status;
|
||||
union {
|
||||
struct s_lights_value
|
||||
{
|
||||
char _top_light;
|
||||
char _bottom_light;
|
||||
char _ring_light;
|
||||
char _coaxial_light;
|
||||
char _spare_light1;
|
||||
char segment[TWO_RINGS];
|
||||
} s_lights_value;
|
||||
};
|
||||
char cFixtureFlag;
|
||||
char Light_Size;
|
||||
char Light_Switch;
|
||||
char ADC_Number;
|
||||
int ADC_Value;
|
||||
char Sys_Reset_Flag;
|
||||
char cVerNumber;
|
||||
char InterruptFlag[2];
|
||||
int _motor_pulse_num;
|
||||
|
||||
struct s_so7_axis x;
|
||||
struct s_so7_axis y;
|
||||
struct s_so7_axis z;
|
||||
struct s_so7_axis zm;
|
||||
|
||||
};
|
||||
|
||||
#define SEVENOCEAN_VID 0x4532
|
||||
#define SEVENOCEAN_PID 0x5567
|
||||
|
||||
//****************************************************************************************************
|
||||
// Binary SevenOcean command structure, out going
|
||||
//
|
||||
//****************************************************************************************************
|
||||
#define pSO7_CMD_02 ((s_SO7_CMD_BUFF_02 *) ep_buff[EP_02_CMD_IDX]._buffer)
|
||||
|
||||
struct s_SO7_CMD_BUFF_02
|
||||
{
|
||||
UCHAR uCmdByte;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
BYTE uSubCmdByte;
|
||||
char data[9];
|
||||
}s_SO7_CMD_MOVE_TO_XYZ;
|
||||
struct
|
||||
{
|
||||
BYTE uSubCmdByte;
|
||||
char data[12];
|
||||
}s_SO7_CMD_MOVETOXYZV;
|
||||
struct
|
||||
{
|
||||
BYTE uSubCmdByte;
|
||||
BYTE uStartCmdByte;
|
||||
char _bottom_light;
|
||||
char _top_light;
|
||||
char _ring_light;
|
||||
char _coaxial_light;
|
||||
char _spare_light1;
|
||||
char _outer_ring_light_switch;
|
||||
char _inner_ring_light_switch;
|
||||
BYTE uEndCmdByte;
|
||||
}s_SO7_CMD_SET_LIGHT;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
//======================
|
||||
struct struct_so7_ep_buff
|
||||
{
|
||||
int _ep;
|
||||
BYTE _save_send_cmd;
|
||||
BYTE _save_send_cmd0;
|
||||
BYTE _save_send_cmd1;
|
||||
char *_buffer; // MAX_BUFF_SIZE
|
||||
int _size;
|
||||
void *_async_context;
|
||||
BOOL _hProtoPending;
|
||||
HANDLE _event;
|
||||
};
|
||||
|
||||
//======================================================================================
|
||||
class CSO7_Proto
|
||||
{
|
||||
public:
|
||||
// EP 81/82 channel threads.
|
||||
static int g_hEP8x_Thread_State;
|
||||
static unsigned __stdcall g_EP8x_Thread(LPVOID pThis);
|
||||
static HANDLE g_hEP8x_Thread_Id;
|
||||
|
||||
// EP 02channel threads.
|
||||
static int g_hEP02_Thread_State;
|
||||
static unsigned __stdcall g_EP02_Thread(LPVOID pThis);
|
||||
static HANDLE g_hEP02_Thread_Id;
|
||||
static HANDLE g_hEP02_Serial_Mutex; // EP02
|
||||
|
||||
static HANDLE g_hHomedEvent;
|
||||
|
||||
//
|
||||
CSO7_Proto();
|
||||
virtual ~CSO7_Proto();
|
||||
|
||||
// Global Structures
|
||||
static struct_so7_ep_buff ep_buff[lEPSIZE];
|
||||
static struct_so7_machine g_machine;
|
||||
|
||||
|
||||
SSI_STATUS_MOTION Init_SO7Usb();
|
||||
SSI_STATUS_MOTION Exit_SO7Usb();
|
||||
|
||||
usb_dev_handle* _open_usb_dev(void);
|
||||
SSI_STATUS_MOTION _do_single_threaded_usb_comm(int iEP);
|
||||
|
||||
SSI_STATUS_MOTION _read_data_8x(int iEP_Base);
|
||||
SSI_STATUS_MOTION _send_usb_cmd(int iEP_Base);
|
||||
SSI_STATUS_MOTION _write_usb_data_only(int iEP_Base);
|
||||
static void _process_rcv_transfer_data(int iEP);
|
||||
|
||||
static double TimeInSecs(void);
|
||||
static CLogger* g_pLogger;
|
||||
static usb_dev_handle *g_dev;
|
||||
bool m_bHomingActive;
|
||||
|
||||
double ScaleToMM(long lCount, double dResolution);
|
||||
long MMtoScale(double lDistanceMM, double dResolution);
|
||||
static void Trace_EP_Buff(long lIndex);
|
||||
|
||||
static void _swap_byte(unsigned short &Val);
|
||||
static void _reverse_dword(DWORD *);
|
||||
static void _scale2inch(unsigned long scale, double &inch);
|
||||
static void _inch2scale(unsigned long &scale, double inch);
|
||||
static long _4char2long(unsigned char *cBuff);
|
||||
static long _3char2long(unsigned char *cBuff);
|
||||
static void _char2bin(unsigned char *cBuff, BYTE *cBytes, int len);
|
||||
|
||||
SSI_STATUS_MOTION _replay_capture(CString cFileName);
|
||||
SSI_STATUS_MOTION _process_replay_capture_commands(char *inBuff, FILE* pInFile);
|
||||
SSI_STATUS_MOTION Load_SevenOcean_Inifile(CString csSO7INIFile);
|
||||
SSI_STATUS_MOTION Save_SevenOcean_Inifile(CString csSO7INIFile);
|
||||
SSI_STATUS_MOTION Load_So7_Config();
|
||||
SSI_STATUS_MOTION Save_So7_Config();
|
||||
SSI_STATUS_MOTION GetAppPath(CString &Path);
|
||||
SSI_STATUS_MOTION ExtractAppPath(CString &Path);
|
||||
|
||||
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 _start_machine();
|
||||
SSI_STATUS_MOTION _shutdown_machine();
|
||||
SSI_STATUS_MOTION so7_motion_probe_on_off_(bool _bOnOff);
|
||||
SSI_STATUS_MOTION so7_motion_reset_worktable_lower_left();
|
||||
SSI_STATUS_MOTION so7_motion_reset_worktable_top_right();
|
||||
SSI_STATUS_MOTION so7_motion_stop_motor_to_get_laser_data();
|
||||
SSI_STATUS_MOTION so7_motion_laser_on_off(bool _bOnOff);
|
||||
SSI_STATUS_MOTION so7_motion_fixture_on_off(bool _bOnOff);
|
||||
SSI_STATUS_MOTION so7_motion_fixture_up_down(bool _bOnOff);
|
||||
SSI_STATUS_MOTION so7_motion_reset_controller_parameter();
|
||||
|
||||
SSI_STATUS_MOTION _get_xyz_index(long & lX, long & lY, long & lZ);
|
||||
SSI_STATUS_MOTION so7_motion_get_position_xyz(double & dX, double & dY, double & dZ);
|
||||
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 _calculate_straightline_motion(double dSpeedMM);
|
||||
|
||||
SSI_STATUS_MOTION so7_optics_set_scale_position(long lScale);
|
||||
SSI_STATUS_MOTION so7_optics_get_scale_position(long &lScale);
|
||||
SSI_STATUS_MOTION so7_optics_get_scale_range(long &neg_scale_range, long &pos_scale_range);
|
||||
|
||||
void so7_set_full_ringlight_data(long lIntensity);
|
||||
void so7_set_ringlight_data(long lMaxSize, double *pSegments);
|
||||
|
||||
SSI_STATUS_MOTION so7_light_set_light_off();
|
||||
SSI_STATUS_MOTION so7_light_set_light();
|
||||
SSI_STATUS_MOTION so7_light_set_lamp_state(double dBottomPercent, double dTopPercent);
|
||||
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_X(char SpeedGear);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_Y(char SpeedGear);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_Z(char SpeedGear);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_ZM(char SpeedGear);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_STOP_MOVE_XYZ();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_RESET_XYZ();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_RESET_V();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_STOP_V();
|
||||
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_TO_POS_X();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_TO_POS_Y();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_TO_POS_Z();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_TO_POS_ZM();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_TO_POS_XYZ(char ProbeType);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_TO_POS_XYZV();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_AXIS_XYZ();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_PROBE_XYZ();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_V_DATA();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_GET_RESET_FLAG();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_GET_FIXTURE_VALUE();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_RESET_FLAG();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_LIGHT_SIZE(char subCMD,BYTE LightValue);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_ALL_LIGHT_VALUE();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_VER_NUMBER();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_CORRECTION_SCALE(char cAxisType);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_SECTION(char cAxisType);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_COMMON_COMMAND(char Cmd,char SubCmd,char Type);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_COMMON_COMMAND_DATA(char Cmd,char SubCmd,char Type,char Data);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_ZOOM_SPEED(char xyz_gear);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_SPEED_PARAMETER(char axis_type,char xyz_gear);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_SPEED_PRECISION(char axis_type);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_SPEED_PARAMETER(char axis_type,char xyz_gear);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_MOTOR_SPEED_WHEELBASE_PARAMETER();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_MOTOR_SPEED_WHEELBASE_PARAMETER();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_SPEED_PRECISION(char axis_type);
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_INTERRUPT_MESSAGE();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_ZOOM_MOTION_STATUS();
|
||||
SSI_STATUS_MOTION _send_cmd_SO7_CMD_OPEN_KEYENCE_LASER();
|
||||
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_X();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_Y();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_Z();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_ZM();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_RESET_XYZ();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_TO_POS_X();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_TO_POS_Y();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_TO_POS_Z();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_TO_POS_ZM();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_MOVE_TO_POS_XYZ();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_AXIS_XYZ();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_PROBE_XYZ();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_V_DATA();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_GET_GET_RESET_FLAG();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_GET_GET_FIXTURE_VALUE();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_SET_LIGHT();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_SET_SPEED_PARAMETER();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_SET_SPEED_PRECISION();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_SPEED_PARAMETERX();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_SPEED_PARAMETERY();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_SPEED_PARAMETERZ();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_SET_SPEED_MOTOR_WHEELBASE_PARAMETER();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_MOTOR_SPEED_WHEELBASE_PARAMETER();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_SPEED_PRECISIONX();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_SPEED_PRECISIONY();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_SPEED_PRECISIONZ();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_INTERRUPT_MESSAGE();
|
||||
static SSI_STATUS_MOTION _process_SO7_CMD_READ_ZOOM_MOTION_STATUS();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,238 @@
|
||||
#include "StdAfx.h"
|
||||
#include <WinDef.h>
|
||||
#include <WinBase.h>
|
||||
#include "..\Keyence\LkIF.h"
|
||||
#include "So7_Interface.h "
|
||||
|
||||
#define MAX_STORAGE_DATA_SIZE 65536
|
||||
|
||||
CSo7_Interface::CSo7_Interface()
|
||||
{
|
||||
m_bIsStorage=FALSE;
|
||||
m_iSetOutNo=0;
|
||||
m_StoredDataNumber=0;
|
||||
m_NeedStorageDataNumber=0;
|
||||
|
||||
}
|
||||
|
||||
CSo7_Interface::~CSo7_Interface()
|
||||
{
|
||||
FreeLibrary(m_hImageDLL);
|
||||
}
|
||||
//========================================
|
||||
void CSo7_Interface::KeyenceLaserInit(void)
|
||||
{
|
||||
m_hImageDLL=LoadLibrary(_T("Image.dll"));
|
||||
if(m_hImageDLL)
|
||||
{
|
||||
m_pGetCalcData=(pLKIF_GetCalcData)GetProcAddress(m_hImageDLL,"LKIF_GetCalcData");
|
||||
m_pDataStorageStart=(pLKIF_DataStorageStart)GetProcAddress(m_hImageDLL,"LKIF_DataStorageStart");
|
||||
m_pDataStorageStop=(pLKIF_DataStorageStop)GetProcAddress(m_hImageDLL,"LKIF_DataStorageStop");
|
||||
m_pDataStorageInit=(pLKIF_DataStorageInit)GetProcAddress(m_hImageDLL,"LKIF_DataStorageInit");
|
||||
m_pDataStorageGetData=(pLKIF_DataStorageGetData)GetProcAddress(m_hImageDLL,"LKIF_DataStorageGetData");
|
||||
m_pDataStorageGetStatus=(pLKIF_DataStorageGetStatus)GetProcAddress(m_hImageDLL,"LKIF_DataStorageGetStatus");
|
||||
m_pSetDataStorage=(pLKIF_SetDataStorage)GetProcAddress(m_hImageDLL,"LKIF_SetDataStorage");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//==============================================
|
||||
void CSo7_Interface::Get_KeyenceLaserData(float *LaserValue1,float *LaserValue2)
|
||||
{
|
||||
*LaserValue1=10;
|
||||
*LaserValue2=10;
|
||||
LKIF_FLOATVALUE GetVal1,GetVal2;
|
||||
if(m_pGetCalcData(&GetVal1,&GetVal2)!=1)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
switch(GetVal1.FloatResult)
|
||||
{
|
||||
case LKIF_FLOATRESULT_RANGEOVER_P:
|
||||
{
|
||||
*LaserValue1=50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_RANGEOVER_N:
|
||||
{
|
||||
*LaserValue1=-50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_WAITING:
|
||||
{
|
||||
*LaserValue1=0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*LaserValue1=GetVal1.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(GetVal2.FloatResult)
|
||||
{
|
||||
case LKIF_FLOATRESULT_RANGEOVER_P:
|
||||
{
|
||||
*LaserValue2=50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_RANGEOVER_N:
|
||||
{
|
||||
*LaserValue2=-50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_WAITING:
|
||||
{
|
||||
*LaserValue2=0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*LaserValue2=GetVal2.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================
|
||||
BOOL CSo7_Interface::StartStoreData(int _NeedStorageDataNumber,int _SampleTime)
|
||||
{
|
||||
BOOL bStatus(FALSE);
|
||||
GetStoreDataStatus();
|
||||
if (!m_bIsStorage)
|
||||
{
|
||||
bStatus=m_pDataStorageInit();
|
||||
if (_NeedStorageDataNumber<1)
|
||||
{
|
||||
_NeedStorageDataNumber=1;
|
||||
}
|
||||
else if (_NeedStorageDataNumber>65536)
|
||||
{
|
||||
_NeedStorageDataNumber=65536;
|
||||
}
|
||||
m_NeedStorageDataNumber=_NeedStorageDataNumber;
|
||||
|
||||
if (_SampleTime<0.4)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_1;
|
||||
}
|
||||
else if (_SampleTime<1)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_2;
|
||||
}
|
||||
else if (_SampleTime<2)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_5;
|
||||
}
|
||||
else if (_SampleTime<4)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_10;
|
||||
}
|
||||
else if (_SampleTime<10)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_20;
|
||||
}
|
||||
else if (_SampleTime<20)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_50;
|
||||
}
|
||||
else if (_SampleTime<40)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_100;
|
||||
}
|
||||
else if (_SampleTime<100)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_200;
|
||||
}
|
||||
else if (_SampleTime<200)
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_500;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_StorageCycle=LKIF_STORAGECYCLE_1000;
|
||||
}
|
||||
bStatus=m_pSetDataStorage(LKIF_TARGETOUT_OUT1,m_NeedStorageDataNumber,m_StorageCycle);
|
||||
|
||||
if (bStatus)
|
||||
{
|
||||
bStatus=m_pDataStorageStart();
|
||||
}
|
||||
}
|
||||
return bStatus;
|
||||
};
|
||||
//==============================================
|
||||
BOOL CSo7_Interface::StopStoreData()
|
||||
{
|
||||
BOOL bStatus(FALSE);
|
||||
GetStoreDataStatus();
|
||||
if (m_bIsStorage)
|
||||
{
|
||||
bStatus=m_pDataStorageStop();
|
||||
}
|
||||
return bStatus;
|
||||
};
|
||||
//==============================================
|
||||
BOOL CSo7_Interface::PauseScanAndGetData(float *GetStorageData,int *GetStorageNumber)
|
||||
{
|
||||
BOOL bStatus(FALSE);
|
||||
GetStoreDataStatus();
|
||||
if (m_bIsStorage)
|
||||
{
|
||||
bStatus=m_pDataStorageStop();
|
||||
bStatus=GetStoredData(GetStorageData,GetStorageNumber);
|
||||
bStatus=m_pDataStorageStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
bStatus=GetStoredData(GetStorageData,GetStorageNumber);
|
||||
}
|
||||
return bStatus;
|
||||
};
|
||||
//==============================================
|
||||
BOOL CSo7_Interface::GetStoredData(float *GetStorageData,int *GetStorageNumber)
|
||||
{
|
||||
BOOL bStatus(FALSE);
|
||||
GetStoreDataStatus();
|
||||
if (!m_bIsStorage)
|
||||
{
|
||||
LKIF_FLOATVALUE GetStorageValue[MAX_STORAGE_DATA_SIZE];
|
||||
bStatus=m_pDataStorageGetData(m_iSetOutNo,m_StoredDataNumber,GetStorageValue,GetStorageNumber);
|
||||
for(int i=0;i<*GetStorageNumber;i++)
|
||||
{
|
||||
switch(GetStorageValue[i].FloatResult)
|
||||
{
|
||||
case LKIF_FLOATRESULT_RANGEOVER_P:
|
||||
{
|
||||
*GetStorageData++=50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_RANGEOVER_N:
|
||||
{
|
||||
*GetStorageData++=-50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_WAITING:
|
||||
{
|
||||
*GetStorageData++=0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*GetStorageData++=GetStorageValue[i].Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return bStatus;
|
||||
};
|
||||
//==============================================
|
||||
BOOL CSo7_Interface::GetStoreDataStatus()
|
||||
{
|
||||
BOOL bStatus(FALSE);
|
||||
bStatus=m_pDataStorageGetStatus(m_iSetOutNo,&m_bIsStorage,&m_StoredDataNumber);
|
||||
return bStatus;
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
// protocol for control SevenOcean's Machine
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifndef SO7_INTERFACE_H_INCLUDED_
|
||||
#define SO7_INTERFACE_H_INCLUDED_
|
||||
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
typedef int (WINAPI* pGetLaserStoredData) (float *GetStorageData,int *GetStorageNumber);
|
||||
// Starting the Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageStart)(void);
|
||||
// Stopping the Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageStop)(void);
|
||||
// Initializing the Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageInit)(void);
|
||||
// Outputting the Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageGetData)(IN int OutNo,IN int NumOutBuffer,OUT LKIF_FLOATVALUE *OutBuffer,OUT int *NumReceived);
|
||||
// Data Storage Accumulation Status Output
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageGetStatus)(IN int OutNo,OUT BOOL *IsStorage,OUT int *NumStorageData);
|
||||
// Set Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_SetDataStorage)(IN LKIF_TARGETOUT TargetOut,IN int NumStorage,IN LKIF_STORAGECYCLE StorageCycle);
|
||||
|
||||
//======================================================================================
|
||||
class CSo7_Interface
|
||||
{
|
||||
protected:
|
||||
int m_iSetOutNo;
|
||||
int m_NeedStorageDataNumber;
|
||||
LKIF_STORAGECYCLE m_StorageCycle;
|
||||
HINSTANCE m_hImageDLL;
|
||||
public:
|
||||
|
||||
CSo7_Interface();
|
||||
~CSo7_Interface();
|
||||
|
||||
//»ñÈ¡Êý¾ÝµÄº¯ÊýÖ¸Õë
|
||||
pLKIF_GetCalcData m_pGetCalcData;
|
||||
pLKIF_DataStorageStart m_pDataStorageStart;
|
||||
pLKIF_DataStorageStop m_pDataStorageStop;
|
||||
pLKIF_DataStorageInit m_pDataStorageInit;
|
||||
pLKIF_DataStorageGetData m_pDataStorageGetData;
|
||||
pLKIF_DataStorageGetStatus m_pDataStorageGetStatus;
|
||||
pLKIF_SetDataStorage m_pSetDataStorage;
|
||||
|
||||
int m_StoredDataNumber;
|
||||
BOOL m_bIsStorage;
|
||||
void KeyenceLaserInit(void);
|
||||
void Get_KeyenceLaserData(float *LaserValue1,float *LaserValue2);
|
||||
BOOL StartStoreData(int _NeedStorageDataNumber,int _SampleTime);
|
||||
BOOL StopStoreData();
|
||||
BOOL GetStoreDataStatus();
|
||||
BOOL GetStoredData(float *GetStorageData,int *GetStorageNumber);
|
||||
BOOL PauseScanAndGetData(float *GetStorageData,int *GetStorageNumber);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user