Signal to serial port - Programmers Heaven

Howdy, Stranger!

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

Categories

Signal to serial port

DanMoDanMo Posts: 2Member
Please help me to write a procedure in order to send a signal of low tension (5-15 Vcc) to RTS or DTR computer's serial port with 1 sec duration. I will use this signal to controll another device.
Thanks,
Dan ([email protected])

Comments

  • dj_sanniedj_sannie Posts: 92Member
    : Please help me to write a procedure in order to send a signal of low tension (5-15 Vcc) to RTS or DTR computer's serial port with 1 sec duration. I will use this signal to controll another device.
    : Thanks,
    : Dan ([email protected])
    :
    hi,

    i wont write all you're code :P but i can give u a class witch can use RTS en DTR of the serial port, just copy this code and save it as 'U_Comm.pas'
    [code]{ ****************************************************************************
    * *
    * File Name: U_Comm.pas *
    * *
    * This file gives u easy acces to the comm poorts of a pc. *
    * This file may only to be used for study or non profit project. *
    * In other cases contact the creator. *
    * *
    * (C) 2004 Sander Koopmans, *
    * The Netherlands. *
    * *
    * E-Mail [email protected] *
    * *
    **************************************************************************** }
    unit U_Comm;

    interface

    uses
    Windows;

    function CommOpen( COM: PChar ): Boolean;
    function CommClose(): Boolean;
    function CommGetHandleState(): Boolean;
    function CommGetHandle(): HWND;
    function CommSetDTR( Flag: Boolean ): Boolean;
    function CommSetRTS( Flag: Boolean ): Boolean;
    function CommGetCTS(): Boolean;

    implementation

    var
    ComHWND: HWND;
    ComOpen: Boolean;
    overlap: OVERLAPPED;

    function CommOpen( COM: PChar ): Boolean;
    begin
    if( not ComOpen )then
    begin
    ComHWND := CreateFile( COM,
    GENERIC_READ or GENERIC_WRITE,
    0,
    Nil,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    0);

    If ( ComHWND = INVALID_HANDLE_VALUE ) then
    begin
    ComHWND := 0;
    ComOpen := False;
    Result := False;
    end
    else
    begin
    ComOpen := True;
    Result := True;
    end;
    end
    else Result := False;
    end;

    function CommClose(): Boolean;
    begin
    if( ComOpen )then
    begin
    CloseHandle( ComHWND );
    Result := True;
    end
    else Result := False;
    end;

    function CommGetHandleState(): Boolean;
    begin
    result := ComOpen;
    end;

    function CommGetHandle(): HWND;
    begin
    result := ComHWND;
    end;

    function CommSetDTR( Flag: Boolean ): Boolean;
    begin
    if( ComOpen )then
    begin
    if( Flag )
    then Result := EscapeCommFunction( ComHWND, SETDTR )
    else Result := EscapeCommFunction( ComHWND, CLRDTR );
    end
    else Result := False;
    end;

    function CommSetRTS( Flag: Boolean ): Boolean;
    begin
    if( ComOpen )then
    begin
    if( Flag )
    then Result := EscapeCommFunction( ComHWND, SETRTS )
    else Result := EscapeCommFunction( ComHWND, CLRRTS );
    end
    else Result := False;
    end;

    function CommGetCTS(): Boolean;
    var
    CommMask: Cardinal;
    ErrorMask: Cardinal;
    begin
    if( ComOpen )then
    begin
    GetCommModemStatus( ComHWND, CommMask );
    if( CommMask and ms_cts_on <> 0 )
    then Result := True
    else Result := False;
    end;
    end;

    end.[/code]
    please don't be a jerk and leave this code as it is right now.
    if u want to make a signal with a duration of 1 sec just use the sleep command or use a TTimer it's you're choice.

    Greetz SRK.
Sign In or Register to comment.