Click here to Skip to main content
11,933,621 members (53,862 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ C
I'm receiving data from COM1 port char by char and i would like to capture this data from other port(COM3).
LONG  CMainFrame::OnCommunication(WPARAM ch, LPARAM port)
    //getting data in ch. need write down in file chunk by chunk.
    WriteDataEx(m_strCapturePath,l_file, (char*)l_com_buffer,1024, FALSE);
WriteDataEx(const CString& f_strFilepath, CFile& f_file, char* cInput, const int f_size, BOOL bConfig)
    f_file.Write(cInput, f_size);
So how to form each chars as chunk and send to writedataex function ?
Posted 6-Feb-13 20:02pm
Mr Sam725
Edited 6-Feb-13 20:16pm
Mohibur Rashid 7-Feb-13 2:00am
what is the length of your chunk? 1?
Mr Sam 7-Feb-13 2:12am
POP_POP_R3T 7-Feb-13 2:16am
Maybe I'm understanding the question wrong. Are you looking to pool your input into a larger buffer so that you can call WriteDataEx less frequently?
Mr Sam 7-Feb-13 3:29am
yes, instead of writing char by char into file. Writing chunk by chunk, so that it will get finish very fastly.
POP_POP_R3T 7-Feb-13 11:39am
I would create a static buffer/pointer and also a static index variable. Everytime a char comes in from the port, write it to *(buffer + index++). once index == the max size of your buffer then call WriteDataEx.

Depending on timing sensitivities, I might also seperate the file write into its own seperate thread. and every time the buffer gets full you can push the pointer to a queue, alloc a new buffer, and set an event. Then have the writing thread digest the queue entries

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Logically what you wish to do is to create a static buffer which can hold up to 1KB of data.

Each character is first added to the buffer.

If the current size of the buffer is less than the chunk size, add it to the chunk.
If the size of the buffer reaches the chunk size, write the chunk data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100