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;
}
/******************************************************************************/