Find the answer to your Linux question:
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 ...
  1. #1
    Just 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!

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    If I am not mistaken, it should be as easy as:

    echo "Hello" > /dev/ttyS0
    or another device
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just 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.

  4. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    /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.

  5. #5
    Just 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

    Code:
    printf("cat receive.txt\n");
    But how can I save the content as a variable?


    Thanks!

  6. #6
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    C has its own set of file routines. fopen, fwrite, fread, etc...
    Debian GNU/Linux -- You know you want it.

Posting Permissions

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