f



RE: Reading Serial Port in Thread locks up program?

It looks like m_serial_port is sharing info with main app thread?

You may need to synchonise access to this buffer using a
wxCriticalSection=20

If your data read is eradic, I found you can add pending event after
your data read to notify gui that it has received data.

The event is raised in the main thread which can read the data - maybe
display it or whatever.

Ray


-----Original Message-----
From: Bob [mailto:wxwidgets@gmail.com]=20
Sent: Friday, 24 June 2005 06:09
To: wx-users@lists.wxwidgets.org
Subject: Reading Serial Port in Thread locks up program?

I am trying to use MarshallSoft Computing Windows Serial Communication
Component Library (WSC) in a wxThread.  It is claimed that WSC is thread
safe.

http://www.marshallsoft.com/

I have used the WorkerThread example from the wxThread sample to base my
code on.

My code runs for a few seconds ( random amount of time ) correctly, then
my wxWidgets application locks up, and I have to then kill it with the
task manager.  This is on Windows XP.  I have tried both
wx2.5.3 and wx2.6.1, using the Borland Command Line Compiler.

What am I doing wrong here that would make the program run for a few
seconds then lock up? There is only a few characters coming in as I type
them in a terminal program:

void *SerialRxThread::Entry()
{
 uint8_t rx_byte_u8;

 int ReceivedCount;
 int Code;

 while( !TestDestroy() )
 {
  while( (ReceivedCount =3D SioRxQue(COM_Port)) > 0 )
   {// If any characters in the Sio driver  que move them to our own
que:
    for( uint16_t loop_u16 =3D 0; loop_u16 < (uint16_t) ReceivedCount;
++loop_u16 )
     {
      Code =3D SioGetc( COM_Port );
      if( Code >=3D 0 )
       {
	 rx_byte_u8 =3D (uint8_t) Code;
	 m_serial_port->m_RxQueHead_u16 =3D (
m_serial_port->m_RxQueHead_u16 +
1 ) & RX_QUE_SIZE_MASK;
	 m_serial_port->m_RxQue_u8[ m_serial_port->m_RxQueHead_u16 ] =3D
rx_byte_u8;
       }
      }
     }
    Code =3D SioEvent(COM_Port, EV_RXCHAR);// Block until a new =
character
comes in the serial port
   }
    return NULL;
}

If I never enable this thread the program runs fine, except for the
missing serial input.

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
ray
6/24/2005 2:47:42 AM
comp.soft-sys.wxwindows 21076 articles. 0 followers. Post Follow

0 Replies
397 Views

Similar Articles

[PageSpeed] 34

Reply: