bon voila jai fais une classe en c++ .NET et je desire en faire une dll mais bon voila il y a plein de probleme que j'ai du mal à saisir...
// dll.h
#pragma
once
#include <stdio.h>
#include <stdlib.h>
#include "Windows.h"
#include "Winbase.h"
using
namespace System;
namespace dll
{
public
__gc
class liaison
{
private:
static COMMTIMEOUTS *Timeout=
new COMMTIMEOUTS(
/*sizeof(COMMTIMEOUTS)*/);
//char port[5];
int parite;
int bitstop;
HANDLE h_com;
static DCB *ladcb=
new DCB(
/*sizeof( DCB)*/);
int i;
private:
//envoi ok//
int envoi(
unsigned
char* command)
{
DWORD nboce;
int retour;
retour=WriteFile(
this->h_com,command,11,&nboce,NULL);
if((retour==0) || (nboce<=0))
{
return 0;
}
char* bc=(
char*)malloc(100);
return
this->reponse_lecteur(bc);
}
//param ok//
int param()
{
int debit;
int tab[8];
tab[0]=300;
tab[1]=600;
tab[2]=1200;
tab[3]=2400;
tab[4]=4800;
tab[5]=9600;
tab[6]=19200;
tab[7]=38400;
int tab1[9][2];
tab1[0][0]=1;
tab1[0][1]=2;
tab1[1][0]=1;
tab1[1][1]=0;
tab1[2][0]=1;
tab1[2][1]=1;
tab1[3][0]=1;
tab1[3][1]=3;
tab1[4][0]=1;
tab1[4][1]=4;
tab1[5][0]=2;
tab1[5][1]=2;
tab1[6][0]=2;
tab1[6][1]=0;
tab1[7][0]=2;
tab1[7][1]=1;
tab1[8][0]=2;
tab1[8][1]=3;
for(
int i=0;i<8;i++)
{
debit=tab[i];
for(
int y=0;y<9;y++)
{
parite=tab1[y][1];
bitstop=tab1[y][0];
if(!GetCommState(h_com,ladcb))
{
CloseHandle(h_com);
return 0;
}
if(debit==300)
ladcb->BaudRate=CBR_300;
if(debit==600)
ladcb->BaudRate=CBR_600;
if(debit==1200)
ladcb->BaudRate=CBR_1200;
if(debit==2400)
ladcb->BaudRate=CBR_2400;
if(debit==4800)
ladcb->BaudRate=CBR_4800;
if(debit==9600)
ladcb->BaudRate=CBR_9600;
if(debit==19200)
ladcb->BaudRate=CBR_19200;
if(debit==38400)
ladcb->BaudRate=CBR_38400;
if(parite==0)
ladcb->Parity=NOPARITY;
if(parite==2)
ladcb->Parity=EVENPARITY;
if(parite==1)
ladcb->Parity=ODDPARITY;
if(parite==3)
ladcb->Parity=MARKPARITY;
if(parite==4)
ladcb->Parity=SPACEPARITY;
if(bitstop==1)
ladcb->StopBits=ONESTOPBIT;
if(bitstop==3)
ladcb->StopBits=ONE5STOPBITS;
if(bitstop==2)
ladcb->StopBits=TWOSTOPBITS;
if(!SetCommState(h_com,ladcb))
{
CloseHandle(h_com);
return 0;
}
Timeout->ReadTotalTimeoutConstant=500;
if(!SetCommTimeouts(h_com,Timeout))
{
CloseHandle(h_com);
return 0;
}
unsigned
char command[11];
command[0]=0x16;
command[1]=0x4D;
command[2]=0x0D;
command[3]=0x32;
command[4]=0x33;
command[5]=0x32;
command[6]=0x42;
command[7]=0x41;
command[8]=0x44;
command[9]=0x3F;
command[10]=0x2E;
if(
this->envoi(command)!=0)
{
return 1;
}
}
}
return 0;
}
//recherche ok//
int recherche()
{
char port[5];
port[0]='C';
port[1]='O';
port[2]='M';
port[3]=(
char)i;
port[4]='\0';
h_com=CreateFile(port,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(h_com == INVALID_HANDLE_VALUE)
{
CloseHandle(h_com);
return 0;
}
return
this->param();
}
public:
liaison(){}
//connection ok//
int connection()
{
unsigned
char tab[5]={0x31,0x32,0x33,0x34};
for(i=0;i<5;i++)
{
/*port[0]='C';
port[1]='O';
port[2]='M';
port[3]=tab[i];
port[4]='\0';*/
if(
this->recherche()!=0)
{
return 1;
}
else
this->deconnexion();
}
i=0;
return 0;
}
//Modifier_TimeOut ok//
int Modifier_TimeOut(
int seconde)
{
Timeout->ReadTotalTimeoutConstant=(1000*seconde);
if(!SetCommTimeouts(h_com,Timeout))
{
CloseHandle(h_com);
return 0;
}
return 1;
}
//reponse_lecteur ok voir temps du sleep//
int reponse_lecteur(
char* CB1)
{
Sleep(200);
DWORD nb;
if(!ReadFile(h_com,CB1,100,&nb,NULL))
return 0;
CB1[nb]='\0';
if(nb==0)
return 0;
else
return nb;
}
//volume ok
int volume(
int volume)
{
unsigned
char command[11];
command[0]=0x16;
command[1]=0x4D;
command[2]=0x0D;
command[3]=0x42;
command[4]=0x45;
command[5]=0x50;
command[6]=0x4C;
command[7]=0x56;
command[8]=0x4C;
if(volume==0)
command[9]=0x30;
if(volume==1)
command[9]=0x31;
if(volume==2)
command[9]=0x32;
if(volume==3)
command[9]=0x33;
command[10]=0x2E;
return
this->envoi(command);
}
//trigger mode ok//
int trigger_mode(
int trigger)
{
unsigned
char command[11];
command[0]=0x16;
command[1]=0x4D;
command[2]=0x0D;
command[3]=0x54;
command[4]=0x52;
command[5]=0x47;
command[6]=0x4D;
command[7]=0x4F;
command[8]=0x44;
if(trigger==0)
command[9]=0x30;
if(trigger==1)
command[9]=0x31;
command[10]=0x2E;
return
this->envoi(command);
}
//a voir//
int baud_rate(
int rate)
{
unsigned
char command[11];
command[0]=0x16;
command[1]=0x4D;
command[2]=0x0D;
command[3]=0x32;
command[4]=0x33;
command[5]=0x32;
command[6]=0x42;
command[7]=0x41;
command[8]=0x44;
if(rate==300)
command[9]=0x30;
if(rate==600)
command[9]=0x31;
if(rate==1200)
command[9]=0x32;
if(rate==2400)
command[9]=0x33;
if(rate==4800)
command[9]=0x34;
if(rate==9600)
command[9]=0x35;
if(rate==19200)
command[9]=0x36;
if(rate==38400)
command[9]=0x37;
command[10]=0x2E;
if(
this->envoi(command)==0)
return 0;
if(
this->param()==0)
return 0;
return 1;
}
//word_length
int word_length(
int value)
{
unsigned
char command[11];
command[0]=0x16;
command[1]=0x4D;
command[2]=0x0D;
command[3]=0x32;
command[4]=0x33;
command[5]=0x32;
command[6]=0x57;
command[7]=0x52;
command[8]=0x44;
if(value==1)
command[9]=0x33;
if(value==2)
command[9]=0x30;
if(value==3)
command[9]=0x36;
if(value==4)
{
command[9]=0x31;
command[10]=0x32;
}
if(value==5)
command[9]=0x39;
if(value==6)
command[9]=0x34;
if(value==7)
command[9]=0x31;
if(value==8)
command[9]=0x37;
if(value==9)
{
command[9]=0x31;
command[9]=0x33;
}
if(value==10)
{
command[9]=0x31;
command[10]=0x30;
}
if(value!=10 || value!=9 || value!=4)
command[10]=0x2E;
else
command[11]=0x2E;
if(
this->envoi(command)==0)
return 0;
if(
this->param()==0)
return 0;
return 1;
}
//deconnexion ok//
void deconnexion()
{
CloseHandle(h_com);
}
};
}
Afficher la suite