Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Serial communications Posted by Xela on 5 Dec 2004 at 4:49 AM
This message was edited by Xela at 2004-12-5 4:49:58

I need to write Pascal program which sends REAL numbers in any form (text, binary) to other computer running Windows using COM port.

Program COM;

 uses DOS;

 const filename='com1';

 const bd110 = 0;
       bd150 = 1;
       bd300 = 2;
       bd600 = 3;
       bd1200 = 4;
       bd2400 = 5;
       bd4800 = 6;
       bd9600 = 7;

       pNone = 0;
       pOdd = 1;
       pEven = 3;

       sI = 0;
       sII = 1;

       b7 = 2;
       b8 = 3;

       com1 = 0;
       com2 = 1;
       com3 = 2;
       com4 = 3;

  var R: Registers;
      OperationResult: Word;

PROCEDURE WRITE_DATA(V2,TIME_IS,V,V1,V4,V5:REAL);
  VAR
     results: text;
  BEGIN;
    assign (results, filename);
    append(results);
    writeln(results,V,' ',TIME_IS,'  ',V2,'  ',V1,' ',V4,' ',V5);
    close(results);
  END;

 procedure Initialize (Port: Byte; Szybkosc: Byte; Parzystosc: Byte; Stop: Byte; Dlugosc: Byte);
 begin
  R.AH:=0;
  R.AL:=Dlugosc+Stop*4+Parzystosc*8+Szybkosc*32;
  R.DX:=Port;
  Intr ($14,R);
  OperationResult:=R.AX;
 end;

begin
 Initialize (com1,bd9600,pNone,sI,b8);
 Write_Data (1,2,3,4,5,6);
end.


It doesn't work, giving:
Error 160: Device write fault

on the line:
writeln(results,V,' ',TIME_IS,' ',V2,' ',V1,' ',V4,' ',V5);

To test this program I run it on the computer with two COM ports connected with null-modem. Pascal program sends data to COM1, and WinXP Hyper Terminal is connected to COM2. Hyper Terminal connection parameters are:

Bits per second - 9600
Data bits - 8
Parity - None
Stop bits - 1
Flow control - Hardware

Is there some problem in this code? Maybe I can use some other code for serial communication, any working sample. Thanks.


Report
Re: Serial communications Posted by zibadian on 5 Dec 2004 at 9:10 AM
: This message was edited by Xela at 2004-12-5 4:49:58

: I need to write Pascal program which sends REAL numbers in any form (text, binary) to other computer running Windows using COM port.
:
:
: Program COM;
: 
:  uses DOS;
: 
:  const filename='com1';
: 
:  const bd110 = 0;
:        bd150 = 1;
:        bd300 = 2;
:        bd600 = 3;
:        bd1200 = 4;
:        bd2400 = 5;
:        bd4800 = 6;
:        bd9600 = 7;
: 
:        pNone = 0;
:        pOdd = 1;
:        pEven = 3;
: 
:        sI = 0;
:        sII = 1;
: 
:        b7 = 2;
:        b8 = 3;
: 
:        com1 = 0;
:        com2 = 1;
:        com3 = 2;
:        com4 = 3;
: 
:   var R: Registers;
:       OperationResult: Word;
: 
: PROCEDURE WRITE_DATA(V2,TIME_IS,V,V1,V4,V5:REAL);
:   VAR
:      results: text;
:   BEGIN;
:     assign (results, filename);
:     append(results);
:     writeln(results,V,' ',TIME_IS,'  ',V2,'  ',V1,' ',V4,' ',V5);
:     close(results);
:   END;
: 
:  procedure Initialize (Port: Byte; Szybkosc: Byte; Parzystosc: Byte; Stop: Byte; Dlugosc: Byte);
:  begin
:   R.AH:=0;
:   R.AL:=Dlugosc+Stop*4+Parzystosc*8+Szybkosc*32;
:   R.DX:=Port;
:   Intr ($14,R);
:   OperationResult:=R.AX;
:  end;
: 
: begin
:  Initialize (com1,bd9600,pNone,sI,b8);
:  Write_Data (1,2,3,4,5,6);
: end.
: 

:
: It doesn't work, giving:
: Error 160: Device write fault
:
: on the line:
: writeln(results,V,' ',TIME_IS,' ',V2,' ',V1,' ',V4,' ',V5);
:
: To test this program I run it on the computer with two COM ports connected with null-modem. Pascal program sends data to COM1, and WinXP Hyper Terminal is connected to COM2. Hyper Terminal connection parameters are:
:
: Bits per second - 9600
: Data bits - 8
: Parity - None
: Stop bits - 1
: Flow control - Hardware
:
: Is there some problem in this code? Maybe I can use some other code for serial communication, any working sample. Thanks.
:
:
:
It could be that you can only write to the COM using untyped files and not text or typed files. You should try that for starters. Otherwise, it could be that your COM1 is broken, or is blocked by the OS on which the pascal program runs.
Report
Re: Serial communications Posted by Xela on 6 Dec 2004 at 12:49 AM
Thanks. COM port is OK, it is tested and working with other programs.
>> It could be that you can only write to the COM using untyped files and not text or typed files.
Can you show me some code or link to Pascal RS232 serial communications sample?
Report
Re: Serial communications Posted by zibadian on 6 Dec 2004 at 1:04 AM
: Thanks. COM port is OK, it is tested and working with other programs.
: >> It could be that you can only write to the COM using untyped files and not text or typed files.
: Can you show me some code or link to Pascal RS232 serial communications sample?
:
No, sorry, but you can alway google for the code.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.