Serial communications - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Serial communications

XelaXela Posts: 3Member
[b][red]This message was edited by Xela at 2004-12-5 4:49:58[/red][/b][hr]
I need to write Pascal program which sends REAL numbers in any form (text, binary) to other computer running Windows using COM port.

[code]
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.
[/code]

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.


Comments

  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by Xela at 2004-12-5 4:49:58[/red][/b][hr]
    : I need to write Pascal program which sends REAL numbers in any form (text, binary) to other computer running Windows using COM port.
    :
    : [code]
    : 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.
    : [/code]
    :
    : 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.
  • XelaXela Posts: 3Member
    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?
  • zibadianzibadian Posts: 6,349Member
    : 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.
Sign In or Register to comment.