Exemple #1
5
//************************************
// Method:    ApplyProcessor
// FullName:  CPHEEqualizer::ApplyProcessor
// Access:    public 
// Returns:   procStatus
// Qualifier:
// Parameter: CImgSource * in_pImgSrc
// Parameter: CImgSource * out_ImgResult
//************************************
procStatus CPHEEqualizer::ApplyProcessor(CImgSource *in_pImgSrc, CImgSource *out_ImgResult)
{
	ASSERT(in_pImgSrc);
	ASSERT(in_pImgSrc->GetSourceRef());
	ASSERT(out_ImgResult);

	procStatus eRetCode = eNormal;
	//CDWordArray arrProbalility;
	CByteArray arrNewTable;

	CHistogram oSrcHis;
	eRetCode = in_pImgSrc->GetHistoram(oSrcHis);

#ifdef _DEBUG
// 	for (INT i=0; i<IMP_GRAY_LEVELS; i++)
// 	{
// 		TRACE("\nPos:%d \tVal:%d", i, oSrcHis.GetAt(i));
// 	}
// 	TRACE("\nTOTAL:%d", oSrcHis.Accumulate(IMP_GRAY_LEVELS-1));
#endif

	INT nHisSize = oSrcHis.GetSize();
	//arrProbalility.SetSize(nHisSize);
	arrNewTable.SetSize(nHisSize);

	DOUBLE nTotal = oSrcHis.Accumulate(nHisSize-1);
	
	if(eRetCode == eNormal)
	{
		for(INT k=0; k<nHisSize; k++)
		{
			DOUBLE ta = oSrcHis.Accumulate(k);
			DOUBLE dTemp = ((DOUBLE)oSrcHis.Accumulate(k)/nTotal) * (IMP_GRAY_LEVELS -1);
			arrNewTable.SetAt(k, (BYTE) dTemp);
		}
		
		CProcGrayTransformer oTransformer;
		oTransformer.m_eType = eCustomTrans;
		oTransformer.InitCustomTransform(&arrNewTable);
		
		eRetCode = oTransformer.ApplyProcessor(in_pImgSrc, out_ImgResult);
	}
	
	return eRetCode;
}
// 从串口发送数据
//************************************
// Method:    OnSendFromSerialPort
// FullName:  CUartToUdpSocket::OnSendFromSerialPort
// Access:    private 
// Returns:   void
// Qualifier:
// Parameter: unsigned char * TXDATA
// Parameter: unsigned int uiCount
//************************************
void CUartToUdpSocket::OnSendFromSerialPort(unsigned char* TXDATA, unsigned int uiCount)
{
	// 如果端口未打开则不发送数据
// 	if(NULL == hCom)
// 	{
// 		return;
// 	}
// 
// 	OVERLAPPED wol;
// 	wol.Internal=0;
// 	wol.InternalHigh=0;
// 	wol.Offset=0;
// 	wol.OffsetHigh=0;
// 	wol.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
// 	
// 	WriteFile(hCom,TXDATA,uiCount,NULL,&wol);
	if (m_pctrlMSComm1 == NULL)
	{
		AfxMessageBox(_T("串口MSCOMM控件指针为空!"));
		return;
	}
	if(m_pctrlMSComm1->get_PortOpen() == FALSE)
	{
		return;
	}
	CByteArray array;
	array.RemoveAll();
	array.SetSize(uiCount);
	for(unsigned int i=0; i<uiCount; i++)
	{
		array.SetAt(i, TXDATA[i]);
	}
	m_pctrlMSComm1->put_Output(COleVariant(array)); // 发送数据
}
Exemple #3
0
// Read Operation
int CFanmotorDlg::rreg(int reg_addr)
{
success=1;

	CString s;
	int dat=0;
	long r;
	int timeout_counter=0;
	CByteArray baAddr;
	baAddr.SetSize (1);   
	baAddr.SetAt(0,reg_addr); 
	COleVariant ReadAddress(baAddr); // Create ReadAddress argument
	VARIANT dataIn;
	VariantInit(&dataIn);
	int datalen=2;//in bytes

	if(this->virtual_board)
	{
		dat = ReadVirtualBoardReg(reg_addr, fOTP);
	}

	else
	{
		r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn); 
		//r = Bridge->ReadIICdataReg(L"0000011", reg_addr, ReadAddress,datalen, &dataIn); 
		//Sleep(500);
		//r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn);//no data received.????
		//do{
		//	timeout_counter++;
		//	if (timeout_counter == TIMEOUT){
		//		DisplayInforMessageBox((LPCWSTR)L"Error", (LPCWSTR)L"Device is not available.\nPlease check your hardware connection and power supply!");
		//		success = 0;
		//	}
		//	r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn); 
		//}while ((r !=34) && (timeout_counter != TIMEOUT));

			CString strByte;
			for (long i = 0; i < datalen; i++) {
				BYTE ReadByte;
				SafeArrayGetElement(dataIn.parray, &i, &ReadByte);
				strByte.Format(L"%02x",ReadByte);
				s += strByte;
			}
			dat=use_debugdlg_main.string2int(s,2*datalen);
		//	success=1;
		//}
		//else {ErrorMsg(r);};
		VariantClear(&dataIn);
	}
	return dat;
	Sleep(20);
}
Exemple #4
0
//从串口发送数据
void SerialComm::SendComm(BYTE* sendData, int sendLength)
{
	CByteArray send;
	send.RemoveAll();
	send.SetSize(sendLength);
	for (size_t i = 0; i<sendLength; i++)
	{
		send.SetAt(i, sendData[i]);
	}	
	myComm.put_Output(COleVariant(send));

	for (size_t i = 0; i < 105; i++)
	{
		myReceiveDate[i] = 0;
	}
}
Exemple #5
0
void COscillDlg::OnbtnMSCommSend() 
{
	// TODO: Add your control notification handler code here

	UpdateData( true );
	
	CByteArray sendArr; 
	WORD wLength;

	wLength = m_szMSCommSend.GetLength();
	sendArr.SetSize( wLength );
	for( int i =0; i<wLength; i++ )
	{
		sendArr.SetAt( i, m_szMSCommSend.GetAt( i ) );
	}
//	m_mscom.SetOutput( COleVariant(sendArr) );
}
Exemple #6
0
BOOL COneCommand::GetReceivedBuffer(CByteArray &buffer) {
	BOOL ret;int i,size;BYTE src,dst;
	if((size=m_ReceiveBuffer.GetSize())!=buffer.GetSize()) {
		buffer.RemoveAll();
		buffer.Append(m_ReceiveBuffer);
		return TRUE;
		}
	else {
		ret=FALSE;
		for(i=0;i<size;i++) {
			src=m_ReceiveBuffer.GetAt(i);
			dst=buffer.GetAt(i);
			if(src!=dst) {
				buffer.SetAt(i,src);				
				ret=TRUE;
				}
			}
		return ret;
		}
	}
