Results 1 to 6 of 6

Thread: serial port and USB communication

  1. #1
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Question serial port and USB communication

    hiii friends

    does anybody know how to do communication between two PCs using serial port and also using USB port.

    please tell me how can i write code with the help of Qt.
    It will be better if anybody can provide me with a sample example code.

    I am using Qt 3.3.0 in Red Hat-9 Linux
    There are 10 kinds of people in this world. Those who understand binary, and those who dont.

    regards
    shamik

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: serial port and USB communication

    Qt by itself won't help you much here. You need to set up a connection between both machines using some serial protocol (SLIP/CLIP/PPP?).

  3. #3
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: serial port and USB communication

    but i just want to send and recieve simple data through usb. and for that i dont think i need any protocol.
    cant i write just a simple program in Qt say one for server and one for client and then connect the two pcs through their usb and then start the data transfer?.....actually i dont know anything about data transfer through either usb or serial port.
    can u please help how to do make a correct and systematic approach ? if not usb then atleast can Qt help with serial communication??
    There are 10 kinds of people in this world. Those who understand binary, and those who dont.

    regards
    shamik

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: serial port and USB communication

    Quote Originally Posted by shamik View Post
    but i just want to send and recieve simple data through usb. and for that i dont think i need any protocol.
    Of course you need a protocol. The protocol has to at least specify "who talks now", "who listens now", "how fast we talk" and "what language we use to talk".

    cant i write just a simple program in Qt say one for server and one for client and then connect the two pcs through their usb and then start the data transfer?
    Yes, if the system will create device nodes for those usb/serial devices. You can then open "/dev/sttySomething" and read from it/write to it.

    can u please help how to do make a correct and systematic approach ?
    A correct approach is to setup a communication channel through a device driver (meaning Qt can't help, as already mentioned).

    if not usb then atleast can Qt help with serial communication??
    USB is also serial, so everything applies

  5. #5
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: serial port and USB communication

    Quote Originally Posted by wysota View Post
    Of course you need a protocol. The protocol has to at least specify "who talks now", "who listens now", "how fast we talk" and "what language we use to talk".
    can u tell me how to setup a protocol??

    A correct approach is to setup a communication channel through a device driver (meaning Qt can't help, as already mentioned).
    how to do it. ??


    fine.
    if not Qt then i m sure i can do it using c++ alone. I have done some research and have come to know that using a structure called termios defined in termios.h fine we can communicate through usb and serial port. i.e. we can open, close, read and write through the port. but i dont know how to do it.

    can anybody please help??
    There are 10 kinds of people in this world. Those who understand binary, and those who dont.

    regards
    shamik

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: serial port and USB communication

    Quote Originally Posted by shamik View Post
    if not Qt then i m sure i can do it using c++ alone.
    No, you can't if your system doesn't have support for serial communication enabled. You'll still have to do it no matter what. And when you do it, you won't need any other "special tricks". When using plain serial everything should be already set up, so you'd just need to set proper device options using ioctl (like the speed of the device) and then you can simply open a proper ttyS device and communicate with it as I already mentioned in the previous post. For USB you still need to configure the device to reveal its serial ports (they should be called /dev/ttyUSB0, /dev/ttyUSB1, etc.) and find a proper one to communicate with (especially if you have other USB devices plugged in).

    I have done some research and have come to know that using a structure called termios defined in termios.h fine we can communicate through usb and serial port. i.e. we can open, close, read and write through the port.
    This is true if you already configured the connection between two machines. If you did, you can forget about termios and simply open the device and use it.

    but i dont know how to do it.

    can anybody please help??
    You still have to set the connection between two ends of communication. And if you want a two-way transmission, you'll have to use SOME protocol - either an existing one or your own one. If you don't know what carrier collisions are, I'd suggest you go with an existing one (the easiest one would be PPP as it would give you an IP interface between machines, so you could use IP protocols like TCP or UDP).

    You can start here: http://tldp.org/HOWTO/Serial-HOWTO.html#toc1

    As for Qt support, see here: http://qextserialport.sourceforge.net, it should be enough for you if you don't use USB. If you do, you'll still need to make sure your kernel reveals USB serial ports.

    Anyway, what exactly do you need the connection for? Do you want to transfer files or some application data?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.