Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
I'm receiving data from COM1 port char by char and i would like to capture this data from other port(COM3).
C++
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
Updated 6-Feb-13 19:16pm
v16
Comments
Mohibur Rashid 7-Feb-13 2:00am    
what is the length of your chunk? 1?
Mr Sam 7-Feb-13 2:12am    
1KB
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

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900