Exemple #7
0
int CFanmotorDlg::rFWData(int fType, int nByte)
{
	success=1;
	CString s;
	int dat=0;
	int timeout_counter=0;
	long r;
	CByteArray baAddr;
	baAddr.SetSize (1);   
	baAddr.SetAt(0,fType); 
	COleVariant ReadAddress(baAddr); // Create ReadAddress argument
	VARIANT dataIn;
	VariantInit(&dataIn);

	///*Sleep(50);*/
	//long r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress, 
 //                                  1, &dataIn);  
	do{
		timeout_counter++;
		if (timeout_counter == TIMEOUT){
			DisplayInforMessageBox((LPCWSTR)L"Error", (LPCWSTR)L"Device is not available.\nPlease check your hardware connection and power supply!");
			success = 0;
		}
		r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,nByte, &dataIn); 
	}while ((r !=34) && (timeout_counter != TIMEOUT));
	//{
		CString strByte;
		for (long i = 0; i < nByte; i++) {
			BYTE ReadByte;
			SafeArrayGetElement(dataIn.parray, &i, &ReadByte);
			strByte.Format(L"%02x",ReadByte);
			s += strByte;
		}
		dat=use_debugdlg_main.string2int(s,2*nByte);
		success=1;
	//}
	//else {ErrorMsg(r);};
	VariantClear(&dataIn);
	return dat;	
}
/**
 * Modifies a user param byte array with the ExtParam data passed with
 * argument pParam. ExtParam data objects will be build from 
 * Ext_User_Prm_Data_Const/Ref fields within the GSD. Extparam data 
 * describes the datatype of the Ext_User_Prm_Data, the offset within
 * the user param byte array and the value. The passed user param byte
 * array (see argument UserParam) grows as necessary.
 * Existing user param bytes within the array will be or-ed with the
 * new byte value.
 *
 * @param			CByteArray & UserParam - user param byte array to
 *                  modify. The byte array will grow as necessary.
 * @param			ExtParam *pParam - Reference to ExtParam data 
 *                  object describing the Ext_User_Prm_Data. Shall not
 *                  be NULL.
 * @exception		CMemoryException
 * @see			    GSD: Ext_User_Prm_Data_Const/Ref
*/
void ModifyParamArray(CByteArray & UserParam, ExtParam *pParam)
{
	int offset = 0;
    int sizeArray = 0;
    int sizeBytes = 0;


    ASSERT(pParam);

    switch(pParam->GetParamType()) {
    case Array:
        {
		    CByteArray* pBytes = pParam->GetByteArray();

		    sizeBytes = pBytes->GetSize();
            sizeArray = UserParam.GetSize();
		    offset = pParam->GetByteOffset();

            if(offset + sizeBytes > sizeArray) {
                //grow the array
                UserParam.SetSize(offset + sizeBytes);
                BYTE *pb = UserParam.GetData();
                //preset array
                size_t sizeSet = offset + sizeBytes - sizeArray;
                memset(&pb[sizeArray],0,sizeSet);
            }

		    for (int x = 0; x < sizeBytes; x++) {
			    BYTE userbyte = UserParam.GetAt(offset);
			    BYTE setbyte  = pBytes->GetAt(x);
			    userbyte |= setbyte;
			    UserParam.SetAt(offset++, userbyte);
		    }// next x
	    }
        break;
    case Byte:
	    {
		    offset = pParam->GetByteOffset();
            sizeArray = UserParam.GetSize();
            sizeBytes = sizeof(BYTE);

            if(offset + sizeBytes > sizeArray) {
                //grow the array
                UserParam.SetSize(offset + sizeBytes);
                BYTE *pb = UserParam.GetData();
                //preset array
                size_t sizeSet = offset + sizeBytes - sizeArray;
                memset(&pb[sizeArray],0,sizeSet);
            }

			BYTE userbyte = UserParam.GetAt(offset);	// Get current value in Bytearray
			if (pParam->IsBitArea())	{
				userbyte &= ~MakeBitFieldInByte(pParam->GetBitAreaStart(),
											   pParam->GetBitAreaLength());
				userbyte |= (BYTE)(pParam->GetUsedValue() << pParam->GetBitAreaStart());
			}
			else	{
				userbyte = (BYTE)pParam->GetUsedValue();
			}
			UserParam.SetAt(offset, userbyte);		// Set new value in ByteArray

	    }
        break;
    case Word:
	    {
            BYTE setbyte = 0;
		    WORD data = (WORD)pParam->GetUsedValue();

		    offset = pParam->GetByteOffset();
            sizeArray = UserParam.GetSize();
            sizeBytes = sizeof(data);
            
            if(offset + sizeBytes > sizeArray) {
                //grow the array
                UserParam.SetSize(offset + sizeBytes);
                BYTE *pb = UserParam.GetData();
                //preset array
                size_t sizeSet = offset + sizeBytes - sizeArray;
                memset(&pb[sizeArray],0,sizeSet);
            }
            
            for (int i = sizeBytes - 1; i >= 0 ; i--)	{
			    BYTE userbyte = UserParam.GetAt(offset);
			    setbyte = (BYTE)((data  >> (i*8)) & 0x000000FF);
			    userbyte = setbyte;
			    UserParam.SetAt(offset++, userbyte);
		    }
	    }
        break;
    case DWord:
	    {
		    BYTE setbyte = 0;
		    DWORD data = (DWORD)pParam->GetUsedValue();

		    offset = pParam->GetByteOffset();
            sizeArray = UserParam.GetSize();
            sizeBytes = sizeof(data);
            
            if(offset + sizeBytes > sizeArray) {
                //grow the array
                UserParam.SetSize(offset + sizeBytes);
                BYTE *pb = UserParam.GetData();
                //preset array
                size_t sizeSet = offset + sizeBytes - sizeArray;
                memset(&pb[sizeArray],0,sizeSet);
            }

		    for (int i = sizeBytes - 1; i >= 0 ; i--)	{
			    BYTE userbyte = UserParam.GetAt(offset);
			    setbyte = (BYTE)((data  >> (i*8)) & 0x000000FF);
			    userbyte = setbyte;
			    UserParam.SetAt(offset++, userbyte);
		    }
	    }
        break;
    default:
        break;
    }
}