Click here to Skip to main content
15,889,403 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Help with threads Pin
David Crow5-Sep-12 3:46
David Crow5-Sep-12 3:46 
GeneralRe: Help with threads Pin
pasztorpisti5-Sep-12 3:55
pasztorpisti5-Sep-12 3:55 
GeneralRe: Help with threads Pin
Albert Holguin5-Sep-12 12:26
professionalAlbert Holguin5-Sep-12 12:26 
AnswerRe: Help with threads Pin
Chuck O'Toole5-Sep-12 3:57
Chuck O'Toole5-Sep-12 3:57 
GeneralRe: Help with threads Pin
Albert Holguin5-Sep-12 12:25
professionalAlbert Holguin5-Sep-12 12:25 
AnswerRe: Help with threads Pin
Chuck O'Toole6-Sep-12 15:46
Chuck O'Toole6-Sep-12 15:46 
GeneralRe: Help with threads Pin
Albert Holguin7-Sep-12 3:54
professionalAlbert Holguin7-Sep-12 3:54 
QuestionRe: Help with threads Pin
AndrewG12315-Sep-12 9:55
AndrewG12315-Sep-12 9:55 
Ok, instead of modifying my original question I will continue the thread since it has been really helpful. So, my program uses the following code to create a new thread.
m_Thread = AfxBeginThread(Acq_Data,this,THREAD_PRIORITY_HIGHEST);

This thread is told to look at the current class and the controlling function is Acq_Data. In Acq_Data there is the following code.
while(dlg->m_Continue && ! dlg->m_inst->m_Flags.Halt)
	{
		dlg->m_inst->ADCdbInquire(dlg->m_halfdata,hdlg,MSG_DRAW_SPECTRUM);
	}
The ADCdbInquire()function contains a call to PostMessage()
C#
bool CPXI::ADCdbInquire(short *halfbuffer, HWND hwnd ,int Message)
{
    short iStatus, iHalfReady, iDAQstopped = 0;
    unsigned long ulPtsTfr=1500; // number of points transferred

    // Are you ready?
    iStatus = DAQ_DB_HalfReady(m_6052_Device, &iHalfReady,
         &iDAQstopped);

    if ((iHalfReady == 1) && (iDAQstopped == 0))
    {
        iStatus = DAQ_DB_Transfer(m_6052_Device, halfbuffer,
        &ulPtsTfr, &iDAQstopped);

        NIDAQErrorHandler(iStatus, "DAQ_DB_Transfer",m_SuppressErrors);

        if(Message != -1)
            PostMessage(hwnd,WM_COMMAND,Message,NULL);

        return true;
    }
    return false;

}

and is sending a custom message defined in the header file.
#define MSG_DRAW_SPECTRUM			(WM_APP + 5)
This custom messages refers to member function OnDrawSpectrum() where the following code exists to update the window.
C#
void CDlg_SpectrumAnalyzer::OnDrawSpectrum()
{

    int starti,finishi;
    starti = m_datacount * m_BuffSize / 2;
    finishi = (m_datacount + 1)* m_BuffSize / 2;

    if(finishi > m_AcqNPts)
        finishi = m_AcqNPts;

    int j = 0;
    for(int i = starti; i < finishi; i++)
    {
        m_fftdata[i].re = m_halfdata[j++];
        m_fftdata[i].im = 0.;
    }



    m_datacount++;

    // if we are done collecting draw the graph
    if((m_datacount == m_NBuffs))
    {

        OnSpectrumStart();
        float freq = 0;
        float stepsize = ((float)(m_MaxFreq)) / ((float)(m_AcqNPts-1)/2.0);
        m_datacount = 0;

        m_Graph->ClearGraph(m_graphNum,false);

        // do fft
        fftw_one(m_the_plan, m_fftdata, NULL);

        //m_AcqNPts should be 2^n therefore /2 should be integer
        for(int i = m_AcqNPts-1; i >= m_AcqNPts/2; i-= 1)
        {
            // calculate power spectrum
            m_fftdata[i].re = sqrt(m_fftdata[i].re * m_fftdata[i].re +
                                   m_fftdata[i].im * m_fftdata[i].im);
            if(m_LogY)
                m_fftdata[i].re = log(m_fftdata[i].re);

            if(m_RtHz)
                m_Graph->AddPoint(m_graphNum,sqrt(freq),m_fftdata[i].re,false);
            else
                m_Graph->AddPoint(m_graphNum,freq,m_fftdata[i].re,false);

            freq += stepsize;
        }


        if(!m_LogY)
            m_Graph->SetAxisProps(_T("Intensity"), _T("I"), 2, GRAPH_Y_AXIS,false);
        else
            m_Graph->SetAxisProps(_T("log Intensity"), _T("log(I)"), 2, GRAPH_Y_AXIS,false);


        if(m_RtHz)
            m_Graph->SetAxisProps(_T("Rt Frequency"), _T("Rt Hz"), 2, GRAPH_X_AXIS, false);
        else
            m_Graph->SetAxisProps(_T("Frequency"), _T("Hz"), 2, GRAPH_X_AXIS, false);

        EnableItems(true);
        m_Graph->UpdateWindows(GRAPH_WUV_ALL);

    }


}


So, my question...in order to get this sequence to run several times, say 5 times, and update the window how would I use PostMessage()? Or if I have misunderstood something please let me know.

Thanks again for all the help.
AnswerRe: Help with threads Pin
David Crow6-Sep-12 5:41
David Crow6-Sep-12 5:41 
QuestionRe: Help with threads Pin
AndrewG123111-Sep-12 11:33
AndrewG123111-Sep-12 11:33 
QuestionRe: Help with threads Pin
David Crow12-Sep-12 2:45
David Crow12-Sep-12 2:45 
GeneralRe: Help with threads Pin
AndrewG123112-Sep-12 6:21
AndrewG123112-Sep-12 6:21 
SuggestionRe: Help with threads Pin
David Crow12-Sep-12 8:17
David Crow12-Sep-12 8:17 
QuestionRe: Help with threads Pin
AndrewG123112-Sep-12 14:21
AndrewG123112-Sep-12 14:21 
AnswerRe: Help with threads Pin
David Crow13-Sep-12 3:47
David Crow13-Sep-12 3:47 
GeneralRe: Help with threads Pin
AndrewG123113-Sep-12 7:46
AndrewG123113-Sep-12 7:46 
GeneralRe: Help with threads Pin
David Crow13-Sep-12 7:55
David Crow13-Sep-12 7:55 
GeneralRe: Help with threads Pin
AndrewG123113-Sep-12 8:54
AndrewG123113-Sep-12 8:54 
QuestionRe: Help with threads Pin
David Crow13-Sep-12 9:32
David Crow13-Sep-12 9:32 
AnswerRe: Help with threads Pin
AndrewG123127-Sep-12 12:02
AndrewG123127-Sep-12 12:02 
GeneralRe: Help with threads Pin
David Crow28-Sep-12 2:13
David Crow28-Sep-12 2:13 
GeneralRe: Help with threads Pin
Albert Holguin5-Sep-12 12:22
professionalAlbert Holguin5-Sep-12 12:22 
QuestionStructure containing byte[1] as member variable Pin
Rahul from Poona4-Sep-12 8:45
Rahul from Poona4-Sep-12 8:45 
AnswerRe: Structure containing byte[1] as member variable Pin
Chris Losinger4-Sep-12 8:59
professionalChris Losinger4-Sep-12 8:59 
GeneralRe: Structure containing byte[1] as member variable Pin
jschell4-Sep-12 11:32
jschell4-Sep-12 11:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.