Link to home
Start Free TrialLog in
Avatar of karelin
karelin

asked on

com and lpt

how do i send signals to lpt and com???
without assembler code please!

Avatar of lordxeroth
lordxeroth

I supose you mean writing data to the peripherals?
this can be done with PORT
Sorry as far as my hardware knowledge is concerned it cannot be done using pascal std library function.  you have to go for Assembly.
Sorry as far as my hardware knowledge is concerned it cannot be done using pascal std library function.  you have to go for Assembly.
Avatar of karelin

ASKER

And an example please!
define "send signal" please. If in DOS, write characters to them is just open the port and WRITE...
Try:

Uses Dos,crt;
var s:text;
begin
assign(s,PRN); {PRINTER PORT}
reset(s);
write(s,'What?');
close(s);

assign(s,COM1); {COM PORT 1}
reset(s);
write(s,'Huh?');
close(s);

end;
Do you wanna know how to control an external device, like a stepper motor???, 'cos if so, then the parallel port is the best thing to use rather than the serial... if so let us (See that i use the "US" and not "ME") know... :P
(*  This Proggy shows how to send data bits to the parallel port, in this
Example we are going to connect 8 LEDs (Light Emission Diode) with a resistor
to each bit of the LPT port, Like in the draw

 D0 ----\/\/\-->|--o Ground
              o       R0         Led1       R0 .. R7 = 220 Ohms.
              o                                    8 Red LEDs.
              o       R7         Led8       Cable
 D7 ----\/\/\-->|--o Ground
*)

Program TestLPT;
USES
  CRT,DOS;
CONST
  Min = 0;
  Max = 32;
  Data: Array[Min..Max] Of Byte =
  (0,1,3,7,15,31,63,127,255,254,252,248,240,224,192,128,0,
   128,192,224,240,248,252,254,255,127,63,31,15,7,3,1,0);
TYPE
  CadBin = String[8];
VAR
  C: Char;
  OutPut: Word;
  Secuence: CadBin;
  Time,I,J: Integer;

Procedure OutPutPort(Data: Word); Assembler;
ASM
(*MOV    DX,$3BC*)
  MOV    DX,$378
  MOV    AX,Data
  OUT    DX,AL
End;

Function Binary(B: Byte): CadBin;
VAR
  I: Integer;
  BT: Byte;
  Cad: CadBin;
Begin
  BT:=$01;
  Cad:='';
  For I:=1 To 8 Do
    Begin
      If (B And BT) > 0 Then
        Cad:=#02+Cad
      Else
        Cad:=#01+Cad;
      {$R-} BT:=BT ShL 1 {$R+}
    End;
  Binary:=Cad
End;

Begin
  ClrScr;
  Time:=50;
  I:=0;
  Repeat
    OutPut:=Data[I];
    OutPutPort(OutPut);
    GotoXY(35,12);
    Secuence:=Binary(Lo(OutPut));
    For J:=1 To 8 Do
      Begin
        If Secuence[J] = #02 Then
          Begin
            TextColor(15); WRITE(Secuence[J]);
          End
        Else
          Begin
            TextColor(8); WRITE(Secuence[J]);
          End;
        If KeyPressed Then
          C:=ReadKey
      End;
    TextColor(7);
    Write('  ',OutPut:4);
    Delay(Time);
    If I = Max Then
      I:=Min
    Else
      Inc(I);
    If C = #72 Then If Time < 300 Then INC(Time,10);
    If C = #80 Then If Time > 30 Then DEC(Time,10)
  Until C = #27;
  OutPutPort(0);
  WriteLn
End.
Hi Karelin,

do you want to control a printer via LPT, a modem via COM etc., or do you want to control some own electronics connected to your PC ports?

Regards,
Hamilton
What pascal compiler do you use? If you are using BP7 you can access ports using PORT[<port address>]. If such a thing is not supported by your compiler you can't do it without assembler.
ex:
A=PORT[$278] {read for lpt port (lpt is at address 278)}
PORT[$278]=A {write to the port}

it is possible that the syntax is slightly different, but I'll look it up this weekend
Also you need to know what registers you need to access of the lpt or com (depended on what you want to do with it). This information can be easily found on the internet, or I could send it to you.
>>Sorry as far as my hardware knowledge is concerned it
>>cannot be done using pascal std library function.  you
>>have to go for Assembly.

Not at all; you can write an interrupt routine to intercept chars when arriving at COM port, without writing a single asm instruction. Of course, it's *NOT* an easy task, 'cause you have to deal with the PIC (Programmed Interrupt Controller), but IT IS possible (in fact, I've done it).

To use LPT port, if you only intend to write, just do:

     Assign(text_file_var , 'PRN');
     Writeln(text_file_var, <whatever>);
>>>>Sorry as far as my hardware knowledge...

Cool down there vikiing, Mr. nadt here, was only stating the true and only the true "AS FAR AS HIS HARDWARE KNOWLEDGE"...

But you're right there, it's not an easy task, when dealing with COMs communications...
ASKER CERTIFIED SOLUTION
Avatar of unclebilly
unclebilly

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>Cool down there vikiing

Hey, my friend !!!, I'm not out of control in any way  :)
My friends, this is PASCAL, not Delphi. I asume working in a non Win95/98/NT envirement, just plain DOS.
You don't do windows stuff in Pascal, use Delphi for that.
Hahahaaaa, thanx whatboy :)
It seems our dear Karelin is not with us anymore, lets say a prayer to the allmighty Borland to enlighten his paths.

Karelin: I would suggest to learn assembly. It's easier to do things like this and assembly is not that hard as it seems.
Avatar of karelin

ASKER

Thanks!