Results 1 to 6 of 6
Hello!
I want to work on an application that is transferring some ASCII letters through the serial port of a PC to a microcontroller (So, just Data transferring over the ...
- 06-30-2010 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 4
Serial programming?
Hello!
I want to work on an application that is transferring some ASCII letters through the serial port of a PC to a microcontroller (So, just Data transferring over the TX Pin of the Cable).
My question is: Does anybody have an easy script, which opens the port, sends a char string or something and closes the connection?
I just need an working script or infos with the essential functions.
Thanks!
- 06-30-2010 #2
If I am not mistaken, it should be as easy as:
echo "Hello" > /dev/ttyS0
or another deviceDebian GNU/Linux -- You know you want it.
- 07-01-2010 #3Just Joined!
- Join Date
- Oct 2009
- Posts
- 4
Yes, it worked perfectly! Didnt think, it would be that easy

Thanks
One last question: How can I receive e.g. the word 'Hello' over the serial interface?
Is there an easy command too?
Thanks in advance.
- 07-01-2010 #4
/dev/ttyS0 is a device, but can be accessed like any file.
If you echo with to > to it, it is just like writing to a file.
Try it out:
echo "hello" > newfile.txt
and you will have a new file with this content.
The same applies for reading.
A way to display the content of a file is the cat command.
cat newfile.txt
And this is how you read from ("listen at") the serial port as well.Debian GNU/Linux -- You know you want it.
- 07-01-2010 #5Just Joined!
- Join Date
- Oct 2009
- Posts
- 4
OK, great. That works!
So I write the input to to a file "receive.txt"
Now I want to get the content of that file and save it as a variable in my C Programm. I get the output of the file with
But how can I save the content as a variable?Code:printf("cat receive.txt\n");
Thanks!
- 07-01-2010 #6
C has its own set of file routines. fopen, fwrite, fread, etc...
Debian GNU/Linux -- You know you want it.


Reply With Quote