⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pascal_comm.htm

📁 pascal写的一个通讯例子
💻 HTM
字号:
<!-- Copyright 1996 Reginald Group. All rights reserved. 	-->
<!-- Created by Orel Software, 1996 v.0.3 			-->
<HTML>
<HEAD>
  <TITLE>Pascal Source Code Sample</TITLE>
</HEAD>
<BODY BGCOLOR=#F0F0F0>
<H4>
  <CENTER>
    <FONT COLOR=A03000> Orel Software: Custom Software Programming</FONT>
  </CENTER>
</H4>
<H3>
  <CENTER>
    <FONT COLOR=A03000> Pascal Source Code Sample</FONT>
  </CENTER>
</H3>
<P>
<A HREF="s_hist.htm"><IMG SRC="ret_butt.gif" ALIGN=MIDDLE> Return to Track
Record Bits page</A>. 
<P>
<BR>
<A HREF="index.htm"><IMG SRC="orel.gif" ALIGN=MIDDLE> Return to Orel Software
home page</A>.
<PRE>
/**
*  Name         HNGUP_MD -- Hang up the phone.
*
*  Synopsis     state = hngup_md(pmodem,percode);
*               int    state      The operation state
*               MODEM  *pmodem    The modem descriptor
*               int    *percode   Returned status error code.
*
*  Description  This function terminates a carrier linkage (hangs up the
*               phone).  This is accomplished by simply inhibiting DTR
*               to put the modem into its comatose state.  If DTR is not
*               supported, the function calls gocmd_md to force the modem
*               into command mode, then issues the hangup command (H0).
*
*  Returns
*               state           The current operation state:
*                                   0 - done;
*                                   1 - not yet.
*               ercode            The possible values are:
*                                   0 - No errors encountered.
*                                   2 - Invalid port number.
*                                   3 - Port not open.
*                                   7 - Output queue full.
*                                 100 - Modem control structure has not
*                                       been initialized.
*                                 102 - Modem does not respond.
*
*  Version      4.10 (C)Copyright Blaise Computing Inc.  1995
*
**/

#include <asynch_m.h>

#define WAITABIT (200L / B_MS_PER_TICK)

int hngup_md(PMODEM pmodem,
          int _FAR* percode)
{
    char resp [RESPSTR_LEN];
    int  resp_code, dcdstat;

    CHECK_MD(pmodem,"HNGUP_MD",*percode);
    MPUSH;

    switch (CURRENT_MSTATE)
    {
        case H_INIT:
                                           /* Pull DTR low             */
        utclrdtr(pmodem-&gt;port_no);
        new_mstate("HNGUP_MD", pmodem, H_PAUSING1);

        case H_PAUSING1:
            if (!TIMED_OUT(pmodem-&gt;start_time, WAITABIT))
                MCONTINUE;              /* Wait a bit                  */
                                        /* Push DTR high               */
            utsetdtr(pmodem-&gt;port_no);
                                        /* Then check for DCD          */
            if((*percode = isdcd_md(pmodem, &amp;dcdstat)) != M_OK)
                break;

            new_mstate("HNGUP_MD", pmodem,
                       dcdstat ? H_GOCOMMAND : H_HANGINGUP);
                MCONTINUE;

                                        /* Carrier still up, so force  */
                                        /* command mode and hang up.   */
        case H_GOCOMMAND:
            if (gocmd_md(pmodem,&amp;resp_code,percode))
                MCONTINUE
            else if (*percode != A_OK)
                break;
            else
                new_mstate("HNGUP_MD", pmodem, H_HANGINGUP);

        case H_HANGINGUP:
            if (query_md(pmodem, HO_BARREN,
                         pmodem-&gt;hangup, resp, &amp;resp_code, percode))
                MCONTINUE;

        default:     /* No meaningful function state. Reset and retry. */
            prep_md(pmodem);
            new_mstate("HNGUP_MD", pmodem, H_INIT);
    }

    LOGERCODE("HNGUP_MD", *percode);
    MFINISH;
}
/**
*  Name         FMOVE_FT -- Send/receive file(s) using
*                               ASCII/XMODEM/YMODEM/ZMODEM/Kermit
*
*  Synopsis     ercode = fmove_ft(FTCS      *pft,
*                                 PXFER_CTL  paccess_func);
*
*               int        ercode      The returned error status.
*
*               FTCS       *pft        Pointer to a data transfer
*                                        control structure
*
*               PXFER_CTRL paccess_func
*                                      Pointer to a transfer control
*                                        access function
*
*  Description  This function sends/receives one or more files using
*               Xmodem, Ymodem, Zmodem or Kermit protocol. It is the
*               responsibility of the calling function to initialize
*               the data transfer structure referenced by pft.  (See
*               SINIT_FT  and  RINIT_FT).  The file(s)  are moved by
*               making repeated calls to  AFER_FT (ASCII transfers),
*               XFER_FT   (Xmodem  transfers),   YFER_FT   (Ymodem),
*               ZFER_FT (Zmodem) or KFER_FT (Kermit).
*
*               If paccess_func is specified (non-NIL), the function
*               referenced  is  called  after each call  to  AFER_FT,
*               XFER_FT, YFER_FT, ZFER_FT or KFER_FT, and  passed the
*               pointer  to  the  data transfer structure.  Thus this
*               function can monitor  the state  of  the transfer for
*               various purposes  (e.g. display current packet number
*               or let the operator cancel the transmission).  If the
*               function returns a non-zero value,  the  transmission
*               is cancelled.  Note that  when sending files FMOVE_FT
*               waits for a complete packet to be sent before sending
*               the string of CANs.
*
*               Under normal conditions,  the function returns 0 when
*               all  file(s)  have been transmitted.  If the transfer
*               has  aborted,  the  function  returns  the  value  of
*               pft-&gt;fatal_error.
*
*  Returns      ercode            Possible return values:
*                                   0   - File transfer successful.
*                                   2   - Port number out of range.
*                                         *pft may have become corrupted
*                                   3   - Port is not open.  The port
*                                         may have been closed too soon.
*                                   7   - Could not a character to the
*                                         output queue. Check queue
*                                         size, hardware/software flow
*                                         control.
*                                   150 - Structure not initialized.
*                                   151 - Error opening file.
*                                   154 - Error reading file.
*                                   155 - Error writing receive file.
*                                   156 - File already exists (no-over-
*                                         write option set)
*                                   157 - Error updating file modtime.
*                                   160 - Cumulative timeouts &gt; max.
*                                   161 - Cancel received from remote.
*                                   162 - No initial NAK/'C' received.
*                                   163 - Output queue not draining.
*                                   164 - Sender timed out waiting for
*                                         ACK.
*                                   165 - Final ACK not received
*                                         after EOT.
*                                   166 - Receiver timed out waiting for
*                                         initial packet.
*                                   167 - Receiver exceeded retry limit
*                                         for a single packet.
*                                   168 - No incoming packet.
*                                   169 - Fatal packet number sequence
*                                         error.
*
*               pft               Various fields in the descriptor
*                                 are modified by the process.
*
*  Version      4.10 (C)Copyright Blaise Computing Inc.  1995
*
*  Change       4.10 02/23/95 VNP Windows version.
*  Change       4.01 10/30/92 VNP no return on fatal error; DONE only.
*
**/



