Re: serial port Writefile: sometimes 998 ERROR_NOACCESS
On 23 Dez., 17:19, Joseph M. Newcomer <newco...@flounder.com> wrote:
See below...
On Thu, 23 Dec 2010 05:26:27 -0800 (PST), mfc <mfcp...@googlemail.com> wr=
ote:
Hi,
I`ve noticed an 998 ERROR_NOACCESS error during a WriteFile method.
This error occurs only sometimes - e.g. after 15min where the prog is
running without problems...
I`m not sure, because the explanation of this error is pretty small,
to which memory I didn`t have an access (to the memory with the data
writing to the serial port | or to the serial-port handle)?
If installed two threads, one who is responsible for collecting the
data to tx by the com port and another thread which will transmit
these data. As data I`m using a huge CByteArray located at the heap.
//Data to tx by usb
void CASoc::RxData(ADATA *ptr)
{
CByteArray *pData = new CByteArray;
pData->SetSize(SIZE_OF_ARRAY);
memcpy(pData->GetData(), &ptr->Data[0], SIZE_OF_ARRAY);
*****
What is SIZE_OF_ARRAY? And why is it not computed dynamically based on=
the *actual*
amount of data read? And why are you writing'
&ptr->Data[0]
when it should be sufficient to write
ptr->Data
?
****
::PostThreadMessage(m_ThreadIDs[0], UWM_GET_NEW_DATA,(WPARAM)pData,
SIZE_OF_ARRAY);
}
****
Is there an array of threads handling this? Why do you have an array o=
f thread IDs? What
good does this do? And are they valid if the thread terminates? Man=
y problems here.
****
Yes in the final version, there are 12 thread-ids (m_ThreadIDs[0]) -
for 12 serial port writer threads. At the moment I`m using only one
thread (therefore the fix number m_ThreadIDs[0]).
The thread (its not the mainthread) which calls this method
(CASoc::RxData(ADATA *ptr)) will be generated normally.
Bool CASocThread::InitInstance()
{
//do all required things
//send msg to mainthread that this thread is running
target->PostMessage(UWM_ASOCTH_RUNNING, (WPARAM)m_nThreadID, 0);
return TRUE;
}
After receiving this PostMessage in the mainframe I will start all
serial port writer threads. Is there a better solution to acchieve
that the CASocThread is definitely running and after that all serial
port writer threads are installed? OR is it better to install a class
generating all these serial port threads which is derrived from CWnd
so that this class will be able to receive PostMessages()? So that I
didn`t need to write some messages to the mainframe???
In the InitInstance of the serial port writer threads I will post a
thread message to the CASocThread with the threadID of this serial
port thread ID which will be located in the m_ThreadIDs[] array. IF
one of these serial port threads will be terminated during the
programm is it ok to post another threadmessage to the CASocThread to
tell this thread I`m shutting down (in the ExistInstance method?).
Because if the whole programm will be closed this message will be
unsuccessfull, because the CAsocThread will be closed earliere than
all these serial port threads....(which depends on the order in the
thread-array (in the mainframe).
best regards
Hans