Find the answer to your Linux question:
Results 1 to 5 of 5
Can anyone plz help ?? I want to write a C program which can receive and transmit a serial data through the usb port . are there any ready packages ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    2

    Read and write serial data to USB port


    Can anyone plz help ??
    I want to write a C program which can receive and transmit a serial data through the usb port .
    are there any ready packages to do so??

    plz help ...
    Thank you

  2. #2
    Just Joined!
    Join Date
    Feb 2006
    Posts
    1

    usb to serial

    The easiest way is to get a usb to serial dongle. It will give you an RS232 interface, and you can access it through a simple terminal program such as GTKTerm or minicom. Good luck.

  3. #3
    Linux User
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    260
    Once you have your USB-Serial dongle, plug it into your USB port. Open a terminal and type:
    Code:
    ls /dev/ttyUSB*
    If you see the output "/dev/ttyUSB0" or something like it, then your system is ready to use the USB-Serial interface.

    To use the serial interface, you need the "cu" program ("cu" means "call-up"). In debian systems, to install the suite of tools including "cu" just type
    Code:
    apt-get install uucp
    To use "cu", just specify the USB device and the line speed.The line speed (sometimes called "baud rate") depends on the device you are talking to. 9600, 38400, and 115200 are commonly used line speeds.

    Once you have verified that "cu" is working, you can write your C program. Use the "fork()" function to start a child process, and in the child process, call the "system()" function to launch "cu": for example:
    Code:
    ...
    int parent_main(int argc, char * argv[]);
    ...
    int main(int argc, char * argv[]) {
        int pid = fork();
        if(pid == 0) {
            system("cu -l /dev/ttyUSB0 -s 115200");
        }
        else if(pid > 0) { return parent_main(argc, argv); }
    }
    ...
    Use the pipes API to communicate between the child "cu" process and the parent process of your C program.

    Emacs also has a built-in "cu" like program, so you may not need to install "cu". If you enter the emacs command "serial-term", emacs will ask you for the interface, ("/dev/ttyUSB0") and the line speed, and then give open a terminal buffer for you to communicate with your device.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Oct 2011
    Posts
    2

    Is there any solution without using USB to serial converter?

    Thanks for the reply.
    Actually I have a USB led lamp which changes its colour. So I wanted to write a program which can send diff data through the port,which will change the colour on the lamp. Do you have a solution for this?
    Writting a program which sends raw random data through the port....

    Thanks a lot

  6. #5
    Linux User
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    260
    Quote Originally Posted by Vish-Master View Post
    Writting a program which sends raw random data through the port....
    OK, I suggest using the "libusb" library. Libusb is a pretty good C language API that give you the tools to select the device from the USB device tree by its name, and then send it arbitrary data. The documentation (click here) is pretty good too.

    Use your Linux's package manager to install both the library package and the C header files package.

    You should check the chipset of your colour-lamp to make sure you send it data in the correct format.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •