基于接收工程的一些编译和阅读
This commit is contained in:
@@ -207,7 +207,7 @@ double CAutoZoom::ReadZoomAngle()
|
||||
|
||||
char seps[] = "$AD:";
|
||||
|
||||
token = strtok(m_pSO7_Serial->m_RecvData,seps);
|
||||
token = strtok((char *)m_pSO7_Serial->m_RecvData,seps);
|
||||
if (token)
|
||||
{
|
||||
memcpy(cTemp,token,8);
|
||||
|
||||
@@ -3950,7 +3950,7 @@ SSI_STATUS_MOTION CSO7_Proto::_write_usb_data_only(int iEP_Base)
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
//=================================================================
|
||||
// false: probe off 当前探头为激光;true: probe on当前探头为接触式.//
|
||||
// false: probe off ��ǰ̽ͷΪ���⣻true: probe on��ǰ̽ͷΪ�Ӵ�ʽ.//
|
||||
//=================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_probe_on_off_(bool _bOnOff)
|
||||
{
|
||||
@@ -3983,7 +3983,7 @@ SSI_STATUS_MOTION CSO7_Proto::so7_motion_stop_motor_to_get_laser_data()
|
||||
};
|
||||
|
||||
//=================================================================
|
||||
// false: 关闭夹具 ; true: 启动夹具. //
|
||||
// false: �رռо� �� true: ����о�. //
|
||||
//=================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_fixture_on_off(bool _bOnOff)
|
||||
{
|
||||
@@ -3996,7 +3996,7 @@ SSI_STATUS_MOTION CSO7_Proto::so7_motion_fixture_on_off(bool _bOnOff)
|
||||
};
|
||||
|
||||
//=================================================================
|
||||
// false: 夹具下 ; true: 夹具上. //
|
||||
// false: ��� �� true: ���. //
|
||||
//=================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_fixture_up_down(bool _bOnOff)
|
||||
{
|
||||
@@ -4009,7 +4009,7 @@ SSI_STATUS_MOTION CSO7_Proto::so7_motion_fixture_up_down(bool _bOnOff)
|
||||
};
|
||||
|
||||
//==================================================================
|
||||
//false: CT_LASE_TIMMER_ON 关马达; true: CT_LASE_TIMMER_OFF 开马达//
|
||||
//false: CT_LASE_TIMMER_ON ���� true: CT_LASE_TIMMER_OFF �����//
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_laser_on_off(bool _bOnOff)
|
||||
{
|
||||
@@ -4160,7 +4160,7 @@ SSI_STATUS_MOTION CSO7_Proto::so7_motion_Dcc_HomeXYZ(char cHomeMachineMode)
|
||||
SetEvent(g_hHomedEvent);
|
||||
return SSI_STATUS_MOTION_NORMAL;
|
||||
}
|
||||
//查询是否复位
|
||||
//��ѯ�Ƿ�λ
|
||||
_send_cmd_SO7_CMD_GET_RESET_FLAG();
|
||||
g_machine.cVerNumber=3;
|
||||
if (g_machine.Sys_Reset_Flag == 1)
|
||||
@@ -4239,7 +4239,7 @@ SSI_STATUS_MOTION CSO7_Proto::so7_Motion_R_IsHomed(bool &bHomed)
|
||||
//==================================================================
|
||||
SSI_STATUS_MOTION CSO7_Proto::so7_motion_Dcc_Home_R()
|
||||
{
|
||||
//查询是否复位
|
||||
//��ѯ�Ƿ�λ
|
||||
if (g_so7_config.m_bDebugOutputEnable>=1)
|
||||
{
|
||||
g_pLogger->SendAndFlushWithTime(_T("Enter so7_motion_Dcc_Home_R.\n"));
|
||||
@@ -6054,7 +6054,7 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_X()
|
||||
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer) = CT_MOTOR;
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+1) = CT_MOVETOX;
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=(((g_machine.x._pos_fixed._char_[3])<0x80)?(g_machine.x._pos_fixed._char_[2]):((g_machine.x._pos_fixed._char_[2])|0x80));//最高位
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=(((g_machine.x._pos_fixed._char_[3])<0x80)?(g_machine.x._pos_fixed._char_[2]):((g_machine.x._pos_fixed._char_[2])|0x80));//���λ
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+3)=(g_machine.x._pos_fixed._char_[1]);
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+4)=(g_machine.x._pos_fixed._char_[0]);
|
||||
|
||||
@@ -6076,7 +6076,7 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_Y()
|
||||
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer) = CT_MOTOR;
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+1) = CT_MOVETOY;
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=(((g_machine.y._pos_fixed._char_[3])<0x80)?(g_machine.y._pos_fixed._char_[2]):((g_machine.y._pos_fixed._char_[2])|0x80));//最高位
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=(((g_machine.y._pos_fixed._char_[3])<0x80)?(g_machine.y._pos_fixed._char_[2]):((g_machine.y._pos_fixed._char_[2])|0x80));//���λ
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+3)=(g_machine.y._pos_fixed._char_[1]);
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+4)=(g_machine.y._pos_fixed._char_[0]);
|
||||
|
||||
@@ -6101,13 +6101,13 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_Z()
|
||||
if(g_machine.z._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.z._pos_fixed._long_=-g_machine.z._pos_fixed._long_;
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=((g_machine.z._pos_fixed._char_[2])|0x80);//最高位
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=((g_machine.z._pos_fixed._char_[2])|0x80);//���λ
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+3)=(g_machine.z._pos_fixed._char_[1]);
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+4)=(g_machine.z._pos_fixed._char_[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=(g_machine.z._pos_fixed._char_[2]);//最高位
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=(g_machine.z._pos_fixed._char_[2]);//���λ
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+3)=(g_machine.z._pos_fixed._char_[1]);
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+4)=(g_machine.z._pos_fixed._char_[0]);
|
||||
}
|
||||
@@ -6134,13 +6134,13 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_ZM()
|
||||
if(g_machine.zm._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.zm._pos_fixed._long_=-g_machine.zm._pos_fixed._long_;
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=((g_machine.zm._pos_fixed._char_[2])|0x80);//最高位
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=((g_machine.zm._pos_fixed._char_[2])|0x80);//���λ
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+3)=(g_machine.zm._pos_fixed._char_[1]);
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+4)=(g_machine.zm._pos_fixed._char_[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=(g_machine.zm._pos_fixed._char_[2]);//最高位
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+2)=(g_machine.zm._pos_fixed._char_[2]);//���λ
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+3)=(g_machine.zm._pos_fixed._char_[1]);
|
||||
*(ep_buff[EP_02_CMD_IDX]._buffer+4)=(g_machine.zm._pos_fixed._char_[0]);
|
||||
}
|
||||
@@ -6166,14 +6166,14 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_XYZ(char ProbeType)
|
||||
if(g_machine.x._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.x._pos_fixed._long_=-g_machine.x._pos_fixed._long_;
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[0]=(g_machine.x._pos_fixed._char_[2] | 0x80);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[0]=(g_machine.x._pos_fixed._char_[2] | 0x80);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[1]=(g_machine.x._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[2]=(g_machine.x._pos_fixed._char_[0]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[0]=(g_machine.x._pos_fixed._char_[2]);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[0]=(g_machine.x._pos_fixed._char_[2]);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[1]=(g_machine.x._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[2]=(g_machine.x._pos_fixed._char_[0]);
|
||||
}
|
||||
@@ -6181,14 +6181,14 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_XYZ(char ProbeType)
|
||||
if(g_machine.y._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.y._pos_fixed._long_=-g_machine.y._pos_fixed._long_;
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[3]=(g_machine.y._pos_fixed._char_[2] | 0x80);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[3]=(g_machine.y._pos_fixed._char_[2] | 0x80);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[4]=(g_machine.y._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[5]=(g_machine.y._pos_fixed._char_[0]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[3]=(g_machine.y._pos_fixed._char_[2]);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[3]=(g_machine.y._pos_fixed._char_[2]);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[4]=(g_machine.y._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[5]=(g_machine.y._pos_fixed._char_[0]);
|
||||
}
|
||||
@@ -6196,14 +6196,14 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_XYZ(char ProbeType)
|
||||
if(g_machine.z._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.z._pos_fixed._long_=-g_machine.z._pos_fixed._long_;
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[6]=(g_machine.z._pos_fixed._char_[2] | 0x80);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[6]=(g_machine.z._pos_fixed._char_[2] | 0x80);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[7]=(g_machine.z._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[8]=(g_machine.z._pos_fixed._char_[0]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[6]=(g_machine.z._pos_fixed._char_[2]);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[6]=(g_machine.z._pos_fixed._char_[2]);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[7]=(g_machine.z._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVE_TO_XYZ.data[8]=(g_machine.z._pos_fixed._char_[0]);
|
||||
}
|
||||
@@ -6231,14 +6231,14 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_XYZV()
|
||||
if(g_machine.x._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.x._pos_fixed._long_=-g_machine.x._pos_fixed._long_;
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[0]=(g_machine.x._pos_fixed._char_[2] | 0x80);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[0]=(g_machine.x._pos_fixed._char_[2] | 0x80);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[1]=(g_machine.x._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[2]=(g_machine.x._pos_fixed._char_[0]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[0]=(g_machine.x._pos_fixed._char_[2]);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[0]=(g_machine.x._pos_fixed._char_[2]);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[1]=(g_machine.x._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[2]=(g_machine.x._pos_fixed._char_[0]);
|
||||
}
|
||||
@@ -6246,14 +6246,14 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_XYZV()
|
||||
if(g_machine.y._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.y._pos_fixed._long_=-g_machine.y._pos_fixed._long_;
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[3]=(g_machine.y._pos_fixed._char_[2] | 0x80);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[3]=(g_machine.y._pos_fixed._char_[2] | 0x80);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[4]=(g_machine.y._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[5]=(g_machine.y._pos_fixed._char_[0]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[3]=(g_machine.y._pos_fixed._char_[2]);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[3]=(g_machine.y._pos_fixed._char_[2]);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[4]=(g_machine.y._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[5]=(g_machine.y._pos_fixed._char_[0]);
|
||||
}
|
||||
@@ -6261,14 +6261,14 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_XYZV()
|
||||
if(g_machine.z._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.z._pos_fixed._long_=-g_machine.z._pos_fixed._long_;
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[6]=(g_machine.z._pos_fixed._char_[2] | 0x80);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[6]=(g_machine.z._pos_fixed._char_[2] | 0x80);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[7]=(g_machine.z._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[8]=(g_machine.z._pos_fixed._char_[0]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[6]=(g_machine.z._pos_fixed._char_[2]);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[6]=(g_machine.z._pos_fixed._char_[2]);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[7]=(g_machine.z._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[8]=(g_machine.z._pos_fixed._char_[0]);
|
||||
}
|
||||
@@ -6276,14 +6276,14 @@ SSI_STATUS_MOTION CSO7_Proto::_send_cmd_SO7_CMD_MOVE_TO_POS_XYZV()
|
||||
if(g_machine.zm._pos_fixed._long_<0)
|
||||
{
|
||||
g_machine.zm._pos_fixed._long_=-g_machine.z._pos_fixed._long_;
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[6]=(g_machine.zm._pos_fixed._char_[2] | 0x80);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[6]=(g_machine.zm._pos_fixed._char_[2] | 0x80);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[7]=(g_machine.zm._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[8]=(g_machine.zm._pos_fixed._char_[0]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[9]=(g_machine.zm._pos_fixed._char_[2]);//最高位
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[9]=(g_machine.zm._pos_fixed._char_[2]);//���λ
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[10]=(g_machine.zm._pos_fixed._char_[1]);
|
||||
pSO7_CMD_02->s_SO7_CMD_MOVETOXYZV.data[11]=(g_machine.zm._pos_fixed._char_[0]);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "..\Tools\UsbUtility\logger.h"
|
||||
#include "CMD_H.h"
|
||||
#include "..\..\..\..\..\ThirdParty\UsbSupport\LibUsb_Win\Include\lusb0_usb.h"
|
||||
#include "./lusb0_usb.h"
|
||||
#include "SO7_Proto_Def.h"
|
||||
|
||||
#define MAX_BUFF_SIZE 0x200
|
||||
|
||||
@@ -97,7 +97,7 @@ void CSo7_Interface::PauseScanAndGetData(void)
|
||||
//========================================
|
||||
int CSo7_Interface::Pro_Face_Du(MY3DPoint* pArr, int n, double* Coe, double* Error, double& dis)
|
||||
{
|
||||
//g_Set_Face_Flag 1--双向最大值差 2--平均值 3--正向最大值
|
||||
//g_Set_Face_Flag 1--双向最大值差 2--平均值 3--正向最大值
|
||||
double dis1(0.0),dis2(0.0),dis3(0.0);
|
||||
double sum(0.0);
|
||||
double d1=pArr[0].z;
|
||||
|
||||
+188
-186
@@ -13,244 +13,247 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
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;
|
||||
m_RXTempPtr = nullptr;
|
||||
m_RXHead = nullptr;
|
||||
m_RXTail = nullptr;
|
||||
m_SXTempPtr = nullptr;
|
||||
m_SXHead = nullptr;
|
||||
m_SXTail = nullptr;
|
||||
CurrentPointer = 0;
|
||||
m_iNbMsgWaiting = 0;
|
||||
m_terminator = '\0';
|
||||
m_usesTerminator = FALSE;
|
||||
m_pReceiveNotify = nullptr;
|
||||
}
|
||||
|
||||
void CMMIO::SetCallback(CMMIO::p_fstr ptr)
|
||||
void CMMIO::SetCallback(p_fstr ptr)
|
||||
{
|
||||
m_pReceiveNotify = ptr;
|
||||
m_pReceiveNotify = ptr;
|
||||
}
|
||||
|
||||
DWORD CMMIO::Send(CString buffer, BOOL needsResponse/*=FALSE*/)
|
||||
{
|
||||
//ZH 12-12-05 EnterCriticalSection(&m_QueueLock); //ZH-122904
|
||||
//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;
|
||||
}
|
||||
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);
|
||||
auto 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);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
LocBuffer[i] = static_cast<char>(ptr[i] & 0xff);
|
||||
}
|
||||
DWORD res = Send(LocBuffer, length, needsResponse);
|
||||
|
||||
//ZH 12-12-05 LeaveCriticalSection( &m_QueueLock ); //ZH-122904
|
||||
//ZH 12-12-05 LeaveCriticalSection( &m_QueueLock ); //ZH-122904
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
// GetNextReceived() : Helper function, rreturns receives messages placed in the queue
|
||||
// by LineReceive()
|
||||
//
|
||||
int CMMIO::GetNextReceived(char *inputBuf)
|
||||
int CMMIO::GetNextReceived(char* inputBuf)
|
||||
{
|
||||
struct SerialList *Free;
|
||||
int cnt=0;
|
||||
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;
|
||||
// If there is a previous block then delete it
|
||||
if (nullptr != m_RXTempPtr)
|
||||
delete[] m_RXTempPtr;
|
||||
m_RXTempPtr = nullptr;
|
||||
|
||||
// We are messing with pointers so use the CriticalSection
|
||||
// EnterCriticalSection(&m_QueueLock);
|
||||
// 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;
|
||||
// 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
|
||||
// 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);
|
||||
}
|
||||
// move over the data to the user's buffer
|
||||
if (nullptr != inputBuf)
|
||||
memcpy(inputBuf, m_RXTempPtr, cnt);
|
||||
}
|
||||
|
||||
if( m_RXHead == NULL )
|
||||
m_RXTail = NULL;
|
||||
if (m_RXHead == nullptr)
|
||||
m_RXTail = nullptr;
|
||||
|
||||
// All done so out of the CriticalSection
|
||||
// LeaveCriticalSection( &m_QueueLock );
|
||||
// All done so out of the CriticalSection
|
||||
// LeaveCriticalSection( &m_QueueLock );
|
||||
|
||||
return(cnt);
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
int CMMIO::AddReceived( const char *Buffer,DWORD Bytes)
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
//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
|
||||
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;
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
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; */
|
||||
// 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,
|
||||
auto 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__;
|
||||
Ptr->Bytes = count, __FILE__, __LINE__;
|
||||
#endif
|
||||
Ptr->Next = NULL;
|
||||
memcpy( Ptr->Buffer, Buffer2, count );
|
||||
Ptr->Buffer[count] = 0;
|
||||
Ptr->Next = nullptr;
|
||||
memcpy(Ptr->Buffer, Buffer2, count);
|
||||
Ptr->Buffer[count] = 0;
|
||||
|
||||
memcpy(m_sLastMessage,Buffer2,count); //copy to last message
|
||||
m_sLastMessage[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;
|
||||
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"));
|
||||
// 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);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
struct SerialList* Free;
|
||||
|
||||
// Delete the contents of the temp rx pointer if any
|
||||
delete[] m_RXTempPtr;
|
||||
m_RXTempPtr = NULL;
|
||||
// Delete the contents of the temp rx pointer if any
|
||||
delete[] m_RXTempPtr;
|
||||
m_RXTempPtr = nullptr;
|
||||
|
||||
// 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;
|
||||
// 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 = nullptr;
|
||||
|
||||
// for now we are not using the Transmit list
|
||||
// for now we are not using the Transmit list
|
||||
#if 0
|
||||
|
||||
while( m_TXHead )
|
||||
@@ -262,11 +265,10 @@ DWORD CMMIO::Close()
|
||||
}
|
||||
m_TXHead = NULL;
|
||||
#endif
|
||||
// LeaveCriticalSection( &m_QueueLock );
|
||||
return(TRUE);
|
||||
|
||||
// LeaveCriticalSection( &m_QueueLock );
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// END OF BASE CLASS CMMIO
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
+580
-585
File diff suppressed because it is too large
Load Diff
+46
-43
@@ -6,15 +6,18 @@
|
||||
|
||||
enum eThreadSignal
|
||||
{
|
||||
THREAD_STATE_RUNNING, // Current state of the thread
|
||||
THREAD_STATE_EXIT // Signal to thread to exit
|
||||
THREAD_STATE_RUNNING,
|
||||
// Current state of the thread
|
||||
THREAD_STATE_EXIT // Signal to thread to exit
|
||||
};
|
||||
unsigned __stdcall ReadLightData(LPVOID pThis);
|
||||
eThreadSignal _serial_WatchThreadState;
|
||||
const char DigitalLuxMeter_StopDatas[9] = { 0X3C,0X02,0X00,0X00,0X00,0X00,0X00,0XDE,0X00 };
|
||||
const char DigitalLuxMeter_StartDatas[9] = { 0X1E,0X00,0X00,0X00,0X00,0X00,0X00,0X1E,0X00 };
|
||||
const char DigitalLuxMeter_BeginDatas[9] = { 0X3C,0X01,0X00,0X00,0X00,0X00,0X00,0X3D,0X00 };
|
||||
|
||||
unsigned __stdcall ReadLightData(LPVOID pThis);
|
||||
eThreadSignal _serial_WatchThreadState;
|
||||
const char DigitalLuxMeter_StopDatas[9] = {0X3C, 0X02, 0X00, 0X00, 0X00, 0X00, 0X00, 0XDE, 0X00};
|
||||
const char DigitalLuxMeter_StartDatas[9] = {0X1E, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X1E, 0X00};
|
||||
const char DigitalLuxMeter_BeginDatas[9] = {0X3C, 0X01, 0X00, 0X00, 0X00, 0X00, 0X00, 0X3D, 0X00};
|
||||
HANDLE _smc_WatchThreadHandle;
|
||||
|
||||
CGetDigitalLuxMeterValue::CGetDigitalLuxMeterValue()
|
||||
{
|
||||
m_iSerialComPort = 1;
|
||||
@@ -22,13 +25,13 @@ CGetDigitalLuxMeterValue::CGetDigitalLuxMeterValue()
|
||||
m_iSleepTime = 50;
|
||||
m_dCabStep = 0.1;
|
||||
m_iCompareGap = 25;
|
||||
m_iSelectLightType = 0;
|
||||
m_iRoadBoardNum = 1;
|
||||
m_iGetWhichRingForInitValue = 2;
|
||||
m_iRingGapSleepTime = 20;
|
||||
m_iSelectLightType = 0;
|
||||
m_iRoadBoardNum = 1;
|
||||
m_iGetWhichRingForInitValue = 2;
|
||||
m_iRingGapSleepTime = 20;
|
||||
m_bIsEnableToGetLuxValue = true;
|
||||
m_bGetSingleRingInitValue = true;
|
||||
m_bPopUpPromptDialog = false;
|
||||
m_bGetSingleRingInitValue = true;
|
||||
m_bPopUpPromptDialog = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,32 +52,32 @@ void CGetDigitalLuxMeterValue::LoadConfig()
|
||||
//CString strRS232BuadRate = _T("DigitalLuxMeterRS232BuadRate");
|
||||
CString strRS232SleepTime = _T("DigitalLuxMeterRS232SleepTime");
|
||||
CString strRS232CabStep = _T("DigitalLuxMeterCabStep");
|
||||
CString strRS232LightType= _T("LightType");
|
||||
CString strRS232RoadBoardNum = _T("RoadBoardNum");
|
||||
CString strRS232CabCompGap = _T("DigitalLuxMeterCabCompGap");
|
||||
CString strRS232CabGetSingRingInitValue = _T("DigitalLuxMeterGetSingRingInitValue");
|
||||
CString strRS232CabGetWhichRingForInitValue = _T("DigitalLuxMeterGetWhichRingForInitValue");
|
||||
CString strPopUpPromptDialog = _T("PopUpPromptDialog");
|
||||
CString strRingGapSleepTime = _T("RingGapSleepTime");
|
||||
CString strRS232LightType = _T("LightType");
|
||||
CString strRS232RoadBoardNum = _T("RoadBoardNum");
|
||||
CString strRS232CabCompGap = _T("DigitalLuxMeterCabCompGap");
|
||||
CString strRS232CabGetSingRingInitValue = _T("DigitalLuxMeterGetSingRingInitValue");
|
||||
CString strRS232CabGetWhichRingForInitValue = _T("DigitalLuxMeterGetWhichRingForInitValue");
|
||||
CString strPopUpPromptDialog = _T("PopUpPromptDialog");
|
||||
CString strRingGapSleepTime = _T("RingGapSleepTime");
|
||||
ReadWriteIni rIni(strFileName);
|
||||
rIni.setSection(strKeyName);
|
||||
m_bIsEnableToGetLuxValue = rIni.getBool(strRS232Enable, false, true);
|
||||
m_bPopUpPromptDialog = rIni.getBool(strPopUpPromptDialog, false, true);
|
||||
m_iSerialComPort = rIni.getInt(strRS232ComNum, 1, true);
|
||||
m_bPopUpPromptDialog = rIni.getBool(strPopUpPromptDialog, false, true);
|
||||
m_iSerialComPort = rIni.getInt(strRS232ComNum, 1, true);
|
||||
m_iBuadRate = 19200;
|
||||
//m_iBuadRate = rIni.getInt(strRS232BuadRate, 19200);
|
||||
m_iSleepTime = rIni.getInt(strRS232SleepTime, 100, true);
|
||||
m_dCabStep = rIni.getDouble(strRS232CabStep, 0.1, true);
|
||||
m_iCompareGap = rIni.getInt(strRS232CabCompGap, 25, true);
|
||||
m_iRoadBoardNum = rIni.getInt(strRS232RoadBoardNum, 1, true);
|
||||
m_iSelectLightType = rIni.getInt(strRS232LightType, 0, true);
|
||||
m_bGetSingleRingInitValue = rIni.getBool(strRS232CabGetSingRingInitValue, true, true);
|
||||
m_iGetWhichRingForInitValue = rIni.getInt(strRS232CabGetWhichRingForInitValue, 2, true);
|
||||
m_iRingGapSleepTime = rIni.getInt(strRingGapSleepTime, 20, true);
|
||||
if ((m_iGetWhichRingForInitValue > 5) || (m_iGetWhichRingForInitValue < 0))
|
||||
{
|
||||
m_iGetWhichRingForInitValue = 2;
|
||||
}
|
||||
m_iCompareGap = rIni.getInt(strRS232CabCompGap, 25, true);
|
||||
m_iRoadBoardNum = rIni.getInt(strRS232RoadBoardNum, 1, true);
|
||||
m_iSelectLightType = rIni.getInt(strRS232LightType, 0, true);
|
||||
m_bGetSingleRingInitValue = rIni.getBool(strRS232CabGetSingRingInitValue, true, true);
|
||||
m_iGetWhichRingForInitValue = rIni.getInt(strRS232CabGetWhichRingForInitValue, 2, true);
|
||||
m_iRingGapSleepTime = rIni.getInt(strRingGapSleepTime, 20, true);
|
||||
if ((m_iGetWhichRingForInitValue > 5) || (m_iGetWhichRingForInitValue < 0))
|
||||
{
|
||||
m_iGetWhichRingForInitValue = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void CGetDigitalLuxMeterValue::SaveIni()
|
||||
@@ -89,8 +92,8 @@ void CGetDigitalLuxMeterValue::SaveIni()
|
||||
//CString strRS232BuadRate = _T("DigitalLuxMeterRS232BuadRate");
|
||||
CString strRS232SleepTime = _T("DigitalLuxMeterRS232SleepTime");
|
||||
CString strRS232CabStep = _T("DigitalLuxMeterCabStep");
|
||||
CString strRS232LightType = _T("LightType");
|
||||
CString strRS232RoadBoardNum = _T("RoadBoardNum");
|
||||
CString strRS232LightType = _T("LightType");
|
||||
CString strRS232RoadBoardNum = _T("RoadBoardNum");
|
||||
CString strRS232CabCompGap = _T("DigitalLuxMeterCabCompGap");
|
||||
CString strRS232CabGetSingRingInitValue = _T("DigitalLuxMeterGetSingRingInitValue");
|
||||
CString strRS232CabGetWhichRingForInitValue = _T("DigitalLuxMeterGetWhichRingForInitValue");
|
||||
@@ -100,17 +103,17 @@ void CGetDigitalLuxMeterValue::SaveIni()
|
||||
wIni.setInt(strRS232ComNum, m_iSerialComPort);
|
||||
wIni.setInt(strRS232SleepTime, m_iSleepTime);
|
||||
wIni.setDouble(strRS232CabStep, m_dCabStep);
|
||||
wIni.setInt(strRS232RoadBoardNum, m_iRoadBoardNum);
|
||||
wIni.setInt(strRS232LightType, m_iSelectLightType);
|
||||
wIni.setInt(strRS232RoadBoardNum, m_iRoadBoardNum);
|
||||
wIni.setInt(strRS232LightType, m_iSelectLightType);
|
||||
wIni.setInt(strRS232CabCompGap, m_iCompareGap);
|
||||
wIni.setBool(strRS232CabGetSingRingInitValue, m_bGetSingleRingInitValue);
|
||||
wIni.setInt(strRS232CabGetWhichRingForInitValue, m_iGetWhichRingForInitValue);
|
||||
//wIni.setInt(strRS232BuadRate, m_iBuadRate);
|
||||
}
|
||||
|
||||
unsigned __stdcall ReadLightData(LPVOID pThis)
|
||||
unsigned __stdcall ReadLightData(LPVOID pThis)
|
||||
{
|
||||
CGetDigitalLuxMeterValue* _pThis = (CGetDigitalLuxMeterValue*)pThis;
|
||||
auto _pThis = static_cast<CGetDigitalLuxMeterValue*>(pThis);
|
||||
while (_serial_WatchThreadState == THREAD_STATE_RUNNING)
|
||||
{
|
||||
_pThis->OnGetRealTimeDigitalLuxMeterValueResult();
|
||||
@@ -140,15 +143,15 @@ BOOL CGetDigitalLuxMeterValue::OnInit()
|
||||
CString str = (L"Serial port open failed!");
|
||||
str.AppendFormat((L"Port Number:"));
|
||||
str.AppendFormat(_T("%d "), m_iSerialComPort);
|
||||
MessageBoxEx(NULL, str, (L"Serial port"), MB_OK | MB_SYSTEMMODAL, MB_SYSTEMMODAL);
|
||||
MessageBoxEx(nullptr, str, (L"Serial port"), MB_OK | MB_SYSTEMMODAL, MB_SYSTEMMODAL);
|
||||
}
|
||||
BOOL bReady = OnStartDigitalLuxMeter();
|
||||
if (bReady)
|
||||
{
|
||||
_serial_WatchThreadState = THREAD_STATE_RUNNING;
|
||||
_smc_WatchThreadHandle = CreateThread((LPSECURITY_ATTRIBUTES)NULL,
|
||||
0, (LPTHREAD_START_ROUTINE)ReadLightData,
|
||||
this, 0, NULL);
|
||||
_smc_WatchThreadHandle = CreateThread(nullptr,
|
||||
0, (LPTHREAD_START_ROUTINE)ReadLightData,
|
||||
this, 0, nullptr);
|
||||
}
|
||||
}
|
||||
return bInitState;
|
||||
@@ -284,4 +287,4 @@ void CGetDigitalLuxMeterValue::OnGetRealTimeDigitalLuxMeterValueResult()
|
||||
{
|
||||
Sleep(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+107
-73
@@ -1,4 +1,3 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ReadWriteIni.h"
|
||||
|
||||
@@ -11,140 +10,175 @@
|
||||
|
||||
ReadWriteIni::ReadWriteIni()
|
||||
{
|
||||
m_nDefDoubleBitNum = 6;
|
||||
setSection(_T("Defalut"));
|
||||
m_nDefDoubleBitNum = 6;
|
||||
setSection(_T("Defalut"));
|
||||
}
|
||||
|
||||
ReadWriteIni::ReadWriteIni(const wchar_t* szFilePath)
|
||||
{
|
||||
m_nDefDoubleBitNum = 6;
|
||||
LoadFile(szFilePath);
|
||||
setSection(_T("Defalut"));
|
||||
m_nDefDoubleBitNum = 6;
|
||||
LoadFile(szFilePath);
|
||||
setSection(_T("Defalut"));
|
||||
}
|
||||
|
||||
ReadWriteIni::ReadWriteIni(const wchar_t* szFilePath, const wchar_t* szSection)
|
||||
{
|
||||
m_nDefDoubleBitNum = 6;
|
||||
LoadFile(szFilePath);
|
||||
setSection(szSection);
|
||||
m_nDefDoubleBitNum = 6;
|
||||
LoadFile(szFilePath);
|
||||
setSection(szSection);
|
||||
}
|
||||
|
||||
bool ReadWriteIni::LoadFile(const wchar_t* szFilePath)
|
||||
{
|
||||
::GetFullPathNameW(szFilePath, MAX_PATH, m_szFilePath, NULL);
|
||||
setSection(_T("Defalut"));
|
||||
return true;
|
||||
GetFullPathNameW(szFilePath, MAX_PATH, m_szFilePath, nullptr);
|
||||
setSection(_T("Defalut"));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReadWriteIni::SaveFile()
|
||||
{
|
||||
setSection(L"XXX{B1CAE400-AF03-40E4-A1CE-30F2134309DE}XXX");
|
||||
delSection(L"XXX{B1CAE400-AF03-40E4-A1CE-30F2134309DE}XXX");
|
||||
setSection(m_szSection);
|
||||
return true;
|
||||
setSection(L"XXX{B1CAE400-AF03-40E4-A1CE-30F2134309DE}XXX");
|
||||
delSection(L"XXX{B1CAE400-AF03-40E4-A1CE-30F2134309DE}XXX");
|
||||
setSection(m_szSection);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ReadWriteIni::setSection(const wchar_t* szSection)
|
||||
{
|
||||
wcscpy_s(m_szSection, szSection);
|
||||
return;
|
||||
wcscpy_s(m_szSection, szSection);
|
||||
}
|
||||
|
||||
bool ReadWriteIni::delSection(const wchar_t* szSection)
|
||||
{
|
||||
return ::WritePrivateProfileStringW(szSection, NULL, NULL, m_szFilePath);
|
||||
return WritePrivateProfileStringW(szSection, nullptr, nullptr, m_szFilePath);
|
||||
}
|
||||
|
||||
bool ReadWriteIni::delKeyName(const wchar_t* szKeyName)
|
||||
{
|
||||
return ::WritePrivateProfileStringW(m_szSection, szKeyName, NULL, m_szFilePath);
|
||||
return WritePrivateProfileStringW(m_szSection, szKeyName, nullptr, m_szFilePath);
|
||||
}
|
||||
|
||||
bool ReadWriteIni::setInt(const wchar_t* szKey, int nVal)
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%d", nVal);
|
||||
return ::WritePrivateProfileStringW(m_szSection, szKey, m_szValTemp, m_szFilePath);
|
||||
swprintf_s(m_szValTemp, L"%d", nVal);
|
||||
return WritePrivateProfileStringW(m_szSection, szKey, m_szValTemp, m_szFilePath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ReadWriteIni::getInt(const wchar_t* szKey, int nDefVal /*= 0*/, bool bAddIfUnexist /*= false*/)
|
||||
{
|
||||
int UnExistNumber = LIMIT_MAX_32INT;
|
||||
int nVal = ::GetPrivateProfileIntW(m_szSection, szKey, UnExistNumber, m_szFilePath);
|
||||
if (nVal == UnExistNumber)
|
||||
{
|
||||
if (bAddIfUnexist)
|
||||
setInt(szKey, nDefVal);
|
||||
return nDefVal;
|
||||
}
|
||||
return nVal;
|
||||
int UnExistNumber = LIMIT_MAX_32INT;
|
||||
int nVal = GetPrivateProfileIntW(m_szSection, szKey, UnExistNumber, m_szFilePath);
|
||||
if (nVal == UnExistNumber)
|
||||
{
|
||||
if (bAddIfUnexist)
|
||||
setInt(szKey, nDefVal);
|
||||
return nDefVal;
|
||||
}
|
||||
return nVal;
|
||||
}
|
||||
|
||||
|
||||
bool ReadWriteIni::setBool(const wchar_t* szKey, bool bVal)
|
||||
{
|
||||
return setInt(szKey, (int)bVal);
|
||||
return setInt(szKey, bVal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ReadWriteIni::getBool(const wchar_t* szKey, bool bDefVal /*= false*/, bool bAddIfUnexist /*= false*/)
|
||||
{
|
||||
return (bool)getInt(szKey, bDefVal, bAddIfUnexist);
|
||||
return static_cast<bool>(getInt(szKey, bDefVal, bAddIfUnexist));
|
||||
}
|
||||
|
||||
bool ReadWriteIni::setString(const wchar_t* szKey, const wchar_t* szVal)
|
||||
{
|
||||
return ::WritePrivateProfileStringW(m_szSection, szKey, szVal, m_szFilePath);
|
||||
return WritePrivateProfileStringW(m_szSection, szKey, szVal, m_szFilePath);
|
||||
}
|
||||
|
||||
const wchar_t* ReadWriteIni::getString(const wchar_t* szKey, const wchar_t* szDefVal /*= NULL*/, bool bAddIfUnexist /*= false*/)
|
||||
const wchar_t* ReadWriteIni::getString(const wchar_t* szKey, const wchar_t* szDefVal /*= NULL*/,
|
||||
bool bAddIfUnexist /*= false*/)
|
||||
{
|
||||
::GetPrivateProfileStringW(m_szSection, szKey, szDefVal, m_szValTemp, sizeof(m_szValTemp), m_szFilePath);
|
||||
if (bAddIfUnexist && (m_szValTemp[0] == 0) && (szDefVal != nullptr))
|
||||
{
|
||||
wcscpy_s(m_szValTemp, szDefVal);
|
||||
setString(szKey, szDefVal);
|
||||
}
|
||||
return m_szValTemp;
|
||||
GetPrivateProfileStringW(m_szSection, szKey, szDefVal, m_szValTemp, sizeof(m_szValTemp), m_szFilePath);
|
||||
if (bAddIfUnexist && (m_szValTemp[0] == 0) && (szDefVal != nullptr))
|
||||
{
|
||||
wcscpy_s(m_szValTemp, szDefVal);
|
||||
setString(szKey, szDefVal);
|
||||
}
|
||||
return m_szValTemp;
|
||||
}
|
||||
|
||||
bool ReadWriteIni::setDouble(const wchar_t* szKey, double dVal)
|
||||
{
|
||||
switch (m_nDefDoubleBitNum)
|
||||
{
|
||||
case 1: {swprintf_s(m_szValTemp, L"%.1f", dVal);break;}
|
||||
case 2: {swprintf_s(m_szValTemp, L"%.2f", dVal);break;}
|
||||
case 3: {swprintf_s(m_szValTemp, L"%.3f", dVal);break;}
|
||||
case 4: {swprintf_s(m_szValTemp, L"%.4f", dVal);break;}
|
||||
case 5: {swprintf_s(m_szValTemp, L"%.5f", dVal);break;}
|
||||
case 6: {swprintf_s(m_szValTemp, L"%.6f", dVal);break;}
|
||||
case 7: {swprintf_s(m_szValTemp, L"%.7f", dVal);break;}
|
||||
case 8: {swprintf_s(m_szValTemp, L"%.8f", dVal);break;}
|
||||
case 9: {swprintf_s(m_szValTemp, L"%.9f", dVal);break;}
|
||||
default: {swprintf_s(m_szValTemp, L"%.6f", dVal);break;}
|
||||
}
|
||||
return setString(szKey, m_szValTemp);
|
||||
switch (m_nDefDoubleBitNum)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.1f", dVal);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.2f", dVal);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.3f", dVal);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.4f", dVal);
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.5f", dVal);
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.6f", dVal);
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.7f", dVal);
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.8f", dVal);
|
||||
break;
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.9f", dVal);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
swprintf_s(m_szValTemp, L"%.6f", dVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return setString(szKey, m_szValTemp);
|
||||
}
|
||||
|
||||
double ReadWriteIni::getDouble(const wchar_t* szKey, double dDefVal/*=0*/, bool bAddIfUnexist /*= false*/)
|
||||
{
|
||||
const wchar_t* m_pVal = getString(szKey, 0, false);
|
||||
if (m_pVal[0] != 0)
|
||||
{
|
||||
double dVal = _wtof(m_pVal);
|
||||
return dVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bAddIfUnexist)
|
||||
{
|
||||
setDouble(szKey, dDefVal);
|
||||
}
|
||||
return dDefVal;
|
||||
}
|
||||
return 0.0f;
|
||||
const wchar_t* m_pVal = getString(szKey, nullptr, false);
|
||||
if (m_pVal[0] != 0)
|
||||
{
|
||||
double dVal = _wtof(m_pVal);
|
||||
return dVal;
|
||||
}
|
||||
if (bAddIfUnexist)
|
||||
{
|
||||
setDouble(szKey, dDefVal);
|
||||
}
|
||||
return dDefVal;
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
+1108
-1045
File diff suppressed because it is too large
Load Diff
+4
-5
@@ -1,4 +1,3 @@
|
||||
|
||||
// UtilityForSo7Light.cpp : Defines the class behaviors for the application.
|
||||
//
|
||||
|
||||
@@ -41,7 +40,7 @@ BOOL CUtilityForSo7LightApp::InitInstance()
|
||||
|
||||
// Create the shell manager, in case the dialog contains
|
||||
// any shell tree view or shell list view controls.
|
||||
CShellManager *pShellManager = new CShellManager;
|
||||
auto pShellManager = new CShellManager;
|
||||
|
||||
// Activate "Windows Native" visual manager for enabling themes in MFC controls
|
||||
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
|
||||
@@ -71,11 +70,12 @@ BOOL CUtilityForSo7LightApp::InitInstance()
|
||||
else if (nResponse == -1)
|
||||
{
|
||||
TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n");
|
||||
TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
|
||||
TRACE(traceAppMsg, 0,
|
||||
"Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
|
||||
}
|
||||
|
||||
// Delete the shell manager created above.
|
||||
if (pShellManager != NULL)
|
||||
if (pShellManager != nullptr)
|
||||
{
|
||||
delete pShellManager;
|
||||
}
|
||||
@@ -84,4 +84,3 @@ BOOL CUtilityForSo7LightApp::InitInstance()
|
||||
// application, rather than start the application's message pump.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@@ -14,19 +14,20 @@
|
||||
<ProjectGuid>{BFC37D2E-B136-44A0-9FC6-64A410E6C13A}</ProjectGuid>
|
||||
<RootNamespace>UtilityForSo7Light</RootNamespace>
|
||||
<Keyword>MFCProj</Keyword>
|
||||
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Static</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Static</UseOfMfc>
|
||||
|
||||
+2921
-2846
File diff suppressed because it is too large
Load Diff
+87
@@ -0,0 +1,87 @@
|
||||
|
||||
// UtilityForSo7Light.cpp : Defines the class behaviors for the application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "UtilityForSo7Light.h"
|
||||
#include "UtilityForSo7LightDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
|
||||
// CUtilityForSo7LightApp
|
||||
|
||||
BEGIN_MESSAGE_MAP(CUtilityForSo7LightApp, CWinApp)
|
||||
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// CUtilityForSo7LightApp construction
|
||||
|
||||
CUtilityForSo7LightApp::CUtilityForSo7LightApp()
|
||||
{
|
||||
// TODO: add construction code here,
|
||||
// Place all significant initialization in InitInstance
|
||||
}
|
||||
|
||||
|
||||
// The one and only CUtilityForSo7LightApp object
|
||||
|
||||
CUtilityForSo7LightApp theApp;
|
||||
|
||||
|
||||
// CUtilityForSo7LightApp initialization
|
||||
|
||||
BOOL CUtilityForSo7LightApp::InitInstance()
|
||||
{
|
||||
CWinApp::InitInstance();
|
||||
|
||||
|
||||
// Create the shell manager, in case the dialog contains
|
||||
// any shell tree view or shell list view controls.
|
||||
CShellManager *pShellManager = new CShellManager;
|
||||
|
||||
// Activate "Windows Native" visual manager for enabling themes in MFC controls
|
||||
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
|
||||
|
||||
// Standard initialization
|
||||
// If you are not using these features and wish to reduce the size
|
||||
// of your final executable, you should remove from the following
|
||||
// the specific initialization routines you do not need
|
||||
// Change the registry key under which our settings are stored
|
||||
// TODO: You should modify this string to be something appropriate
|
||||
// such as the name of your company or organization
|
||||
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
|
||||
|
||||
CUtilityForSo7LightDlg dlg;
|
||||
m_pMainWnd = &dlg;
|
||||
INT_PTR nResponse = dlg.DoModal();
|
||||
if (nResponse == IDOK)
|
||||
{
|
||||
// TODO: Place code here to handle when the dialog is
|
||||
// dismissed with OK
|
||||
}
|
||||
else if (nResponse == IDCANCEL)
|
||||
{
|
||||
// TODO: Place code here to handle when the dialog is
|
||||
// dismissed with Cancel
|
||||
}
|
||||
else if (nResponse == -1)
|
||||
{
|
||||
TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n");
|
||||
TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
|
||||
}
|
||||
|
||||
// Delete the shell manager created above.
|
||||
if (pShellManager != NULL)
|
||||
{
|
||||
delete pShellManager;
|
||||
}
|
||||
|
||||
// Since the dialog has been closed, return FALSE so that we exit the
|
||||
// application, rather than start the application's message pump.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
+4045
File diff suppressed because it is too large
Load Diff
+287
@@ -0,0 +1,287 @@
|
||||
#include "stdafx.h"
|
||||
#include "So7_Illumination.h"
|
||||
#include "ReadWriteIni.h"
|
||||
#include "GetDigitalLuxMeterValue.h"
|
||||
|
||||
|
||||
enum eThreadSignal
|
||||
{
|
||||
THREAD_STATE_RUNNING, // Current state of the thread
|
||||
THREAD_STATE_EXIT // Signal to thread to exit
|
||||
};
|
||||
unsigned __stdcall ReadLightData(LPVOID pThis);
|
||||
eThreadSignal _serial_WatchThreadState;
|
||||
const char DigitalLuxMeter_StopDatas[9] = { 0X3C,0X02,0X00,0X00,0X00,0X00,0X00,0XDE,0X00 };
|
||||
const char DigitalLuxMeter_StartDatas[9] = { 0X1E,0X00,0X00,0X00,0X00,0X00,0X00,0X1E,0X00 };
|
||||
const char DigitalLuxMeter_BeginDatas[9] = { 0X3C,0X01,0X00,0X00,0X00,0X00,0X00,0X3D,0X00 };
|
||||
HANDLE _smc_WatchThreadHandle;
|
||||
CGetDigitalLuxMeterValue::CGetDigitalLuxMeterValue()
|
||||
{
|
||||
m_iSerialComPort = 1;
|
||||
m_iBuadRate = 19200;
|
||||
m_iSleepTime = 50;
|
||||
m_dCabStep = 0.1;
|
||||
m_iCompareGap = 25;
|
||||
m_iSelectLightType = 0;
|
||||
m_iRoadBoardNum = 1;
|
||||
m_iGetWhichRingForInitValue = 2;
|
||||
m_iRingGapSleepTime = 20;
|
||||
m_bIsEnableToGetLuxValue = true;
|
||||
m_bGetSingleRingInitValue = true;
|
||||
m_bPopUpPromptDialog = false;
|
||||
}
|
||||
|
||||
|
||||
CGetDigitalLuxMeterValue::~CGetDigitalLuxMeterValue()
|
||||
{
|
||||
_serial_WatchThreadState = THREAD_STATE_EXIT;
|
||||
}
|
||||
|
||||
void CGetDigitalLuxMeterValue::LoadConfig()
|
||||
{
|
||||
CString filePath;
|
||||
CSo7_Illumination oSo7Illum;
|
||||
oSo7Illum.GetAppPath(filePath);
|
||||
CString strFileName = filePath + _T("\\Device.Config.ini");
|
||||
CString strKeyName = _T("DIGITAL_LUX_METER_RS232_SERIALCOMPORT");
|
||||
CString strRS232Enable = _T("DigitalLuxMeterRS232Enable");
|
||||
CString strRS232ComNum = _T("DigitalLuxMeterRS232ComNum");
|
||||
//CString strRS232BuadRate = _T("DigitalLuxMeterRS232BuadRate");
|
||||
CString strRS232SleepTime = _T("DigitalLuxMeterRS232SleepTime");
|
||||
CString strRS232CabStep = _T("DigitalLuxMeterCabStep");
|
||||
CString strRS232LightType= _T("LightType");
|
||||
CString strRS232RoadBoardNum = _T("RoadBoardNum");
|
||||
CString strRS232CabCompGap = _T("DigitalLuxMeterCabCompGap");
|
||||
CString strRS232CabGetSingRingInitValue = _T("DigitalLuxMeterGetSingRingInitValue");
|
||||
CString strRS232CabGetWhichRingForInitValue = _T("DigitalLuxMeterGetWhichRingForInitValue");
|
||||
CString strPopUpPromptDialog = _T("PopUpPromptDialog");
|
||||
CString strRingGapSleepTime = _T("RingGapSleepTime");
|
||||
ReadWriteIni rIni(strFileName);
|
||||
rIni.setSection(strKeyName);
|
||||
m_bIsEnableToGetLuxValue = rIni.getBool(strRS232Enable, false, true);
|
||||
m_bPopUpPromptDialog = rIni.getBool(strPopUpPromptDialog, false, true);
|
||||
m_iSerialComPort = rIni.getInt(strRS232ComNum, 1, true);
|
||||
m_iBuadRate = 19200;
|
||||
//m_iBuadRate = rIni.getInt(strRS232BuadRate, 19200);
|
||||
m_iSleepTime = rIni.getInt(strRS232SleepTime, 100, true);
|
||||
m_dCabStep = rIni.getDouble(strRS232CabStep, 0.1, true);
|
||||
m_iCompareGap = rIni.getInt(strRS232CabCompGap, 25, true);
|
||||
m_iRoadBoardNum = rIni.getInt(strRS232RoadBoardNum, 1, true);
|
||||
m_iSelectLightType = rIni.getInt(strRS232LightType, 0, true);
|
||||
m_bGetSingleRingInitValue = rIni.getBool(strRS232CabGetSingRingInitValue, true, true);
|
||||
m_iGetWhichRingForInitValue = rIni.getInt(strRS232CabGetWhichRingForInitValue, 2, true);
|
||||
m_iRingGapSleepTime = rIni.getInt(strRingGapSleepTime, 20, true);
|
||||
if ((m_iGetWhichRingForInitValue > 5) || (m_iGetWhichRingForInitValue < 0))
|
||||
{
|
||||
m_iGetWhichRingForInitValue = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void CGetDigitalLuxMeterValue::SaveIni()
|
||||
{
|
||||
CString filePath;
|
||||
CSo7_Illumination oSo7Illum;
|
||||
oSo7Illum.GetAppPath(filePath);
|
||||
CString strFileName = filePath + _T("\\Device.Config.ini");
|
||||
CString strKeyName = _T("DIGITAL_LUX_METER_RS232_SERIALCOMPORT");
|
||||
CString strRS232Enable = _T("DigitalLuxMeterRS232Enable");
|
||||
CString strRS232ComNum = _T("DigitalLuxMeterRS232ComNum");
|
||||
//CString strRS232BuadRate = _T("DigitalLuxMeterRS232BuadRate");
|
||||
CString strRS232SleepTime = _T("DigitalLuxMeterRS232SleepTime");
|
||||
CString strRS232CabStep = _T("DigitalLuxMeterCabStep");
|
||||
CString strRS232LightType = _T("LightType");
|
||||
CString strRS232RoadBoardNum = _T("RoadBoardNum");
|
||||
CString strRS232CabCompGap = _T("DigitalLuxMeterCabCompGap");
|
||||
CString strRS232CabGetSingRingInitValue = _T("DigitalLuxMeterGetSingRingInitValue");
|
||||
CString strRS232CabGetWhichRingForInitValue = _T("DigitalLuxMeterGetWhichRingForInitValue");
|
||||
ReadWriteIni wIni(strFileName);
|
||||
wIni.setSection(strKeyName);
|
||||
wIni.setBool(strRS232Enable, m_bIsEnableToGetLuxValue);
|
||||
wIni.setInt(strRS232ComNum, m_iSerialComPort);
|
||||
wIni.setInt(strRS232SleepTime, m_iSleepTime);
|
||||
wIni.setDouble(strRS232CabStep, m_dCabStep);
|
||||
wIni.setInt(strRS232RoadBoardNum, m_iRoadBoardNum);
|
||||
wIni.setInt(strRS232LightType, m_iSelectLightType);
|
||||
wIni.setInt(strRS232CabCompGap, m_iCompareGap);
|
||||
wIni.setBool(strRS232CabGetSingRingInitValue, m_bGetSingleRingInitValue);
|
||||
wIni.setInt(strRS232CabGetWhichRingForInitValue, m_iGetWhichRingForInitValue);
|
||||
//wIni.setInt(strRS232BuadRate, m_iBuadRate);
|
||||
}
|
||||
|
||||
unsigned __stdcall ReadLightData(LPVOID pThis)
|
||||
{
|
||||
CGetDigitalLuxMeterValue* _pThis = (CGetDigitalLuxMeterValue*)pThis;
|
||||
while (_serial_WatchThreadState == THREAD_STATE_RUNNING)
|
||||
{
|
||||
_pThis->OnGetRealTimeDigitalLuxMeterValueResult();
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
BOOL CGetDigitalLuxMeterValue::OnInit()
|
||||
{
|
||||
BOOL bInitState = FALSE;
|
||||
LoadConfig();
|
||||
|
||||
if (m_bIsEnableToGetLuxValue)
|
||||
{
|
||||
m_SO7_Serial.SetPort(m_iSerialComPort, m_iBuadRate);
|
||||
if (m_SO7_Serial.Open())
|
||||
{
|
||||
bInitState = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitState = FALSE;
|
||||
}
|
||||
|
||||
if (bInitState == FALSE)
|
||||
{
|
||||
CString str = (L"Serial port open failed!");
|
||||
str.AppendFormat((L"Port Number:"));
|
||||
str.AppendFormat(_T("%d "), m_iSerialComPort);
|
||||
MessageBoxEx(NULL, str, (L"Serial port"), MB_OK | MB_SYSTEMMODAL, MB_SYSTEMMODAL);
|
||||
}
|
||||
BOOL bReady = OnStartDigitalLuxMeter();
|
||||
if (bReady)
|
||||
{
|
||||
_serial_WatchThreadState = THREAD_STATE_RUNNING;
|
||||
_smc_WatchThreadHandle = CreateThread((LPSECURITY_ATTRIBUTES)NULL,
|
||||
0, (LPTHREAD_START_ROUTINE)ReadLightData,
|
||||
this, 0, NULL);
|
||||
}
|
||||
}
|
||||
return bInitState;
|
||||
}
|
||||
|
||||
BOOL CGetDigitalLuxMeterValue::OnUninit()
|
||||
{
|
||||
if (m_bIsEnableToGetLuxValue)
|
||||
{
|
||||
m_SO7_Serial.Close();
|
||||
_serial_WatchThreadState = THREAD_STATE_EXIT;
|
||||
ExitThread(0);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CGetDigitalLuxMeterValue::OnStartDigitalLuxMeter()
|
||||
{
|
||||
BOOL bState = FALSE;
|
||||
|
||||
DWORD iWriteByte = m_SO7_Serial.Send(DigitalLuxMeter_StopDatas, 9);
|
||||
INT iRetrys(0);
|
||||
Sleep(50);
|
||||
|
||||
iWriteByte = m_SO7_Serial.Send(DigitalLuxMeter_StartDatas, 9);
|
||||
iRetrys = 0;
|
||||
while (!m_SO7_Serial.m_iRecvState && iRetrys < 18 && iWriteByte == 9)
|
||||
{
|
||||
iRetrys++;
|
||||
Sleep(50);
|
||||
}
|
||||
if (m_SO7_Serial.m_iRecvState)
|
||||
{
|
||||
m_SO7_Serial.m_iRecvState = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bState = FALSE;
|
||||
MessageBox(nullptr, L"Start digital lux meter error", L"Error", MB_ICONERROR);
|
||||
}
|
||||
|
||||
iWriteByte = m_SO7_Serial.Send(DigitalLuxMeter_BeginDatas, 9);
|
||||
iRetrys = 0;
|
||||
while (!m_SO7_Serial.m_iRecvState && iRetrys < 18 && iWriteByte == 9)
|
||||
{
|
||||
iRetrys++;
|
||||
Sleep(50);
|
||||
}
|
||||
if (m_SO7_Serial.m_iRecvState)
|
||||
{
|
||||
m_SO7_Serial.m_iRecvState = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bState = FALSE;
|
||||
MessageBox(nullptr, L"Start digital lux meter error", L"Error", MB_ICONERROR);
|
||||
}
|
||||
bState = TRUE;
|
||||
return bState;
|
||||
}
|
||||
|
||||
BOOL CGetDigitalLuxMeterValue::OnStopToGetRealTimeDigitalLuxMeterValue()
|
||||
{
|
||||
BOOL bState = FALSE;
|
||||
DWORD iWriteByte = m_SO7_Serial.Send(DigitalLuxMeter_StopDatas, 9);
|
||||
INT iRetrys(0);
|
||||
while (!m_SO7_Serial.m_iRecvState && iRetrys < 18 && iWriteByte == 9)
|
||||
{
|
||||
iRetrys++;
|
||||
Sleep(50);
|
||||
}
|
||||
if (m_SO7_Serial.m_iRecvState)
|
||||
{
|
||||
m_SO7_Serial.m_iRecvState = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bState = FALSE;
|
||||
MessageBox(nullptr, L"Stop digital lux meter error", L"Error", MB_ICONERROR);
|
||||
}
|
||||
bState = TRUE;
|
||||
return bState;
|
||||
}
|
||||
|
||||
void CGetDigitalLuxMeterValue::OnGetRealTimeDigitalLuxMeterValueResult()
|
||||
{
|
||||
INT iRetrys(0);
|
||||
if (m_SO7_Serial.m_iRecvState)
|
||||
{
|
||||
if (m_SO7_Serial.m_iRecvBytes == 8)
|
||||
{
|
||||
int num3 = 0.0;
|
||||
double num4 = 0.0;
|
||||
int num5 = 0;
|
||||
int num6 = 0.0;
|
||||
num3 = m_SO7_Serial.m_RecvData[2] >> 6;
|
||||
switch (num3)
|
||||
{
|
||||
case 0:
|
||||
num4 = 1.0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
num4 = 10.0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
num4 = 100.0;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
num4 = 1000.0;
|
||||
break;
|
||||
}
|
||||
num5 = m_SO7_Serial.m_RecvData[2] & 0x3f;
|
||||
num6 = m_SO7_Serial.m_RecvData[3];
|
||||
double value1 = ((num5 * 0x100) + num6) * 0.1;
|
||||
m_dLuxVal = value1 * num4;
|
||||
m_dTempVal = (m_SO7_Serial.m_RecvData[5] * 0x100) + m_SO7_Serial.m_RecvData[6];
|
||||
if (m_SO7_Serial.m_RecvData[4] == 0)
|
||||
{
|
||||
m_dTempVal *= -0.1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dTempVal *= 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
m_SO7_Serial.m_iRecvState = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sleep(50);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
#ifndef __USB_H__
|
||||
#define __USB_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
/*
|
||||
* 'interface' is defined somewhere in the Windows header files. This macro
|
||||
* is deleted here to avoid conflicts and compile errors.
|
||||
*/
|
||||
|
||||
#ifdef interface
|
||||
#undef interface
|
||||
#endif
|
||||
|
||||
/*
|
||||
* PATH_MAX from limits.h can't be used on Windows if the dll and
|
||||
* import libraries are build/used by different compilers
|
||||
*/
|
||||
|
||||
#define LIBUSB_PATH_MAX 512
|
||||
|
||||
|
||||
/*
|
||||
* USB spec information
|
||||
*
|
||||
* This is all stuff grabbed from various USB specs and is pretty much
|
||||
* not subject to change
|
||||
*/
|
||||
|
||||
/*
|
||||
* Device and/or Interface Class codes
|
||||
*/
|
||||
#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
|
||||
#define USB_CLASS_AUDIO 1
|
||||
#define USB_CLASS_COMM 2
|
||||
#define USB_CLASS_HID 3
|
||||
#define USB_CLASS_PRINTER 7
|
||||
#define USB_CLASS_MASS_STORAGE 8
|
||||
#define USB_CLASS_HUB 9
|
||||
#define USB_CLASS_DATA 10
|
||||
#define USB_CLASS_VENDOR_SPEC 0xff
|
||||
|
||||
/*
|
||||
* Descriptor types
|
||||
*/
|
||||
#define USB_DT_DEVICE 0x01
|
||||
#define USB_DT_CONFIG 0x02
|
||||
#define USB_DT_STRING 0x03
|
||||
#define USB_DT_INTERFACE 0x04
|
||||
#define USB_DT_ENDPOINT 0x05
|
||||
|
||||
#define USB_DT_HID 0x21
|
||||
#define USB_DT_REPORT 0x22
|
||||
#define USB_DT_PHYSICAL 0x23
|
||||
#define USB_DT_HUB 0x29
|
||||
|
||||
/*
|
||||
* Descriptor sizes per descriptor type
|
||||
*/
|
||||
#define USB_DT_DEVICE_SIZE 18
|
||||
#define USB_DT_CONFIG_SIZE 9
|
||||
#define USB_DT_INTERFACE_SIZE 9
|
||||
#define USB_DT_ENDPOINT_SIZE 7
|
||||
#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
|
||||
#define USB_DT_HUB_NONVAR_SIZE 7
|
||||
|
||||
|
||||
/* ensure byte-packed structures */
|
||||
#include <pshpack1.h>
|
||||
|
||||
|
||||
/* All standard descriptors have these 2 fields in common */
|
||||
struct usb_descriptor_header
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
};
|
||||
|
||||
/* String descriptor */
|
||||
struct usb_string_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short wData[1];
|
||||
};
|
||||
|
||||
/* HID descriptor */
|
||||
struct usb_hid_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short bcdHID;
|
||||
unsigned char bCountryCode;
|
||||
unsigned char bNumDescriptors;
|
||||
};
|
||||
|
||||
/* Endpoint descriptor */
|
||||
#define USB_MAXENDPOINTS 32
|
||||
struct usb_endpoint_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bEndpointAddress;
|
||||
unsigned char bmAttributes;
|
||||
unsigned short wMaxPacketSize;
|
||||
unsigned char bInterval;
|
||||
unsigned char bRefresh;
|
||||
unsigned char bSynchAddress;
|
||||
|
||||
unsigned char *extra; /* Extra descriptors */
|
||||
int extralen;
|
||||
};
|
||||
|
||||
#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
|
||||
#define USB_ENDPOINT_DIR_MASK 0x80
|
||||
|
||||
#define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
|
||||
#define USB_ENDPOINT_TYPE_CONTROL 0
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
|
||||
#define USB_ENDPOINT_TYPE_BULK 2
|
||||
#define USB_ENDPOINT_TYPE_INTERRUPT 3
|
||||
|
||||
/* Interface descriptor */
|
||||
#define USB_MAXINTERFACES 32
|
||||
struct usb_interface_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bInterfaceNumber;
|
||||
unsigned char bAlternateSetting;
|
||||
unsigned char bNumEndpoints;
|
||||
unsigned char bInterfaceClass;
|
||||
unsigned char bInterfaceSubClass;
|
||||
unsigned char bInterfaceProtocol;
|
||||
unsigned char iInterface;
|
||||
|
||||
struct usb_endpoint_descriptor *endpoint;
|
||||
|
||||
unsigned char *extra; /* Extra descriptors */
|
||||
int extralen;
|
||||
};
|
||||
|
||||
#define USB_MAXALTSETTING 128 /* Hard limit */
|
||||
|
||||
struct usb_interface
|
||||
{
|
||||
struct usb_interface_descriptor *altsetting;
|
||||
|
||||
int num_altsetting;
|
||||
};
|
||||
|
||||
/* Configuration descriptor information.. */
|
||||
#define USB_MAXCONFIG 8
|
||||
struct usb_config_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short wTotalLength;
|
||||
unsigned char bNumInterfaces;
|
||||
unsigned char bConfigurationValue;
|
||||
unsigned char iConfiguration;
|
||||
unsigned char bmAttributes;
|
||||
unsigned char MaxPower;
|
||||
|
||||
struct usb_interface *interface;
|
||||
|
||||
unsigned char *extra; /* Extra descriptors */
|
||||
int extralen;
|
||||
};
|
||||
|
||||
/* Device descriptor */
|
||||
struct usb_device_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short bcdUSB;
|
||||
unsigned char bDeviceClass;
|
||||
unsigned char bDeviceSubClass;
|
||||
unsigned char bDeviceProtocol;
|
||||
unsigned char bMaxPacketSize0;
|
||||
unsigned short idVendor;
|
||||
unsigned short idProduct;
|
||||
unsigned short bcdDevice;
|
||||
unsigned char iManufacturer;
|
||||
unsigned char iProduct;
|
||||
unsigned char iSerialNumber;
|
||||
unsigned char bNumConfigurations;
|
||||
};
|
||||
|
||||
struct usb_ctrl_setup
|
||||
{
|
||||
unsigned char bRequestType;
|
||||
unsigned char bRequest;
|
||||
unsigned short wValue;
|
||||
unsigned short wIndex;
|
||||
unsigned short wLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* Standard requests
|
||||
*/
|
||||
#define USB_REQ_GET_STATUS 0x00
|
||||
#define USB_REQ_CLEAR_FEATURE 0x01
|
||||
/* 0x02 is reserved */
|
||||
#define USB_REQ_SET_FEATURE 0x03
|
||||
/* 0x04 is reserved */
|
||||
#define USB_REQ_SET_ADDRESS 0x05
|
||||
#define USB_REQ_GET_DESCRIPTOR 0x06
|
||||
#define USB_REQ_SET_DESCRIPTOR 0x07
|
||||
#define USB_REQ_GET_CONFIGURATION 0x08
|
||||
#define USB_REQ_SET_CONFIGURATION 0x09
|
||||
#define USB_REQ_GET_INTERFACE 0x0A
|
||||
#define USB_REQ_SET_INTERFACE 0x0B
|
||||
#define USB_REQ_SYNCH_FRAME 0x0C
|
||||
|
||||
#define USB_TYPE_STANDARD (0x00 << 5)
|
||||
#define USB_TYPE_CLASS (0x01 << 5)
|
||||
#define USB_TYPE_VENDOR (0x02 << 5)
|
||||
#define USB_TYPE_RESERVED (0x03 << 5)
|
||||
|
||||
#define USB_RECIP_DEVICE 0x00
|
||||
#define USB_RECIP_INTERFACE 0x01
|
||||
#define USB_RECIP_ENDPOINT 0x02
|
||||
#define USB_RECIP_OTHER 0x03
|
||||
|
||||
/*
|
||||
* Various libusb API related stuff
|
||||
*/
|
||||
|
||||
#define USB_ENDPOINT_IN 0x80
|
||||
#define USB_ENDPOINT_OUT 0x00
|
||||
|
||||
/* Error codes */
|
||||
#define USB_ERROR_BEGIN 500000
|
||||
|
||||
/*
|
||||
* This is supposed to look weird. This file is generated from autoconf
|
||||
* and I didn't want to make this too complicated.
|
||||
*/
|
||||
#define USB_LE16_TO_CPU(x)
|
||||
|
||||
/* Data types */
|
||||
/* struct usb_device; */
|
||||
/* struct usb_bus; */
|
||||
|
||||
struct usb_device
|
||||
{
|
||||
struct usb_device *next, *prev;
|
||||
|
||||
char filename[LIBUSB_PATH_MAX];
|
||||
|
||||
struct usb_bus *bus;
|
||||
|
||||
struct usb_device_descriptor descriptor;
|
||||
struct usb_config_descriptor *config;
|
||||
|
||||
void *dev; /* Darwin support */
|
||||
|
||||
unsigned char devnum;
|
||||
|
||||
unsigned char num_children;
|
||||
struct usb_device **children;
|
||||
};
|
||||
|
||||
struct usb_bus
|
||||
{
|
||||
struct usb_bus *next, *prev;
|
||||
|
||||
char dirname[LIBUSB_PATH_MAX];
|
||||
|
||||
struct usb_device *devices;
|
||||
unsigned long location;
|
||||
|
||||
struct usb_device *root_dev;
|
||||
};
|
||||
|
||||
/* Version information, Windows specific */
|
||||
struct usb_version
|
||||
{
|
||||
struct
|
||||
{
|
||||
int major;
|
||||
int minor;
|
||||
int micro;
|
||||
int nano;
|
||||
} dll;
|
||||
struct
|
||||
{
|
||||
int major;
|
||||
int minor;
|
||||
int micro;
|
||||
int nano;
|
||||
} driver;
|
||||
};
|
||||
|
||||
|
||||
struct usb_dev_handle;
|
||||
typedef struct usb_dev_handle usb_dev_handle;
|
||||
|
||||
/* Variables */
|
||||
#ifndef __USB_C__
|
||||
#define usb_busses usb_get_busses()
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/* usb.c */
|
||||
usb_dev_handle *usb_open(struct usb_device *dev);
|
||||
int usb_close(usb_dev_handle *dev);
|
||||
int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
|
||||
size_t buflen);
|
||||
int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
|
||||
size_t buflen);
|
||||
|
||||
/* descriptors.c */
|
||||
int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
|
||||
unsigned char type, unsigned char index,
|
||||
void *buf, int size);
|
||||
int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
|
||||
unsigned char index, void *buf, int size);
|
||||
|
||||
/* <arch>.c */
|
||||
int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
|
||||
int value, int index, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_set_configuration(usb_dev_handle *dev, int configuration);
|
||||
int usb_claim_interface(usb_dev_handle *dev, int interface);
|
||||
int usb_release_interface(usb_dev_handle *dev, int interface);
|
||||
int usb_set_altinterface(usb_dev_handle *dev, int alternate);
|
||||
int usb_resetep(usb_dev_handle *dev, unsigned int ep);
|
||||
int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
|
||||
int usb_reset(usb_dev_handle *dev);
|
||||
|
||||
char *usb_strerror(void);
|
||||
|
||||
void usb_init(void);
|
||||
void usb_set_debug(int level);
|
||||
int usb_find_busses(void);
|
||||
int usb_find_devices(void);
|
||||
struct usb_device *usb_device(usb_dev_handle *dev);
|
||||
struct usb_bus *usb_get_busses(void);
|
||||
|
||||
|
||||
/* Windows specific functions */
|
||||
|
||||
#define LIBUSB_HAS_INSTALL_SERVICE_NP 1
|
||||
int usb_install_service_np(void);
|
||||
void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
|
||||
int usb_uninstall_service_np(void);
|
||||
void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
#define LIBUSB_HAS_INSTALL_DRIVER_NP 1
|
||||
int usb_install_driver_np(const char *inf_file);
|
||||
void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
|
||||
int usb_touch_inf_file_np(const char *inf_file);
|
||||
void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
|
||||
int usb_install_needs_restart_np(void);
|
||||
|
||||
#define LIBUSB_HAS_INSTALL_NP 1
|
||||
int usb_install_npW(HWND hwnd, HINSTANCE instance, LPCWSTR cmd_line, int starg_arg);
|
||||
int usb_install_npA(HWND hwnd, HINSTANCE instance, LPCSTR cmd_line, int starg_arg);
|
||||
#define usb_install_np usb_install_npA
|
||||
void CALLBACK usb_install_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
const struct usb_version *usb_get_version(void);
|
||||
|
||||
int usb_isochronous_setup_async(usb_dev_handle *dev, void **context,
|
||||
unsigned char ep, int pktsize);
|
||||
int usb_bulk_setup_async(usb_dev_handle *dev, void **context,
|
||||
unsigned char ep);
|
||||
int usb_interrupt_setup_async(usb_dev_handle *dev, void **context,
|
||||
unsigned char ep);
|
||||
|
||||
int usb_submit_async(void *context, char *bytes, int size);
|
||||
int usb_reap_async(void *context, int timeout);
|
||||
int usb_reap_async_nocancel(void *context, int timeout);
|
||||
int usb_cancel_async(void *context);
|
||||
int usb_free_async(void **context);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_H__ */
|
||||
|
||||
@@ -0,0 +1,415 @@
|
||||
#ifndef __USB_H__
|
||||
#define __USB_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
/*
|
||||
* 'interface' is defined somewhere in the Windows header files. This macro
|
||||
* is deleted here to avoid conflicts and compile errors.
|
||||
*/
|
||||
|
||||
#ifdef interface
|
||||
#undef interface
|
||||
#endif
|
||||
|
||||
/*
|
||||
* PATH_MAX from limits.h can't be used on Windows if the dll and
|
||||
* import libraries are build/used by different compilers
|
||||
*/
|
||||
|
||||
#define LIBUSB_PATH_MAX 512
|
||||
|
||||
|
||||
/*
|
||||
* USB spec information
|
||||
*
|
||||
* This is all stuff grabbed from various USB specs and is pretty much
|
||||
* not subject to change
|
||||
*/
|
||||
|
||||
/*
|
||||
* Device and/or Interface Class codes
|
||||
*/
|
||||
#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
|
||||
#define USB_CLASS_AUDIO 1
|
||||
#define USB_CLASS_COMM 2
|
||||
#define USB_CLASS_HID 3
|
||||
#define USB_CLASS_PRINTER 7
|
||||
#define USB_CLASS_MASS_STORAGE 8
|
||||
#define USB_CLASS_HUB 9
|
||||
#define USB_CLASS_DATA 10
|
||||
#define USB_CLASS_VENDOR_SPEC 0xff
|
||||
|
||||
/*
|
||||
* Descriptor types
|
||||
*/
|
||||
#define USB_DT_DEVICE 0x01
|
||||
#define USB_DT_CONFIG 0x02
|
||||
#define USB_DT_STRING 0x03
|
||||
#define USB_DT_INTERFACE 0x04
|
||||
#define USB_DT_ENDPOINT 0x05
|
||||
|
||||
#define USB_DT_HID 0x21
|
||||
#define USB_DT_REPORT 0x22
|
||||
#define USB_DT_PHYSICAL 0x23
|
||||
#define USB_DT_HUB 0x29
|
||||
|
||||
/*
|
||||
* Descriptor sizes per descriptor type
|
||||
*/
|
||||
#define USB_DT_DEVICE_SIZE 18
|
||||
#define USB_DT_CONFIG_SIZE 9
|
||||
#define USB_DT_INTERFACE_SIZE 9
|
||||
#define USB_DT_ENDPOINT_SIZE 7
|
||||
#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
|
||||
#define USB_DT_HUB_NONVAR_SIZE 7
|
||||
|
||||
|
||||
/* ensure byte-packed structures */
|
||||
#include <pshpack1.h>
|
||||
|
||||
|
||||
/* All standard descriptors have these 2 fields in common */
|
||||
struct usb_descriptor_header
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
};
|
||||
|
||||
/* String descriptor */
|
||||
struct usb_string_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short wData[1];
|
||||
};
|
||||
|
||||
/* HID descriptor */
|
||||
struct usb_hid_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short bcdHID;
|
||||
unsigned char bCountryCode;
|
||||
unsigned char bNumDescriptors;
|
||||
};
|
||||
|
||||
/* Endpoint descriptor */
|
||||
#define USB_MAXENDPOINTS 32
|
||||
struct usb_endpoint_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bEndpointAddress;
|
||||
unsigned char bmAttributes;
|
||||
unsigned short wMaxPacketSize;
|
||||
unsigned char bInterval;
|
||||
unsigned char bRefresh;
|
||||
unsigned char bSynchAddress;
|
||||
|
||||
unsigned char *extra; /* Extra descriptors */
|
||||
int extralen;
|
||||
};
|
||||
|
||||
#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
|
||||
#define USB_ENDPOINT_DIR_MASK 0x80
|
||||
|
||||
#define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
|
||||
#define USB_ENDPOINT_TYPE_CONTROL 0
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
|
||||
#define USB_ENDPOINT_TYPE_BULK 2
|
||||
#define USB_ENDPOINT_TYPE_INTERRUPT 3
|
||||
|
||||
/* Interface descriptor */
|
||||
#define USB_MAXINTERFACES 32
|
||||
struct usb_interface_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bInterfaceNumber;
|
||||
unsigned char bAlternateSetting;
|
||||
unsigned char bNumEndpoints;
|
||||
unsigned char bInterfaceClass;
|
||||
unsigned char bInterfaceSubClass;
|
||||
unsigned char bInterfaceProtocol;
|
||||
unsigned char iInterface;
|
||||
|
||||
struct usb_endpoint_descriptor *endpoint;
|
||||
|
||||
unsigned char *extra; /* Extra descriptors */
|
||||
int extralen;
|
||||
};
|
||||
|
||||
#define USB_MAXALTSETTING 128 /* Hard limit */
|
||||
|
||||
struct usb_interface
|
||||
{
|
||||
struct usb_interface_descriptor *altsetting;
|
||||
|
||||
int num_altsetting;
|
||||
};
|
||||
|
||||
/* Configuration descriptor information.. */
|
||||
#define USB_MAXCONFIG 8
|
||||
struct usb_config_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short wTotalLength;
|
||||
unsigned char bNumInterfaces;
|
||||
unsigned char bConfigurationValue;
|
||||
unsigned char iConfiguration;
|
||||
unsigned char bmAttributes;
|
||||
unsigned char MaxPower;
|
||||
|
||||
struct usb_interface *interface;
|
||||
|
||||
unsigned char *extra; /* Extra descriptors */
|
||||
int extralen;
|
||||
};
|
||||
|
||||
/* Device descriptor */
|
||||
struct usb_device_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short bcdUSB;
|
||||
unsigned char bDeviceClass;
|
||||
unsigned char bDeviceSubClass;
|
||||
unsigned char bDeviceProtocol;
|
||||
unsigned char bMaxPacketSize0;
|
||||
unsigned short idVendor;
|
||||
unsigned short idProduct;
|
||||
unsigned short bcdDevice;
|
||||
unsigned char iManufacturer;
|
||||
unsigned char iProduct;
|
||||
unsigned char iSerialNumber;
|
||||
unsigned char bNumConfigurations;
|
||||
};
|
||||
|
||||
struct usb_ctrl_setup
|
||||
{
|
||||
unsigned char bRequestType;
|
||||
unsigned char bRequest;
|
||||
unsigned short wValue;
|
||||
unsigned short wIndex;
|
||||
unsigned short wLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* Standard requests
|
||||
*/
|
||||
#define USB_REQ_GET_STATUS 0x00
|
||||
#define USB_REQ_CLEAR_FEATURE 0x01
|
||||
/* 0x02 is reserved */
|
||||
#define USB_REQ_SET_FEATURE 0x03
|
||||
/* 0x04 is reserved */
|
||||
#define USB_REQ_SET_ADDRESS 0x05
|
||||
#define USB_REQ_GET_DESCRIPTOR 0x06
|
||||
#define USB_REQ_SET_DESCRIPTOR 0x07
|
||||
#define USB_REQ_GET_CONFIGURATION 0x08
|
||||
#define USB_REQ_SET_CONFIGURATION 0x09
|
||||
#define USB_REQ_GET_INTERFACE 0x0A
|
||||
#define USB_REQ_SET_INTERFACE 0x0B
|
||||
#define USB_REQ_SYNCH_FRAME 0x0C
|
||||
|
||||
#define USB_TYPE_STANDARD (0x00 << 5)
|
||||
#define USB_TYPE_CLASS (0x01 << 5)
|
||||
#define USB_TYPE_VENDOR (0x02 << 5)
|
||||
#define USB_TYPE_RESERVED (0x03 << 5)
|
||||
|
||||
#define USB_RECIP_DEVICE 0x00
|
||||
#define USB_RECIP_INTERFACE 0x01
|
||||
#define USB_RECIP_ENDPOINT 0x02
|
||||
#define USB_RECIP_OTHER 0x03
|
||||
|
||||
/*
|
||||
* Various libusb API related stuff
|
||||
*/
|
||||
|
||||
#define USB_ENDPOINT_IN 0x80
|
||||
#define USB_ENDPOINT_OUT 0x00
|
||||
|
||||
/* Error codes */
|
||||
#define USB_ERROR_BEGIN 500000
|
||||
|
||||
/*
|
||||
* This is supposed to look weird. This file is generated from autoconf
|
||||
* and I didn't want to make this too complicated.
|
||||
*/
|
||||
#define USB_LE16_TO_CPU(x)
|
||||
|
||||
/* Data types */
|
||||
/* struct usb_device; */
|
||||
/* struct usb_bus; */
|
||||
|
||||
struct usb_device
|
||||
{
|
||||
struct usb_device *next, *prev;
|
||||
|
||||
char filename[LIBUSB_PATH_MAX];
|
||||
|
||||
struct usb_bus *bus;
|
||||
|
||||
struct usb_device_descriptor descriptor;
|
||||
struct usb_config_descriptor *config;
|
||||
|
||||
void *dev; /* Darwin support */
|
||||
|
||||
unsigned char devnum;
|
||||
|
||||
unsigned char num_children;
|
||||
struct usb_device **children;
|
||||
};
|
||||
|
||||
struct usb_bus
|
||||
{
|
||||
struct usb_bus *next, *prev;
|
||||
|
||||
char dirname[LIBUSB_PATH_MAX];
|
||||
|
||||
struct usb_device *devices;
|
||||
unsigned long location;
|
||||
|
||||
struct usb_device *root_dev;
|
||||
};
|
||||
|
||||
/* Version information, Windows specific */
|
||||
struct usb_version
|
||||
{
|
||||
struct
|
||||
{
|
||||
int major;
|
||||
int minor;
|
||||
int micro;
|
||||
int nano;
|
||||
} dll;
|
||||
struct
|
||||
{
|
||||
int major;
|
||||
int minor;
|
||||
int micro;
|
||||
int nano;
|
||||
} driver;
|
||||
};
|
||||
|
||||
|
||||
struct usb_dev_handle;
|
||||
typedef struct usb_dev_handle usb_dev_handle;
|
||||
|
||||
/* Variables */
|
||||
#ifndef __USB_C__
|
||||
#define usb_busses usb_get_busses()
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/* usb.c */
|
||||
usb_dev_handle *usb_open(struct usb_device *dev);
|
||||
int usb_close(usb_dev_handle *dev);
|
||||
int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
|
||||
size_t buflen);
|
||||
int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
|
||||
size_t buflen);
|
||||
|
||||
/* descriptors.c */
|
||||
int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
|
||||
unsigned char type, unsigned char index,
|
||||
void *buf, int size);
|
||||
int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
|
||||
unsigned char index, void *buf, int size);
|
||||
|
||||
/* <arch>.c */
|
||||
int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
|
||||
int value, int index, char *bytes, int size,
|
||||
int timeout);
|
||||
int usb_set_configuration(usb_dev_handle *dev, int configuration);
|
||||
int usb_claim_interface(usb_dev_handle *dev, int interface);
|
||||
int usb_release_interface(usb_dev_handle *dev, int interface);
|
||||
int usb_set_altinterface(usb_dev_handle *dev, int alternate);
|
||||
int usb_resetep(usb_dev_handle *dev, unsigned int ep);
|
||||
int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
|
||||
int usb_reset(usb_dev_handle *dev);
|
||||
|
||||
char *usb_strerror(void);
|
||||
|
||||
void usb_init(void);
|
||||
void usb_set_debug(int level);
|
||||
int usb_find_busses(void);
|
||||
int usb_find_devices(void);
|
||||
struct usb_device *usb_device(usb_dev_handle *dev);
|
||||
struct usb_bus *usb_get_busses(void);
|
||||
|
||||
|
||||
/* Windows specific functions */
|
||||
|
||||
#define LIBUSB_HAS_INSTALL_SERVICE_NP 1
|
||||
int usb_install_service_np(void);
|
||||
void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
|
||||
int usb_uninstall_service_np(void);
|
||||
void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
#define LIBUSB_HAS_INSTALL_DRIVER_NP 1
|
||||
int usb_install_driver_np(const char *inf_file);
|
||||
void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
|
||||
int usb_touch_inf_file_np(const char *inf_file);
|
||||
void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
|
||||
int usb_install_needs_restart_np(void);
|
||||
|
||||
#define LIBUSB_HAS_INSTALL_NP 1
|
||||
int usb_install_npW(HWND hwnd, HINSTANCE instance, LPCWSTR cmd_line, int starg_arg);
|
||||
int usb_install_npA(HWND hwnd, HINSTANCE instance, LPCSTR cmd_line, int starg_arg);
|
||||
#define usb_install_np usb_install_npA
|
||||
void CALLBACK usb_install_np_rundll(HWND wnd, HINSTANCE instance,
|
||||
LPSTR cmd_line, int cmd_show);
|
||||
|
||||
const struct usb_version *usb_get_version(void);
|
||||
|
||||
int usb_isochronous_setup_async(usb_dev_handle *dev, void **context,
|
||||
unsigned char ep, int pktsize);
|
||||
int usb_bulk_setup_async(usb_dev_handle *dev, void **context,
|
||||
unsigned char ep);
|
||||
int usb_interrupt_setup_async(usb_dev_handle *dev, void **context,
|
||||
unsigned char ep);
|
||||
int usb_submit_async(void *context, char *bytes, int size);
|
||||
int usb_reap_async(void *context, int timeout);
|
||||
int usb_reap_async_nocancel(void *context, int timeout);
|
||||
int usb_cancel_async(void *context);
|
||||
int usb_free_async(void **context);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_H__ */
|
||||
|
||||
Reference in New Issue
Block a user