NosferatuAlucard | Bonjour a tous.
je suis actuellement en BTS IG, en fin de première année. Je dois faire un programme qui fasse interface entre un pc portable et une carte ISA branché sur USB via un adaptateur USB/ISA.
Autant vous dire tout de suite que mon niveau en programmation n'est pas extraordinaire mais je veus comprendre.
Voila comment sa fonctionne. materiel >>
1 pc portable
1 pc de bureau
1 system de comptage
Sur le pc portable, il y a un logiciel, qui s'occupe du comptage (temps au tour pour des voitures, ...), sur le pc de bureau, un logiciel en pascal qui fait fonctionner le system de comptage brancher sur le port isa et renvoi les infos necessaire via le port com.
Voila comment il va falloir que sa fonctionne.
materiel >>
1 pc portable
1 adaptateur usb/isa
1 system de comptage.
Le logiciel de comtage tourne toujours sur l'ordinateur portable. en meme temps en lance mon petit programme (qui marche en dos pas plus) et qui initialise la carte isa (qui est dans son adaptateur USB/ISA) afin que le logiciel de comptage récupere les infos. au travers de l'usb.
je vais vous mettre le programme en pascal qui fonctionne actuellement.
Code :
- program Example;
- Uses
- Crt,
- Dos,
- Printer;
- type
- tableau_byte = array[1..256] of byte;
- const
- txt_amb = 'A M B T I M I N G H O L L A N D';
- Maxpnt = 10000; { Maximum number of entry's so maxlap pro car =Maxpnt/10 }
- MaxHit = 50; { maximum count of hits in 10mS }
- Ind_Hold = false;{ Hold flag }
- DelaySec = 2; { Delay time = 2 seconds }
- BitMap : array[0..15] of word =
- ($0001,$0002,$0004,$0008,
- $0010,$0020,$0040,$0080,
- $0100,$0200,$0400,$0800,
- $1000,$2000,$4000,$8000
- );
- Paddr1 = $170;
- Paddr2 = $190;
- Paddr3 = $1B0;
- Paddr4 = $1D0;
- Paddr5 = $1F0;
- irq3 = $08;
- irq4 = $10;
- irq5 = $20;
- irq6 = $40;
- irq7 = $80;
- masqirq3 = $F7;
- masqirq4 = $EF;
- masqirq5 = $DF;
- masqirq6 = $BF;
- masqirq7 = $7F;
- irq = irq3;
- masqirq = masqirq3;
- Paddr = Paddr3;
- com_port = 0;
- nbport=0;
- PortAdr = $3FE;
- type
- str1 = string[1];
- str2 = string[2];
- str4 = string[4];
- str8 = string[8];
- str11 = string[11];
- str13 = string[13];
- str15 = string[15];
- str80 = string[80];
- RegSet = record
- ax,bx,cx,dx,bp,si,di,ds,es,f: integer
- end;
- DelTabEntry = { This is the format for the delay tabel }
- record
- S,D : byte;
- Tpnt : integer;
- Zero : Boolean;
- Hold : Boolean;
- Hit : Byte;
- HitDel : Byte;
- end;
- TimTabEntry = { Used for storing the data from the interrupt }
- record
- Car : byte; { Car number (1-10) }
- H,M,S,D : byte; { Hous, Minutes, Seconds, 1/100 sec }
- Hit : byte; { Number of contacts with the transponder }
- end;
- TimTabarr = array[1..Maxpnt] of TimTabEntry;
- MainTabEntry =
- record
- laps,
- new_H, new_M, new_S, new_D,
- old_H, old_M, old_S, old_D,
- lap_H, lap_M, lap_S, lap_D : integer;
- Hit : integer; { hitcounter }
- Hitstr : str2;
- end;
- var
- ind_full : boolean; { buffer full }
- ind_beep : boolean; { Indicator beep on/off }
- ind_start : boolean; { Start indicator }
- ind_quit : boolean; { Stop indicator }
- etattrans : boolean;
- dummy,I : integer; { for start/stop timer }
- Inpstr : Str80;
- key : char; { input keyboard }
- HH,MM,SS,DD : byte; { main timer }
- Ipnt,Mpnt : integer; { pointers in timtab }
- TimTab :^TimTabarr;
- MainTab : array[1..10] of MainTabEntry;
- old_sec,old : byte; { for display_main }
- Bpcnt,oldmot : byte; { for beeper }
- Bpdel : byte; { for delay beeper }
- R : RegSet;
- DS_Save : integer absolute $0000:$01C7;
- InA, InB : byte;
- InData : integer;
- Dpnt : integer;
- DelTab : array[0..15] of DelTabEntry; { the delay tabel }
- d : byte;
- procedure rs_init;
- var
- regs : registers;
- begin
- regs.ah:=0;
- regs.dx:=nbport; {com1}
- regs.al:=$E3; {9600,1stop,7bits,aucun ctrl}
- intr($14,regs);
- end;
- procedure rs_write(data : byte);
- var
- regs : registers;
- begin
- regs.ah:=1;
- regs.dx:=nbport;
- regs.al:=data;
- intr($14,regs);
- if (regs.ah and 128)=128 then
- begin
- gotoxy(1,1);writeln('Erreur transmission');
- end;
- end;
- procedure envoi_carac(carac : char);
- begin
- rs_write(ord(carac));
- end;
- procedure envoicom(amb232:str15);
- var boucle,longueur : integer;
- lettre : char;
- begin
- if etattrans then
- begin
- gotoxy(1,20); writeln('WINARC a ouvert le port com');
- gotoxy(32,22);writeln(' ');
- gotoxy(1,22);writeln('envoi sur port comm : ',amb232);
- longueur := Length(amb232);
- for boucle:=1 to longueur do
- begin
- lettre := amb232[boucle];
- envoi_carac(lettre);
- end;
- end
- else
- begin
- gotoxy(1,20); writeln('WINARC a ferm le port com ');
- gotoxy(1,22);writeln(' ');
- end;
- end;
- procedure MyIntHandler;
- interrupt;
- begin
- InData := (Port[Paddr+6] shl 8) or Port[Paddr+4]; { This is the data from }
- for Dpnt:=9 downto 0 do { the 10 inputs }
- begin
- if Deltab[Dpnt].Hold then
- begin
- if DelTab[Dpnt].Zero then
- begin
- if ((InData and BitMap[Dpnt]) <> 0) and not ind_Hold then
- begin
- TimTab^[Ipnt].Car := Dpnt+1; { The main program gets it data }
- TimTab^[Ipnt].H := HH; { via the TimTab tabel }
- TimTab^[Ipnt].M := MM; { HH= Hours, MM= Minuts, }
- TimTab^[Ipnt].S := SS; { SS= sec, DD= 1/100 sec. }
- TimTab^[Ipnt].D := DD;
- DelTab[Dpnt].Hit := 0; { init hitcount }
- DelTab[Dpnt].Hitdel:= MaxHit; { maxhit = 500ms }
- DelTab[Dpnt].Tpnt := Ipnt; { remember ipnt }
- DelTab[Dpnt].Zero := false;
- DelTab[Dpnt].S := DELAYSEC;
- DelTab[Dpnt].D := 0;
- Bpcnt := Bpcnt+1;
- Ipnt := Ipnt + 1;
- If Ipnt >= Maxpnt then Ipnt:=1;
- end
- end
- else
- begin { DelTab[Dpnt].Zero false }
- if DelTab[Dpnt].D=0 then
- begin
- if DelTab[Dpnt].S=0 then DelTab[Dpnt].Zero := true else DelTab[Dpnt].S := DelTab[Dpnt].S - 1;
- DelTab[Dpnt].D := 99;
- end
- else DelTab[Dpnt].D := DelTab[Dpnt].D - 1;
- end;
- end;
- with DelTab[Dpnt] do
- begin
- if HitDel > 0 then { do this for Maxhit*10ms }
- begin
- HitDel := HitDel - 1; { this is the delay }
- if (Indata and BitMap[Dpnt]) <> 0 then
- begin { count hits only in when exist }
- Hit := Hit + 1;
- end;
- if HitDel=0 then TimTab^[Tpnt].Hit := Hit;
- end;
- end; { with DelTab[dpnt] }
- end;
- If (Bpcnt<>0) and (Bpdel=0) and ind_beep then
- begin
- Port[97]:=Port[97] or $03; {Beeper on}
- Bpdel:=20; {Beeper delay}
- Bpcnt:=Bpcnt-1;
- end;
- If Bpdel=7 then
- begin
- Port[97]:=Port[97] and $FC; {Beeper off}
- end;
- If Bpdel<>0 then Bpdel:=Bpdel-1; {beeper delay}
- DD:=DD+1;
- if DD>=100 then
- begin
- DD:=0; SS:=SS+1;
- if SS>=60 then
- begin
- SS:=0; MM:=MM+1;
- if MM>=60 then
- begin
- MM:=0; HH:=HH+1;
- if HH>=100 then HH:=0
- end
- end
- end;
- dummy:=Port[Paddr+4];
- Inline(
- $EC/ { in al,dx }
- $B0/$20/ { mov al,20h }
- $E6/$20 { out 20h,al }
- ); { End of inlinecode }
- end; { MyIntHandler }
- {******* end of interrupt handler *********}
- procedure start_timer; { start timer / interrupt handler }
- begin
- dummy := Port[Paddr+4]; { start interrupt }
- end; { start_timer }
- procedure stop_timer;
- begin
- dummy := Port[Paddr+7]; { stop interrupt }
- end; { stop_timer }
- procedure set_point; {save and set pointers interrupt handler}
- begin
- DS_Save := Dseg;
- R.ax := $250B;
- R.ds := Cseg;
- R.dx := Ofs(MyIntHandler);
- MsDos(Dos.Registers(R));
- Port[$21] := Port[$21] and masqirq;
- Port[Paddr+3]:= $34; { mode:count 0,2 byte load/read,mode2,NO BCD count }
- Port[Paddr+0]:= $20; { LSB first $4E20 = 20000, 20000*.5us=10ms }
- Port[Paddr+0]:= $4E; { MSB last, total 10 msec by clk = 2Mc }
- Port[$20] := $20;
- start_timer;
- stop_timer;
- end; { set_point }
- procedure restore_point; { restore pointers interrupt handler }
- begin
- Port[$21] := Port[$21] or irq;
- end; { restore_point }
- procedure conv2 (inp : integer ;var outp : str2);
- begin
- if inp > 99 then outp := '??'
- else
- begin
- if inp < 10 then
- begin
- str(inp:1,outp);
- outp := '0' + outp;
- end
- else
- begin
- str(inp:2,outp);
- end;
- end;
- end; {of conv2}
- procedure format_time(hf,mf,sf,df,sup : integer; var form : str11);
- var hulp : str2;
- tel : integer;
- begin { hh:mm:ss.dd }
- form := ''; { format time to 12:34:56.78 }
- conv2(hf,hulp);
- form := form + hulp + ':';
- conv2(mf,hulp);
- form := form + hulp + ':';
- conv2(sf,hulp);
- form := form + hulp + '.';
- conv2(df,hulp);
- form := form + hulp;
- tel := 1;
- while ((form[tel] = '0') or (form[tel] = ':')) and (tel < sup) do
- begin
- form[tel] := ' ';
- tel := tel + 1;
- end; { of while/do}
- end;
- procedure format_rs232(cf,hf,mf,sf,df,hitf: integer; var form : str15);
- var hulp : str2;
- begin { car hh:mm:ss.dd }
- form := '@'; { format time to @NNhhmmssdd}
- conv2(cf,hulp);
- form := form + hulp;
- conv2(hf,hulp);
- form := form + hulp;
- conv2(mf,hulp);
- form := form + hulp;
- conv2(sf,hulp);
- form := form + hulp;
- conv2(df,hulp);
- form := form + hulp;
- conv2(hitf,hulp);
- form := form +hulp+chr(13)+chr(10);
- end;
- procedure format_temps_rs232(hf,mf,sf: integer; var form : str15);
- var hulp : str2;
- begin { car hh:mm:ss.dd }
- form := '@00'; { format time to @NNhhmmssdd}
- conv2(hf,hulp);
- form := form + hulp;
- conv2(mf,hulp);
- form := form + hulp;
- conv2(sf,hulp);
- form := form +hulp+chr(13)+chr(10);
- end;
- procedure subtrct(var outp,inp1,inp2,carry:integer;max:integer);
- begin
- outp := inp1 - inp2 - carry;
- carry := 0;
- if outp < 0 then
- begin
- outp := max + outp;
- carry := 1;
- end;
- end; { subtrct }
- procedure Read_Rs232;
- var Portadrr :word;
- Stat : byte;
- Stat4 : byte;
- Stat5 : byte;
- mot : byte;
- begin
- stat:=(Port[PortAdr] and $F0);
- stat4:=(Stat and $10) div 16;
- stat5:=(Stat and $20) div 32;
- if old<>stat then
- begin
- mot:=stat4+stat5*2;
- { gotoxy(1,1); writeln(oldmot);
- gotoxy(1,2); writeln(mot);}
- if mot=3 then ind_start:=true;
- if (mot=3) and (oldmot<>0) then etattrans:=true else etattrans:=false;
- if ind_start then begin
- gotoxy(1,18); writeln('ordre de start donn ');
- end
- else begin
- gotoxy(1,18); writeln('plus d ordre de start');
- end;
- oldmot:=mot;
- old:=stat;
- end;
- end; { Read_Rs232 }
- procedure build_screen; { build standard screen-layout }
- var arr8 : array[1..8] of char;
- carstr : str2;
- begin
- gotoxy(70, 3); write(#$c9);
- gotoxy(79, 3); write(#$bb);
- gotoxy(70, 4); write(#$ba);
- gotoxy(79, 4); write(#$ba);
- gotoxy(70, 5); write(#$c8);
- gotoxy(79, 5); write(#$bc);
- gotoxy(75, 4); write(' ');
- FillChar(arr8,8,#$cd);
- gotoxy(71, 3); write(arr8);
- gotoxy(71, 5); write(arr8);
- gotoxy(10, 5); write(' Car Time Hits');
- gotoxy( 5, 1); write('AMB Carte --> AMB 232 <C> X.Wilfart');
- gotoxy( 5,25); write(txt_amb);
- end; { build_screen }
- procedure clk_zero;
- begin
- HH := 0; MM := 0; SS := 0; DD := 0; { Reset maintimer }
- old_sec := 99; { forc display timer }
- Gotoxy(71,4);write(' ');
- end; { clk_zero }
- procedure clear_buf; { clear all buffers, pointers etc.}
- var
- I : integer;
- begin
- Release(Heaporg);
- new(TimTab);
- clk_zero; { set main timer to zero }
- For I := 1 to 10 do
- begin
- with MainTab[I] do { Clear MainTab }
- begin
- Hitstr := ' ';
- Hit := 0;
- old_H := 0;
- old_M := 0;
- old_S := 0;
- old_D := 0;
- new_H := 0;
- new_M := 0;
- new_S := 0;
- new_D := 0;
- laps := 0;
- end;
- end;
- For I := 0 to 15 do
- begin
- with DelTab[I] do { Clear DelTab }
- begin
- S := 0;
- D := 0;
- Tpnt := 0;
- zero := true;
- hold := true;
- Hit := 0;
- HitDel := 0;
- end;
- end;
- Ipnt := 1;
- Mpnt := Ipnt;
- end; { clear_buf }
- procedure detect(car,det_H,det_M,det_S,det_D,det_Hit:integer);
- var
- telx,carry : integer;
- tmpnul : integer;
- begin
- tmpnul:=0;
- with maintab[car] do
- begin
- Hit := det_Hit;
- Str(det_Hit:2,HitStr);
- laps := laps + 1;
- If laps >= 10000 then laps := 0;
- old_H := new_H;
- old_M := new_M;
- old_S := new_S;
- old_D := new_D;
- new_H := det_H;
- new_M := det_M;
- new_S := det_S;
- new_D := det_D;
- carry := 0; { carry must be zero for the first call }
- subtrct(lap_D,new_D,old_D,carry,100); { lap_@:=new_@-old_@ }
- subtrct(lap_S,new_S,old_S,carry,60);
- subtrct(lap_M,new_M,old_M,carry,60);
- subtrct(lap_H,new_H,old_H,carry,100);
- end; { of with/do }
- end; { detect }
- procedure auto_detect(pointer:integer;var car:integer);
- begin { Info from TimTab-->MainTab }
- car := TimTab^[pointer].car;
- repeat until DelTab[car-1].HitDel=0; { wait for hit count }
- detect(car,TimTab^[pointer].H,TimTab^[pointer].M,TimTab^[pointer].S,TimTab^[pointer].D,TimTab^[pointer].Hit);
- end; {of auto_detect}
- procedure display_main; { Display maintimer on screen }
- var
- timstr : str11;
- timstr232 : str15;
- dispstr : str8;
- carstr : str2;
- begin
- If old_sec <> SS then
- begin
- old_sec := SS; { take new sec. }
- format_time(HH,MM,SS,DD,5,timstr); { 0:00 }
- format_temps_rs232(HH,MM,SS,timstr232);
- dispstr := Copy(timstr,1,8); { delete 1/100 sec. }
- Gotoxy (71,4); write(dispstr);
- envoicom(timstr232);
- end;
- end; { display_main }
- procedure Disp_dat(I:Integer);
- var dispstr : string[80];
- spltimstr : str11;
- spltimstr232 : str15;
- laptimstr : str11;
- carstr : str2;
- lapstr : str4;
- begin
- with MainTab[I] do
- begin
- str(I:2,carstr);
- format_time(new_H,new_M,new_S,new_D,8,spltimstr); { 0.00 }
- format_rs232(I,new_H,new_M,new_S,new_D,Hit,spltimstr232);
- format_time(lap_H,lap_M,lap_S,lap_D,8,laptimstr);
- laptimstr := Copy(laptimstr,5,7);
- Str(Laps:4,Lapstr);
- dispstr := Carstr + ' >> ' + spltimstr + ' ' + HitStr;
- Gotoxy(10,I+6); write(dispstr);
- envoicom(spltimstr232);
- end;
- end; {of Disp_dat}
- procedure process; { processing the inputs }
- var ind_display : boolean;
- car,lecture : integer;
- begin
- repeat
- display_main;
- if (ipnt <> mpnt) then { ipnt <> mpnt when car in TimTab buffer }
- begin
- auto_detect(mpnt,car);
- Disp_Dat(car);
- mpnt := mpnt+1;
- If mpnt >= Maxpnt then { Attention buffer overflow }
- begin
- gotoxy(1,10);
- clreol;
- write(' B U F F E R F U L L');
- end;
- end;
- if ind_start then
- begin
- stop_timer;
- clrscr;
- rs_init;
- build_screen;
- clear_buf;
- ind_start := false;
- start_timer;
- end;
- read_rs232;
- until ind_quit;
- end;
- var lecture : integer;
- begin
- clrscr;
- rs_init;
- build_screen;
- ind_start := false;
- ind_quit:=false;
- oldmot:=0;
- old:=0;
- clear_buf;
- restore_point;
- set_point;
- stop_timer; { stop existing interrupts }
- repeat
- process;
- until ind_quit;
- stop_timer;
- restore_point;
- clrscr;
- nosound;
- end.
|
Donc ici sa fonctionne avec un pc en plus et les infos son transmise par port com1. Au final, sa doit fonctionner juste avec l'adaptateur USB/ISA.
Les personnes souhaitant m'aider, sont les biens venu, parce que j'en ai besoin.
Comme dit plus haut, je suis débutant, et si il manque des infos je serais ravi des vous les données.
Encore merci a tous |