Visit Our UNIX and Linux User Community

getting problem in my code:::: plz help...(multithreaded appn with serial comm.)

Thread Tools Search this Thread
Operating Systems Linux getting problem in my code:::: plz help...(multithreaded appn with serial comm.)
# 1  
Old 10-26-2007
getting problem in my code:::: plz help...(multithreaded appn with serial comm.)


here I am copying my code...

I am using two threads for reading and writing at com for reading and one for read thread I am using select() api....and polling again and again if there is some data to be read....but select is not returning any positive value so that it can read the data from serial port....
follows is the section my code where I am facing the problem..
can anybody help????????? regarding that....
where is the problem in the code???????
where I am lacking???????

#include "DataServerPort.h"
#include "DataServerLog.h"
//#include "DCSPacket.h"

extern QString packet;
extern DataServerLog d_LogObject;
extern DataServerLog CCUComLog;
extern DataServerPort *DSPComTh1;
extern DataServerPort *DSPComTh2;
extern bool g_bIsCCUCOMPortInitialized;
DataServerPort *p_DataportWrite;
int g_iLinkFailCounter = 0;
bool g_bLinkFailedTimerStartFlag = false;

// Queue
//extern CGCQueue DataPortEventQueue;
//extern CGCQueue DataPortCommandQueue;

pthread_t DataReadThread;
pthread_t DataWriteThread;

pthread_mutex_t g_csDataportMutex=PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t g_csDataportEventQueueMutex=PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t g_csDataportComandQueueMutex=PTHREAD_MUTEX_INITIALIZER;




long DataServerPort::initializeDataServerPort(QString &sPortnumber)
//CCUComLog.writeDataLog("Dataserver Com port init function\n");
//QString sCom = "/dev/ttyS";
//sPortnumber = sPortnumber.stripWhiteSpace();
//sCom = sCom + sPortnumber;
//m_hCreateFile = open(sCom,O_RDWR|O_NOCTTY|O_NDELAY);
m_hCreateFile = open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);
if(m_hCreateFile == -1)
CCUComLog.writeDataLog("Com port open failed\n");
return -1;exit(0);

CCUComLog.writeDataLog("Dataserver Comport before thread\n");
// pthread_create(&DataReadThread,NULL,DataServerThread_readfun,NULL);


CCUComLog.writeDataLog("DataServer Comport after the thread\n");

return 1;


void DataServerPort::initPortSection()

tcgetattr( m_hCreateFile , &s_mTermios);

s_mTermios.c_cc[VMIN] = 1;

s_mTermios.c_iflag &= ~BRKINT;
s_mTermios.c_iflag = ISIG | IUCLC;
s_mTermios.c_oflag &= (OLCUC);
s_mTermios.c_cflag = B9600 | CS8 | CREAD | CLOCAL| HUPCL;

printf("exiting function initportsection\n");

void* DataServerThread_readfun(void* arg)

{ printf("I am in thread 1\n");
int iResultselect , iCheckallfd , iRbyte;
bool b_newPacketStarted=false;
unsigned char cTempbuf[2];
QString sReceivedData = "" ;
QString SendBuff="";
CCUComLog.writeDataLog("DataCom threadfun \n");
DataServerPort* p_Dataport = (DataServerPort*)arg;
//DataServerEvent* TheCEvent = NULL;
bool bFirsttime = true;
//bool b_newPacketStarted=false;
p_DataportWrite = new DataServerPort();

p_DataportWrite->s_mTermios = p_Dataport->s_mTermios;
p_DataportWrite->m_hCreateFile = p_Dataport->m_hCreateFile;

CCUComLog.writeDataLog("DataServer Comport Read Thread: p_Dataport->m_hCreateFile",p_Dataport->m_hCreateFile);

fd_set testfds,readfds;
struct timeval timeout;
FD_SET(p_Dataport->m_hCreateFile,&readfds);///add p_Dataport into readfds...




//printf("you r with try and catch\n");

testfds = readfds;

iResultselect = select(FD_SETSIZE,&testfds,(fd_set *)0,(fd_set *)0,&timeout);

if(iResultselect > 0)
{ printf("hello");
for ( iCheckallfd = 0 ; iCheckallfd < FD_SETSIZE ; iCheckallfd ++ )
if ( FD_ISSET ( iCheckallfd , &testfds ) )
if ( iCheckallfd == p_Dataport->m_hCreateFile )
iRbyte= read(p_Dataport->m_hCreateFile,cTempbuf,1);

if(iRbyte > 0)
sReceivedData ="";
} //if(b_newPacketStarted==false)
else if(b_newPacketStarted==true)
sReceivedData ="";
else if(cTempbuf[0]=='}')
//cout<<"\n\n The Received with bracket data is..."<<sReceivedData;
if(qstrlen(sReceivedData) == 11)
cout<<"\n\n The Received with full check data is....."<<sReceivedData;
CCUComLog.writeDataLog("\nData Received at Conc. -");
//TheCEvent = new DataServerEvent();
sReceivedData = "";
b_newPacketStarted=false ;
else // if data is not '{' or not '}'

} ////////if(iRbyte==1)
} //////////////else if(b_newPacketStarted==true)
} // //if fd==mcreatefile
} // if FD IsSet
} //for
} //if(i_Resultselect > 0)
else if(iResultselect<0)
// Error at comm Port


}// try
{ }

d_LogObject.writeDataLog("\n\n CCU Port Thread STOPPED...\n\n");
return NULL;

void *DataServerThread_writefun(void *arg)
DataServerPort *p_Write = (DataServerPort *)arg;
// DataServerCommand* TheCCommand = NULL;

bool bFirsttime=true;
QString SendBuff="";
//int iCounter=0;
int iStatus;
printf("you r in write thread function\n");
CCUComLog.writeDataLog("Dataserver write thread : ",p_Write->m_hCreateFile);
//CCUPortLog.writeDebugLog("\n CCU Write Thread : p_CCUPort->m_hCreateFile ",p_CCUPort->m_hCreateFile);

if(bFirsttime == true)
iStatus = ioctl(p_Write->m_hCreateFile,TCSETS,p_Write->s_mTermios);
bFirsttime = false;

// pthread_mutex_lock(&g_csDataportComandQueueMutex);
// TheCCommand = (DataPortCommand *)DataPortCommandQueue.RemoveTail();
// pthread_mutex_unlock(&g_csDataportComandQueueMutex);


//iCounter = 0;
//cout<<"\n Sending Packet to DataServer"<<SendBuff;
CCUComLog.writeDataLog("\n Sending Packet to DataServer---");

//while(iCounter < 3)
// {

// iCounter++;
// }
//DataServerLog.writeDebugLog("\n 3 times write completed");




d_LogObject.writeDataLog("\n\n Dataport Write Thread STOPPED...\n\n");
return NULL;

Previous Thread | Next Thread
Test Your Knowledge in Computers #962
Difficulty: Medium
ILOVEYOU, sometimes referred to as Love Bug or Love Letter, was a computer worm that attacked tens of millions of Windows PCs on and after 5 May 2000 local time in the Philippines.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

plz, i wait your help, AWK problem

I have tracefile of three nodes (0 , 1 and 2 ) as follows: + 0.02 0 1 tcp 40 ------- 1 0.0 2.0 0 0 - 0.02 0 1 tcp 40 ------- 1 0.0 2.0 0 0 + 0.02 2 1 tcp 40 ------- 2 2.1 0.1 0 1 - 0.02 2 1 tcp 40 ------- 2 2.1 0.1 0 1 r 0.025032 0 1 tcp 40 ------- 1 0.0 2.0 0 0 + 0.025032 1 2 tcp 40 -------... (11 Replies)
Discussion started by: ASAADAOUI
11 Replies

2. UNIX for Dummies Questions & Answers

Not sure how to use diff and comm for my problem

Hello, Apologies if this question has been repeated before, but I am getting myself confused even more as I scan the posts! I have two files, file1 is a column: 1dlwa_ 1s69a_ 1idra_ 1ngka_ And file2 has three columns (columns seperated by tabs): 1dlw a_ A 1uvy a_ A 1dly a_ A 1uvx... (1 Reply)
Discussion started by: InfoSeeker
1 Replies

3. Shell Programming and Scripting

problem with using comm

hi, I have two unsorted files and want to delete the lines which are common to both. file 1: S1069656304010437 S1069656304010449 S1470204501005393 S1069656304010474 S0001209208001294 S0000000012345678 S0001457507000590 S0002641707000784 S1470204501005381 S0001457507000280... (4 Replies)
Discussion started by: jathin12
4 Replies

4. Shell Programming and Scripting

Interpretion problem. Plz Help me guys.

Hey friends, below mentioned script is giving me proper o/p which can be “1” or “2” echo select status_ac from db_acct where acct_num='$1'" | dbaccess elstest Now I want to interpret the o/p as follows. If o/p is 1 then “YES” If o/p is 2 then “No” And to do this I have modified above... (2 Replies)
Discussion started by: anushree.a
2 Replies

5. Linux

Output formatting problem..Plz hlp

Hi guys, It will be a great help if somebody can help me in following problem. I have tried hard but because of lack of UNIX/LINUX knowledge I am not able to do it. I have written a script that returns 3 things of all the employees in my organisation. i.e. Name, Login time & log out time of... (2 Replies)
Discussion started by: anushree.a
2 Replies

6. UNIX for Dummies Questions & Answers

have a problem with if elif loop .. plz help me with the script

count2=0 var2=NOT if then echo"Loop1" command="egrep ',$var1," if then echo "the command is OR" command=$command"|,$var3," echo "$command" elif then command=$command"| egrep ',$var3," else ... (4 Replies)
Discussion started by: Syms
4 Replies

7. Programming

getting problem in my code:::: plz help...(multithreaded appn with serial comm.)

hello, here I am copying my code... I am using two threads for reading and writing at com for reading and one for read thread I am using select() api....and polling again and again if there is some data to be read....but select is not returning any positive value so... (0 Replies)
Discussion started by: arunchaudhary19
0 Replies

8. UNIX for Advanced & Expert Users

problem while getting the response back..plz help

Hi ALL: I am not able to get the response back from weblogic in the shell script. The weblogic server in different account. I am able to login to that account and bring the server up but while doing a ping, the script is failing. While the same script is running fine if I run it on the account... (1 Reply)
Discussion started by: splax
1 Replies

9. Shell Programming and Scripting

UNIX script problem ..Plz help ASAP

Hi folks, I have written down a UNIX script which actually FTP the file to other server. What is happening now , this script is not working only for 1 server , as it is working for 32 different FTP server . In this particular server , we are getting message “FTp:550 access denied”... (1 Reply)
Discussion started by: khan1978
1 Replies

10. UNIX for Dummies Questions & Answers

Multiboot problem Help plz??

I have installed Win98 OS .......1st then RH7.2 with GRUB bootloader okay i.e in the Grub there is two choices 1-Linux 2-Dos also I install bootloader of linux in MBR -master boot record- when select Linux an error : ... (6 Replies)
Discussion started by: atiato
6 Replies

Featured Tech Videos