基于接收工程的一些编译和阅读
This commit is contained in:
+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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user