Thread: Using COM Ports to send files between two PCs

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    9

    Using COM Ports to send files between two PCs

    Hi, this my first time programming sth in Network. I do not have many ideas about this and since I do not have much time left, and I didn't understand well, I should seek your help.I have to use C to send a file to another PC, well COM port are useful but I didn't find how to refer to the adress of my destination. If someone explains it to me or giveme useful links.

  2. #2
    Registered User
    Join Date
    Oct 2014
    Posts
    9
    I found this C / C++ / C++.NET : Base communication série rs232 (win32) - CodeS SourceS, but I dont know how to use it to send files; if we could use socket it was gonna be great but it is mentionned not to.

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    There are old MSDOS programs like XMODEM, that transfer files over a serial port (to modem to modem) to a serial port. Perhaps you can find information on the protocol that XMODEM uses.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by PrinceDamon View Post
    I found this C / C++ / C++.NET : Base communication série rs232 (win32) - CodeS SourceS, but I dont know how to use it to send files; if we could use socket it was gonna be great but it is mentionned not to.
    You'd use Windows communications functions like:
    Code:
    CreateFile()   /* opens the com port */
    ReadFile()     /* reads from the com port */
    WriteFile()    /* writes to the com port */
    CloseHandle()  /* closes the com port */
    And here is a site I found by Google'ing.

  5. #5
    Registered User
    Join Date
    Oct 2014
    Posts
    9
    Hi everybody, this project was really intersting since I learned hiw COM ports work, but unfortunetely I couldn't finish it because I started it very late.
    The document https://www.google.dz/url?sa=t&rct=j...82001339,d.ZWU explains well how DATA is sent. Once this is understood, the rest is easy.
    This code is the non connected transmission through COM ports. There is a program that helps test in PC that do not have COM ports by creating virtual ones("Configure Virtual Serial Port Driver").
    Code:
    /********************************************************
     * Transmission without controle nor restart if errors *
     *************************************Non connected **/
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <stdint.h>
    #include "Headers.h"
    /******************************************************************************
      send : prepares the info , then send it.
      entry : adr_src         : source address.
                 adr_dest        : destination address.
                 msg              :DATA to sent.
                 lg_msg          :size of msg.
    ******************************************************************************/
    void send(char* adr_src,char* adr_dest,char* msg,int lg_msg){
        int i;
        TRAME trame;//char Buf[100];
    
    
        sprintf(trame.Info,"%s",msg);
        for(i=0;i<6;i++) {
          trame.adr_dst[i]=adr_dest[i];
          trame.adr_src[i]=adr_src[i];}
          trame.lg_info=lg_msg;
          trame.Ctrl=TRANSFERT_DATA;
          trame.deb_trame=DEBUT_TRAME;
          trame.fin_trame=FIN_TRAME;
          trame.num_seq=num_seq;
          trame.Fcs=generer_controle(trame);
          vers_canal(&trame,sizeof(TRAME));
    }
    /******************************************************************************
      receive : reçeives the info.
      entry : adr_src         : source address.
                 adr_dest        : destination address.
                 msg              :DATA to sent.
      returns : size of msg received.
    ******************************************************************************/
    int receive(char* adr_src, char* adr_dest, char* msg){
        int i;
        TRAME trame;//char Buf[100];
    
    
        if(de_canal(&trame,sizeof(TRAME))){
            //Construire_Trame_Reception(trame,Buf);
            sprintf(msg,"%s",trame.Info);
    
    
            for(i=0;i<6;i++) {
                if(trame.adr_src[i]!=adr_src[i]){
                    printf("\ntrame recu d'une source differante (");
                    for(i=0;i<5;i++) printf("%x:",trame.adr_src[i]);
                    printf("%x)\n",trame.adr_src[5]);
                    break;
                }
            }
            for(i=0;i<6;i++) {
                if(trame.adr_dst[i]!=adr_dest[i]){
                    printf("\ntrame recu pour un destinataire differant (");
                    for(i=0;i<5;i++) printf("%x:",trame.adr_dst[i]);
                    printf("%x)\n",trame.adr_dst[5]);
                    break;
                }
            }
        }
        else msg="";
        return trame.lg_info;
    }
    /******************************************************************************/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. best way to send files over socket
    By Annonymous in forum Networking/Device Communication
    Replies: 6
    Last Post: 11-14-2011, 02:40 PM
  2. Using C to send files between 2 Com Ports.
    By Dearster in forum C Programming
    Replies: 4
    Last Post: 11-15-2009, 04:25 PM
  3. Send files from one computer to another
    By arjunajay in forum Windows Programming
    Replies: 2
    Last Post: 03-27-2009, 11:30 PM
  4. Help please: Using I/O to Send Compiled Files
    By Hatchet in forum C++ Programming
    Replies: 5
    Last Post: 04-03-2007, 02:39 PM
  5. How do you send and recieve info from serial ports?
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2002, 12:13 PM