Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C
Hi!
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 Sam700
Edited 6-Feb-13 20:16pm
SoMad134.2K
v16
Comments
Mohibur Rashid at 7-Feb-13 2:00am
   
what is the length of your chunk? 1?
Mr Sam at 7-Feb-13 2:12am
   
1KB
POP_POP_R3T at 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 at 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 at 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
good
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.
  Permalink  

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2014
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