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 ...
- 10-25-2011 #1Just 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
- 10-25-2011 #2Just 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.
- 10-26-2011 #3Linux Newbie
- Join Date
- Nov 2008
- Location
- Tokyo, Japan
- Posts
- 243
Once you have your USB-Serial dongle, plug it into your USB port. Open a terminal and type:
If you see the output "/dev/ttyUSB0" or something like it, then your system is ready to use the USB-Serial interface.Code:ls /dev/ttyUSB*
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 typeTo 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.Code:apt-get install uucp
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:Use the pipes API to communicate between the child "cu" process and the parent process of your C program.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); } } ...
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.
- 10-27-2011 #4Just 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
- 10-27-2011 #5Linux Newbie
- Join Date
- Nov 2008
- Location
- Tokyo, Japan
- Posts
- 243
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.


Reply With Quote

