segfaults are caused by very bad mistakes in code. So we need to see the code before we can give you a solution.
segfaults are caused by very bad mistakes in code. So we need to see the code before we can give you a solution.
sar_van81
For what its worth I have used QextSerialPort and it works well.
Below is the snippet of code used to setup the port. "portname1" is determined by the OS being used at the time.
Hope this is of some use to you....
Qt Code:
void Progarm::setupSerial() { serialPort = new QextSerialPort( portname1 ); serialPort->setBaudRate( QextSerialPort::BAUD9600 ); serialPort->setDataBits( QextSerialPort::DATA_8 ); serialPort->setStopBits( QextSerialPort::STOP_1 ); serialPort->setParity( QextSerialPort::PAR_NONE ); serialPort->setFlowControl( QextSerialPort::FLOW_OFF ); serialPort->setTimeout( 0, 500 ); if (!serialPort->isOpen() ) { "Could not open the serial port\n" "\n" "Please check connections and try again\n" ); label->setText( "Serial port error" ); return; } }To copy to clipboard, switch view to plain text mode
Regards, B1.
B1:
the following is my code:
.Qt Code:
{ setMinimumSize(640,480 ); Posix_QextSerialPort *note= new Posix_QextSerialPort("/dev/ttyS0"); note->setBaudRate(Posix_QextSerialPort::BAUD115200); note->setParity(Posix_QextSerialPort::PAR_NONE); note->setDataBits(Posix_QextSerialPort::DATA_8); note->setStopBits(Posix_QextSerialPort::STOP_1); note->open(IO_ReadOnly); int n; n=note->bytesWaiting(); if(n!=0) printf("\nreading the buffer datas \n"); }To copy to clipboard, switch view to plain text mode
Also can you say me how to read the datas from the serial port . i saw that only int Posix_QextSerialPort::getch() is available. is there any function to read a block of datas for example say 10bytes ?
saravanan
sar_van81,
This is what I use in a simple app...bear in mind I am still learning too!!
Qt Code:
void Program::dataListener() { // see how many bytes available from the serial port rec = serialPort->bytesAvailable(); if (rec > 0 ) { if ( rec > 256 ) rec = 256; z = serialPort->read( buffer, rec); buffer[z] = '\0'; tempmsg = buffer; } dispData(); }To copy to clipboard, switch view to plain text mode
There may be (and probably are!) better ways of doing this but for me it did what I wanted. You can also use serialPort->getChar(buffer) and read the serial port character by character and then process the buffer accordingly.
Hope this helps.
B1.
B1:
Ok. let me try this.but the application does not open successfully.it prompts me for "segmenattion fault error".if i comment the following lines:
.Qt Code:
Posix_QextSerialPort *note= new Posix_QextSerialPort("/dev/ttyS0"); note->setBaudRate(BAUD115200); note->setParity(PAR_NONE); note->setDataBits(DATA_8); note->setStopBits(STOP_1); note->open(IO_ReadOnly);To copy to clipboard, switch view to plain text mode
the program executes successfully. Did you experience any problem like this ?
Am i missing some thing more ?
Why are you commenting out these lines? with out them you don't have an initialized serial port objet.
Also, QextSerialPort is made crossplatform, so you don't need to explicitly use Posix_QextSerialPort (this wont compile under windows) - there are defines in the code that will select the correct version for you.
Just use QextSerialPort.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
high_flyer:
if i use QextSerialPort instead of Posix_QextSerialPort, it shows me the following error:
home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:11:21: error: windows.h: No such file or directory
/home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:57:7: warning: no newline at end of file
In file included from tux.cpp:21:
/home/qtprograms/qwt/qextserial/qextserialport-0.8.0/qextserialport.h:26:7: warning: no newline at end of file
/home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:50: error: ‘HANDLE’ does not name a type
/home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:51: error: ‘COMMCONFIG’ does not name a type
/home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:52: error: ‘COMMTIMEOUTS’ does not name a type
make: *** [tux.o] Error 1
.
So only i used Posix_QextSerialPort. Should i define somewhere about _TTY_POSIX ? Also as i said before when i include them in my code its prompting me segmentation fault.
Exactly - You should add DEFINES += _TTY_POSIX in your pro file (or if you are using KDevelop it has a field for that in the qmake configuration).So only i used Posix_QextSerialPort. Should i define somewhere about _TTY_POSIX ?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
high_flyer:
that parameter has already been set when i untar the qextserial package. should i specify that in my application pro file ?
Let me explain what i have done so far :
1). Downloaded the qextserial package , untarred and entered qmake ,make. there were the following libraries created:
libqextserialport.so libqextserialport.so.1 libqextserialport.so.1.0 libqextserialport.so.1.0.0
2). Then created a directory ,copied my source files. entered the header files and the libraries for qextserial in my project file. then entered make.
is this procedure correct ? else can you say me the correct one ?
yes.should i specify that in my application pro file ?
It should work.is this procedure correct ? else can you say me the correct one ?
But I would not copy the header files and libs, I would link to them or user the -L and -I in my make file.
But that is a subjective private taste matter, your way should work just as well.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
hi ,
i specified in my project file also and it compiled successfully.but still the same error comes . Is there any permission i need to set to serial port ? i'l post my full code here if any one find any error please point me :
Qt Code:
#include <qwidget.h> #include <qapplication.h> #include <stdlib.h> #include <qextserialport.h> { public: private: int mouse; int mouseidx; }; { setMinimumSize(640,480 ); QextSerialPort *note= new QextSerialPort("/dev/ttyS0"); note->setBaudRate(BAUD115200); note->setParity(PAR_NONE); note->setDataBits(DATA_8); note->setStopBits(STOP_1); note->open(IO_ReadOnly); } int main( int argc, char **argv ) { Widget connect1; a.setMainWidget( &connect1 ); connect1.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
Last edited by high_flyer; 7th May 2007 at 10:54. Reason: missing [code] tags
I guess you mean the segmentation fault.compiled successfully.but still the same error comes .
Your code has the following problems:
You are allocating the serial port on to a local pointer.Qt Code:
QextSerialPort *note= new QextSerialPort("/dev/ttyS0");To copy to clipboard, switch view to plain text mode
You will not be able to access the serial port outside the constructor.
'note' needs to be a member variable.
Where is the code that handels the reading/writing to the serial port?
Hi B1,
DId you experience any segementation problem in creating the serialport in heap like mine ? i tried your way of declaring also ? but i still could not make it ?
Do you mean that the program crashes on:I have not added the settings of the serial port.As i found that starting from this line the error pops up.
m_note->setBaudRate(BAUD115200); ?
This code should run.
How did you discover on which line the program crashes, what method did you use to debug?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
high_flyer:
No , the program crashes in the first line itself. i mean :
m_note= new QextSerialPort("/dev/ttyS0");
I had only this line in my constructor ( as i had posted in the above post). i did not have any other line.
You mean the only line of code in ConnectWidget constructor right?I had only this line in my constructor ( as i had posted in the above post). i did not have any other line.
Does it run if you remove that line as well?
Does it run when this construcotr is empty?
Are you sure you are not trying to use a 'note' or 'm_note' somehwere else in your code?
It would be good if you could post you mail() function.
The problem in your code is not the parts we currently see.
Ofcourse there is also the chance that the QextSerialPort lib is faulty for some reason on your system.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
yeah, it runs if i comment that line and place a printf there.And i'm sure i dont use that anywhere in my code.
I have not used any thing like this function .It would be good if you could post you mail() function.
Also i'm using qextserialport-0.8.0 package since only this supports qt-3.3.5 version. remaining packages such as qextserialport-0.9.0,1.0,1.1 supports higher versions of qt. will there be any problem with this version changes ?
Sorry, I meant main().I have not used any thing like this function .
Hmm... then from what you have said so far, it all points to a problem in your QextSerialPort lib.yeah, it runs if i comment that line and place a printf there.And i'm sure i dont use that anywhere in my code.
What do you mean?Also i'm using qextserialport-0.8.0 package since only this supports qt-3.3.5 version. remaining packages such as qextserialport-0.9.0,1.0,1.1 supports higher versions of qt. will there be any problem with this version changes ?
using a Qt4 QextSerialPort with Qt3?
That wont work.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
The following in my main():
Qt Code:
int main( int argc, char **argv ) { ConnectWidget connect1; a.setMainWidget( &connect1 ); connect1.show(); return a.exec(); }To copy to clipboard, switch view to plain text modeNo i mean i'm using qt-3.3.5 version and the other versions of qextserialport requires header and libraries of qt 4 or greater version.What do you mean?
using a Qt4 QextSerialPort with Qt3?
That wont work.
Well, from what I can see, there is no problem with the code it self.
You can only link QextSerialPort for Qt3 (which is linked against Qt3) with Qt3 applications.
You can only link QextSerialPort for Qt4 (which is linked against Qt4) with Qt4 applications.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Bookmarks