#include <io.h>
#include <asynch_f.h>


long cps(long start_time, long num_chars)

{
  long dt;

  if (start_time != -1)
  {
      dt = _clock - start_time;

      if (dt <0) #ifdef _Windows dt = 1; #else dt += B_NEW_DAY; #endif if (dt > 0)
		  return max(0, num_chars * 91 / dt / 5);
  }
  return 0;
}

int f1mov_ft (PFTCS pft)
{
    long new_fpos;

    CHECK_FT(pft);

    if (pft-&gt;cur_state != X_DONE)
    {
	switch(pft-&gt;protocol)    /* Call the appropriate transfer func.  */
        {
            case ASCII:     afer_ft(pft); break;
            case XMODEM:
			case XMODEM_1K: xfer_ft(pft); break;
            case YMODEM:
            case YMODEM_G:  yfer_ft(pft); break;
            case ZMODEM:    zfer_ft(pft); break;
            case KERMIT:    kfer_ft(pft); break;

            default:        pft-&gt;fatal_error = INV_PARAMETER;
                            return FT_NOT_INIT;
        }
    }
    else
        return DONE;

                                /* calculate CPSs       */
	new_fpos = !pft-&gt;pfile ? 0 :
               (pft-&gt;direction == RECEIVER) ?
                      ftell(pft-&gt;pfile)
                    + pft-&gt;fbuffer_size
                    + pft-&gt;packet_index
                    - pft-&gt;append_offset :
               (pft-&gt;fbuffer_size &gt; pft-&gt;fbuffer_index) ?
                      ftell(pft-&gt;pfile)
                    - pft-&gt;fbuffer_size
                    + pft-&gt;packet_index :
		      ftell(pft-&gt;pfile);

    if(pft-&gt;f_pos <new_fpos) { pft->s_pos += new_fpos - pft-&gt;f_pos;
        pft-&gt;f_pos = new_fpos;
    }

    pft-&gt;s_cps = cps(pft-&gt;ss_time, pft-&gt;s_pos);
    pft-&gt;f_cps = cps(pft-&gt;fs_time, pft-&gt;f_pos);

    if (pft-&gt;s_pos &gt; pft-&gt;p_pos + pft-&gt;p_size)
    {
        pft-&gt;p_cps = cps(pft-&gt;ps_time, pft-&gt;s_pos - pft-&gt;p_pos);
        pft-&gt;ps_time = _clock;
        pft-&gt;p_pos = pft-&gt;s_pos;
    }
    else if (pft-&gt;s_pos <pft->p_size)
		pft-&gt;p_cps = pft-&gt;s_cps;

    return  pft-&gt;fatal_error;
}

int fmove_ft (PFTCS pft, PXFER_CTRL paccess_func)
{
    while (f1mov_ft(pft) == A_OK)
    {
        if (!pft-&gt;cancel_trans &amp;&amp; paccess_func)
             pft-&gt;cancel_trans =  paccess_func (pft);
    }

    return  pft-&gt;fatal_error;
}
</PRE>
<H5>
  <B>To contact us, &nbsp;please send
  <A HREF="mailto:orel@servicemart.com"><IMG ALIGN="Middle" SRC="../mail1.gif"
      WIDTH="32" HEIGHT="20"> e-mail to <FONT SIZE=3>Orel Software.</FONT></A>
  </B>
</H5>
<P>
<A HREF="s_hist.htm"><IMG SRC="ret_butt.gif" ALIGN=MIDDLE> Return to Track
Record Bits page</A>. 
<P>
<BR>
<A HREF="index.htm"><IMG SRC="orel.gif" ALIGN=MIDDLE> Return to Orel Software
home page</A>.
<PRE><HR>
<I><FONT SIZE=-1>On the Web since 1995. <BR>
Last revision: March 24, 1997 </FONT></I>
</PRE>
<P>
Copyright &copy;1996, 1997 Reginald group
</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -