Announcement

Collapse
No announcement yet.

Sending serial data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sending serial data

    Hi, I'm currently trying to send data to the MatchPort Pro from a PC by a serial cable. I found a program on the internet that is supposed to send data by the COM1 connector of the PC. But it doesn't work, the MatchPort leaves no trace of any active connection in Tunnel 1. This is the program i'm using :

    Code:
    /**Programme de test liaison s?rie RS232*/
    #include <iostream.h>
    #include <iomanip.h>
    #include <windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    int initSerial();
    int sendSerial(char *Chaine, char *EolChar);
    
    char chaine[100];
    
    
    
    /**Initialisation du port s?rie*/
    int initSerial()
    {
        DCB dcb;                //Configuration du port
        HANDLE handleSerial;    //D?claration handle
        DWORD dwError;          //n? de l?erreur
        BOOL fSuccess;          //Succ?s de l'op?ration
    
    
    //Ouverture du port de communication
        handleSerial=CreateFile("COM1",GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
    
    
    //V?rification de l'ouverture du handle
        if (handleSerial==INVALID_HANDLE_VALUE)
        {
            dwError=GetLastError();
        }
    
    
    //Lecture configuration initiale
        fSuccess = GetCommState(handleSerial, &dcb);
        if (!fSuccess)
        {
            printf("Erreur\n");
        }
    
    
    //Configuration du port
    //Gestion de la vitesse
        dcb.BaudRate=CBR_9600;
    //Gestion du nombre de bits
        dcb.ByteSize=8;
    //Gestion de la parit?
        dcb.Parity=EVENPARITY;
    
    
    //Gestion du Stop Bit
        dcb.StopBits=ONESTOPBIT;
    
    
        dcb.DCBlength=2048;
        dcb.fBinary=1;
        dcb.fParity=1;
        dcb.fOutxCtsFlow=0;
        dcb.fOutxDsrFlow=0;
        dcb.fDtrControl=0;
        dcb.fDsrSensitivity=0;
        dcb.fTXContinueOnXoff=0;
        dcb.fRtsControl=0;
    
        fSuccess=SetCommState(handleSerial, &dcb);
        if (!fSuccess)
        {
            printf("Erreur\n");
        }
    
    
    //Fermeture du port
        CloseHandle(handleSerial);
        return(fSuccess);
    }
    
    
    
    
    /**Ecriture sur le port s?rie*/
    int sendSerial(char *chaine, char *EolChar)
    {
        HANDLE handleSerial;
        DWORD dwError;
        BOOL fSuccess;
        DWORD dwEvtMask;
        unsigned long nBytesWrite;
    
    
    //Ouverture du port de communication
        handleSerial=CreateFile("COM1",GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
    
    
    //Ecriture dans le fichier
        printf("Envoi chaine : %s\n",chaine);
        WriteFile(handleSerial,chaine,sizeof(chaine),&nBytesWrite,NULL);
    
    //Fermeture du handle de communication
        CloseHandle(handleSerial);
    
    //Lib?ration m?moire
        delete chaine;
        return(fSuccess);
    }
    
    
    
    /**Programme principal*/
    int main(void)
    {
        int checkInit;
        char *TrameRecue;
        TrameRecue=new char[200];
        checkInit=initSerial();
        if(checkInit!=0)
        {
        //Envoi de la chaine test
            char mes[100];
            printf("Saisie chaine :\n");
            gets(mes);
            sendSerial(mes, "end");
        }
        else
        {
        printf("Erreur\n");
        }
    
    // Lib?ration m?moire
        delete[] TrameRecue ;
        printf("Fin\n");
    }
    Sorry, comments are in French. Does anyone understand why it doesn't work?
Working...
X