Find the answer to your Linux question:
Results 1 to 9 of 9
If someone know how to open a file on serial port and write on it. Currently I am opeing serial port with the following function: Code: ------ int fd; FILE ...
  1. #1
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5

    Writing file on a serial device in ANSI C

    If someone know how to open a file on serial port and write on it.

    Currently I am opeing serial port with the following function:

    Code:
    ------

    int fd;
    FILE *fp;
    .....

    fd = open("/dev/ttyS0", O_RDWR | O_NDELAY);

    ......

    fp = fopen("file.dat", "w");


    This file is opened and written in current directory, instead.

    If someone know, how to open this file on opened serial port????

  2. #2
    Just Joined!
    Join Date
    Mar 2007
    Posts
    16
    Hi lucky001,

    It is not clear what you are trying to accomplish. You might want to include a bit more or your code. If you have already opened the serial port, it seems you should be writing to that port. Instead it looks like you are writing to the file.dat file. If this is the open file that you are writing to, then it would make sense that file.dat would be created in the current directory. Are you trying to read from the serial port and write to a file?

  3. #3
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5
    Quote Originally Posted by dkloes
    Hi lucky001,

    It is not clear what you are trying to accomplish. You might want to include a bit more or your code. If you have already opened the serial port, it seems you should be writing to that port. Instead it looks like you are writing to the file.dat file. If this is the open file that you are writing to, then it would make sense that file.dat would be created in the current directory. Are you trying to read from the serial port and write to a file?

    Thanks for your reply first.

    I will explain in the steps:

    1) I have two computers connected via serial port.
    2) One have Unix and other one has Windows CE.
    3) I am writing and exceuting C-ANSI program from unix box.
    4) I need to connect to other computer (Windows CE) which I successfully did using fd = open("/dev/ttyS0", O_RDWR | O_NDELAY);
    5) Now I want to open & save this data file on computer having Windows CE.

    but do not know how to?

    I am new to C.

    Please let me know if you still have any questions.

    Regards
    Lucky

  4. #4
    Just Joined!
    Join Date
    Mar 2007
    Posts
    16
    Hi lucky001,

    There are many issues involved in working with serial ports. Serial port device files, such as /dev/ttyS0, are referred to as special files because they are not actual files. So, it is still not clear what you are trying to accomplish when you say you want to open and save this data file. Data that is communicated on a serial device can be read or written, but there are issues, such as flow control that you need to consider. Here is one source that I found that will help to explain some of the issues for interfacing with a serial port. As you will see from the article, there is much more to what you are trying to do than can be explained here simply.
    http://www.masoner.net/articles/async.html

    The article also has many links to other articles that address serial port programming.

  5. #5
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5
    Quote Originally Posted by dkloes
    Hi lucky001,

    There are many issues involved in working with serial ports. Serial port device files, such as /dev/ttyS0, are referred to as special files because they are not actual files. So, it is still not clear what you are trying to accomplish when you say you want to open and save this data file. Data that is communicated on a serial device can be read or written, but there are issues, such as flow control that you need to consider. Here is one source that I found that will help to explain some of the issues for interfacing with a serial port. As you will see from the article, there is much more to what you are trying to do than can be explained here simply.
    http://www.masoner.net/articles/async.html

    The article also has many links to other articles that address serial port programming.
    Thanks once again for your reply. Atleast there is someone who is kind to suggest.

    Anyways, In simple words, I need to transfer one file from one computer to another using serial port. Remember, both computers are connected using serial port.

    Any clue?

    Lucky

  6. #6
    Just Joined!
    Join Date
    Mar 2007
    Posts
    16
    Hi lucky001,

    There is no easy response or simple way to do this. You will need to read articles, such as the link to the one that I posted previously. The exact procedure will depend on how you intend to do this. /dev/ttyS0 is a character device, so once you have connected the file to the serial port on the Windows side, you will need to read the serial port on the Unix side. I can see where you opened the serial port via fd on the Unix side, but what have you done on the Windows side to connect the Windows file to the same port? Once that is done, you will need to read that port as per the considerations in the article.

  7. #7
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5
    Quote Originally Posted by dkloes
    Hi lucky001,

    There is no easy response or simple way to do this. You will need to read articles, such as the link to the one that I posted previously. The exact procedure will depend on how you intend to do this. /dev/ttyS0 is a character device, so once you have connected the file to the serial port on the Windows side, you will need to read the serial port on the Unix side. I can see where you opened the serial port via fd on the Unix side, but what have you done on the Windows side to connect the Windows file to the same port? Once that is done, you will need to read that port as per the considerations in the article.
    Ok - now I got some idea.

    It means I need to develop a client-server application (Client will be running on Windows and Server will be running on Unix) using socket?

    Is that what you said?

    Regards
    Lucky

  8. #8
    Just Joined!
    Join Date
    Mar 2007
    Posts
    16
    Hi lucky001,

    Yes, you will also need something on the Windows side to send the file to the serial port. Then, you can receive it on the Unix side. Factors involved will include the baud rate of the port and flow control. The link that I provided should give you the basics. In addition to using C, you could also get input from a serial port on the Unix side using the stty command and redirection. If it is just a matter of copying a Windows file to Unix (or Unix to Windows), you can use software, such as Samba and NFS.

  9. #9
    Just Joined!
    Join Date
    Mar 2007
    Posts
    5

    Thumbs up

    Quote Originally Posted by dkloes
    Hi lucky001,

    Yes, you will also need something on the Windows side to send the file to the serial port. Then, you can receive it on the Unix side. Factors involved will include the baud rate of the port and flow control. The link that I provided should give you the basics. In addition to using C, you could also get input from a serial port on the Unix side using the stty command and redirection. If it is just a matter of copying a Windows file to Unix (or Unix to Windows), you can use software, such as Samba and NFS.
    Thanks for all the help

    Regards
    Lucky

Posting Permissions

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