1. I am developing an application which should continuously monitor
the serial port inside the thread for any data arrival.
2. In a application, i just created a thread. Inside a thread, i am
opening a port. After that FOREVER loop has started. In side the
forever loop, i have given selecet statement as per the example given
by the help. It goes inside the FOREVER loop and got hanged..
I Hope the error is in the line, if( FD_ISSET( nOpenReturn,
&readFDs ) )
I have no idea, why it fails..
3.I am using Tornado II and VxWorks 5.4.
4. The Source code, i have generated is as follows
/*My Source Code Starts Here....*/
#include "VxWorks.h"
#include "fcntl.h"
#include "selectLib.h"
#include "ioLib.h"
#include "taskLib.h"
#include "sigLib.h"
#include "stdio.h"
#include "string.h"
#define STACK_SIZE 20000
#define MAX_FDS 2
#define MAX_DATA 1024
/* Thread Identifier */
int nReadProcess;
/* File Descriptor */
int nOpenReturn;
/* Thread to monitor and read the serial port continuously */
void ReadingPort(void);
/* Application gets initialized here */
void Read(void)
{
/* Task or thread is being started */
nReadProcess = taskSpawn ("Reading",200, 0, STACK_SIZE,
(FUNCPTR) ReadingPort,0,0,0,0,0,0,0,0,0,0);
}
void ReadingPort(void)
{
struct fd_set readFDs;
int width, i;
char buffer[MAX_DATA];
/* Open File Descriptors */
nOpenReturn = open("/tyCo/0",2,0);
nStatus1 = ioctl( nOpenReturn, FIOBAUDRATE, 9600 );
nStatus2 = ioctl( nOpenReturn, FIOSETOPTIONS, OPT_RAW);
/* Loop for ever for reading data from the serial port */
FOREVER
{
/* Clear bits in read bit mask */
FD_ZERO(&readFDs);
/* Initialise bit masks */
FD_SET( nOpenReturn, &readFDs);
/* pend, waiting for the file descriptor to become ready */
if( select( nOpenReturn, &readFDs, NULL, NULL, NULL ) == ERROR )
return ( ERROR );
/* read from the file descriptor it it gets ready */
if( FD_ISSET( nOpenReturn, &readFDs ) )
{
read(nOpenReturn, buffer, MAX_DATA);
printf("The data read from the serial port is %s", buffer);
}
}
}
/*My Source Code Ends Here....*/
5. Can you suggest me, what is the problem with this code? If it is
not a right way, what is an alternate path to read the message from
the serial port while data occurs at any time. Can you give me some
sample code over here??
With Thanks and Regards,
Manivannan.B.
/* pend, waiting for the file descriptor to become ready */
if( select( nOpenReturn+1, &readFDs, NULL, NULL, NULL ) == ERROR )
return ( ERROR );
shafi
mani...@covansys.com (B.Manivannan) wrote in message news:<23de5426.01123...@posting.google.com>...
Thanks for your response. But still the control gets hanged in the
FOREVER loop. I made nOpenReturn to nOpenReturn+1. In this select
statement only it got hanged..
What i am doing is,
I will type the "Read" and enter in the Target Shell..It has to wait
till the message arrives to serial port..One the message has come, it
has to fall down the flow and should continue to run..Hope you would
have understood my requirement.
Regards,
Manivannan.B.
> /* Open File Descriptors */
> nOpenReturn = open("/tyCo/0",2,0);
Here you open a channel which is already opened by tShell. And you do not
check for a return error code. If the open call fails, nOpenReturn will
get -1 and all the code which uses it to select() will fail very badly,
since file descriptor -1 will never be ready!
Also
> nReadProcess = taskSpawn ("Reading",200, 0, STACK_SIZE,
> (FUNCPTR) ReadingPort,0,0,0,0,0,0,0,0,0,0);
your task is running at priority 200, but the tShell task has priority 1.
So it is very likely that the shell will intercept all the characters from
the serial port and your task will not get them. You could make sure the
shell does not interfere by disabling it or by lowering its priority, but
even better would be not trying to use the same serial port for two
different programs at the same time...
DaveK
--
moderator of
alt.talk.rec.soc.biz.news.comp.humanities.meow.misc.moderated.meow
Burn your ID card! http://www.optional-identity.org.uk/
Help support the campaign, copy this into your .sig!
Proud Member of the Exclusive "I have been plonked by Davee because he
thinks I'm interesting" List
Member #<insert number here>