u're right......i had downloaded a wrong package
now i have downloaded a correct one which works with Qt3. The make command has generated the libraries well.
but i dont know how to use this class and its functions.
all the function i found deals with byte transfer i.e. getch(), putch() etc.
but i want to transfer and recieve files like zip, pdf etc.
i cant find any such functions directly sending and recieving files...
can any1 plz suggest
There are 10 kinds of people in this world. Those who understand binary, and those who dont.
regards
shamik
Use getch or putch in a loop.
suppose its a zip file stored somewhere like /root/xp.zip
then how to use that getch() and putch() ??
There are 10 kinds of people in this world. Those who understand binary, and those who dont.
regards
shamik
Oh come on.... What kind of a question is that?
Open the file, read characters and transmit them over the serial line. You'll probably need some protocol of communication to transfer the file length and file name. You can probably use QDataStream to ease your task.
no need to use getch().
Just use readBytes() and you don't need a loop.
But the rest is the same as wysota said.
==========================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,
Plenty of serial comms classes on the web...
Personally, I use my own I wrote which is for windows, if it is for windows you want to use serial comms, just use api calls such as ::CreateFile, ::WriteFile etc...
Here is some code from my serial class, may help ( this is for Windows )?
Qt Code:
template<class T=char, int nSize=100> class CSerialComms { public: T& operator[]( int nIndex ) { return m_buf[nIndex]; } CSerialComms& operator=( const CSerialComms& r ) { memcpy( m_buf, r.m_buf, nSize ); m_cto = r.m_cto; m_dcb = r.m_dcb; m_hFile = r.m_hFile; return *this; } inline int SetTimeouts( DWORD dwReadInterval = 1, DWORD dwReadTotalTimeout = 100, DWORD dwReadTotalTimeoutConstant = 1000, DWORD dwWriteTotalTimeout = 0, DWORD dwWriteTotalTimeoutConstant = 0 ) { int nError = SUCCESS; m_cto.ReadIntervalTimeout = dwReadInterval; m_cto.ReadTotalTimeoutMultiplier = dwReadTotalTimeout; m_cto.ReadTotalTimeoutConstant = dwReadTotalTimeoutConstant; m_cto.WriteTotalTimeoutMultiplier = dwWriteTotalTimeout; m_cto.WriteTotalTimeoutConstant = dwWriteTotalTimeoutConstant; if( !::SetCommTimeouts( m_hFile, &m_cto) ) { nError = GetLastError(); } return nError; } inline int OpenPort( LPCTSTR szPort = "COM1" ) { int nError = SUCCESS; m_hFile = ::CreateFile( szPort, GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if( m_hFile == INVALID_HANDLE_VALUE ) { nError = GetLastError(); } return nError; } inline int SetCommsDevice( DWORD dwBaud = 57600, BYTE iParity = NOPARITY, BYTE iStopBits = ONESTOPBIT, BYTE iByteSize = 8 ) { int nError = SUCCESS; memset( &m_dcb, 0, sizeof( m_dcb ) ); m_dcb.DCBlength = sizeof( m_dcb ); m_dcb.BaudRate = dwBaud; m_dcb.Parity = iParity; m_dcb.StopBits = iStopBits; m_dcb.ByteSize = iByteSize; if( !::SetCommState( m_hFile, &m_dcb ) ) { nError = GetLastError(); } return nError; } DWORD TxData( T* szBuf ) { DWORD nowrote = 0; memset( m_buf, 0, sizeof( m_buf ) ); if( sizeof( m_buf ) >= strlen( szBuf ) ) // check to see if buffer allocated is big enough { memcpy( &m_buf[1], szBuf, strlen( szBuf ) ); m_buf[0] = 0x2; m_buf[ strlen(szBuf) + 1 ] = 0x3; return TxData(); } return BUFFEROVERFLOW; } DWORD TxData() { DWORD nowrote = 0; ::WriteFile( m_hFile, m_buf, strlen(m_buf), &nowrote, NULL ); return nowrote; } CSerialComms( void ){ memset( m_buf, 0, nSize ); }; ~CSerialComms(){}; private: T m_buf[nSize]; COMMTIMEOUTS m_cto; DCB m_dcb; HANDLE m_hFile; enum { FAILED = 0, SUCCESS = 1, BUFFEROVERFLOW = 2 }; }; #endif // !defined(AFX_SERIALCOMMS_H__BA76EBFF_6F02_4E79_BC65_DD4C2655354B__INCLUDED_)To copy to clipboard, switch view to plain text mode
Regards,
Steve
True, but QextSerialPort is based on QIODevice and therefore integrates well withe Qt Stream classes, and you can sublass it and add signals and slots to it (if you need such a thing, I didn't so far)Plenty of serial comms classes on the web...
And ofcourse, QextSerialPort is cross platform!
Last edited by high_flyer; 22nd May 2007 at 15:46.
==========================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.
here's wat i have done
Qt Code :
Qt Code:
int size; int *i,j,k; if(!file.open( IO_ReadOnly )) { } else { cout<<"File opened successfully"<<endl; } cout<<"file opened...."<<endl; unsigned char fname[]="mxdrv.tgz"; struct termios t; char *device = "/dev/ttyS0"; int sPort, rbyte, status, sPortdest,length; long count=0; unsigned char send1[32]; t.c_cc[VMIN] = 1; t.c_cc[VTIME]=0; t.c_cc[VEOF]='\n'; t.c_iflag |= (ISIG); t.c_iflag &= ~BRKINT; t.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; sPort = open(device,O_RDWR|O_NOCTTY|O_NDELAY); if(sPort != -1) { cout<<"open successfully\n"; status = ioctl(sPort,TCSETS,&t); cout<<"Entering status"<<status<<endl; if(status==0) { //for(count=0;count<20;count++) cout<<"sending name"<<endl; rbyte=write(sPort,fname,strlen((char *)send1)); //usleep(3000); cout<<"name sent"<<endl; cout<<"now sending file"<<endl; while(!file.atEnd()) { //cout<<"Enter :"; //cin>>send1; //strcat((char *)send1,"{MSS TYPE-D DAMA}"); // write(sPort,"{012345678}",11); *i=file.getch(); rbyte=write(sPort,i,sizeof(*i)); cout<<rbyte<<"sent"<<endl; //cout<<"w b:"<<rbyte<<"\t Time:"<<count<<"\t string:"<<send1<<"\n"; //usleep(1000); } } close(sPort); } else { cout<<"Device could not be opened"; } file.close();To copy to clipboard, switch view to plain text mode
by running this code from the shell, following is the output :
File opened successfully
file opened....
open successfully
Entering status0
sending name
name sent
now sending file
Segmentation fault
can any1 please tell watz going wrong over here ??
There are 10 kinds of people in this world. Those who understand binary, and those who dont.
regards
shamik
As far as I can see, int *i is not allocated anywhere.
You must allocate i before you can use it.
Regards
Don't use "int *i" but "int i". You have an uninitialised pointer. I don't see any reason why would you want to use a pointer to an int, so just use the object directly.
sorry
please refer the post below
There are 10 kinds of people in this world. Those who understand binary, and those who dont.
regards
shamik
rather i've used QString with a little bit modification
Code :
Qt Code:
int size; int i,j,k; if(!file.open( IO_ReadOnly )) { } else { cout<<"File opened successfully"<<endl; } cout<<"file opened...."<<endl; unsigned char fname[]="mxdrv.tgz"; struct termios t; char *device = "/dev/ttyS0"; int sPort, rbyte, status, sPortdest,length; long count=0; unsigned char send1[32]; t.c_cc[VMIN] = 1; t.c_cc[VTIME]=0; t.c_cc[VEOF]='\n'; t.c_iflag |= (ISIG); t.c_iflag &= ~BRKINT; t.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; sPort = open(device,O_RDWR|O_NOCTTY|O_NDELAY); if(sPort != -1) { cout<<"open successfully\n"; status = ioctl(sPort,TCSETS,&t); cout<<"Entering status"<<status<<endl; if(status==0) { //for(count=0;count<20;count++) cout<<"sending name"<<endl; rbyte=write(sPort,fname,strlen((char *)fname)); //usleep(3000); cout<<"name sent"<<endl; cout<<"now sending file"<<endl; while(!file.atEnd()) { //cout<<"Enter :"; //cin>>send1; //strcat((char *)send1,"{MSS TYPE-D DAMA}"); // write(sPort,"{012345678}",11); cout<<"getting byte from file"<<endl; i=file.getch(); send.sprintf("%d",i); cout<<send<<endl; rbyte=write(sPort,send,strlen(send)); cout<<rbyte<<"sent"<<endl; //cout<<"w b:"<<rbyte<<"\t Time:"<<count<<"\t string:"<<send1<<"\n"; //usleep(1000); } } close(sPort); } else { cout<<"Device could not be opened"; } file.close();To copy to clipboard, switch view to plain text mode
when i run the program from the terminal, the bytes get transfered which i can see in the hyperterminal of some other pc.
but then after some time the following comes on the terminal and the program exits abruptly:
*** glibc detected *** ./filetransfer: munmap_chunk(): invalid pointer: 0xbffe8e70 ***
======= Backtrace: =========
/lib/libc.so.6(cfree+0x1bb)[0xe5d67b]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x6874871]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QWidget5closeEb+0x1f6)[0x5198e6]
./filetransfer[0x804fdcb]
./filetransfer[0x804fa3b]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QObject15activate_signalEP15QConnectio nListP8QUObject+0x16a)[0x4dbe2a]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QObject15activate_signalEi+0xbd)[0x4dc95d]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QButton7clickedEv+0x2c)[0x86f8ac]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QButton17mouseReleaseEventEP11QMouseEv ent+0xbd)[0x57fa3d]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QWidget5eventEP6QEvent+0x3c5)[0x5192d5]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication14internalNotifyEP7QObjec tP6QEvent+0x9b)[0x4730fb]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication6notifyEP7QObjectP6QEvent +0x287)[0x474757]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN9QETWidget19translateMouseEventEPK7_XEv ent+0x576)[0x40af26]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication15x11ProcessEventEP7_XEve nt+0x5e6)[0x409a26]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop13processEventsEj+0x4eb)[0x41b6ab]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop9enterLoopEv+0x42)[0x48c672]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop4execEv+0x26)[0x48c536]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication4execEv+0x1f)[0x472c0f]
./filetransfer(_ZN7QWidget6createEmbb+0xe2f)[0x804ef2f]
/lib/lAborted
any suggestions ??
There are 10 kinds of people in this world. Those who understand binary, and those who dont.
regards
shamik
Bookmarks