您的位置:首页 > 其它

Pcomm.dll(串口通讯库)中流控函数操作的说明手册

2016-09-12 13:36 489 查看

参数常量定义:

const

  { 波特率设置 baud rate setting }

  B50 = $0;

  B75 = $1;

  B110 = $2;

  B134 = $3;

  B150 = $4;

  B300 = $5;

  B600 = $6;

  B1200 = $7;

  B1800 = $8;

  B2400 = $9;

  B4800 = $A;

  B7200 = $B;

  B9600 = $C;

  B19200 = $D;

  B38400 = $E;

  B57600 = $F;

  B115200 = $10;

  B230400 = $11;

  B460800 = $12;

  B921600 = $13;

  { 数据位 data bit }

  BIT_5 = $0;

  BIT_6 = $1;

  BIT_7 = $2;

  BIT_8 = $3;

  { 停止位 stop bit }

  STOP_1 = $0;

  STOP_2 = $4;

  { 校验位 parity }

  P_EVEN = $18;

  P_ODD  = $8;

  P_SPC  = $38;

  P_MRK  = $28;

  P_NONE = $0;

  { 调制解调器控制设置 modem control setting }

  C_DTR = $1;

  C_RTS = $2;

  { 调制解调器线路状态 modem line status }

  S_CTS = $1;

  S_DSR = $2;

  S_RI  = $4;

  S_CD  = $8;

  { 错误代码 error code }

  SIO_OK                        = 0;    //正确

  SIO_BADPORT            = -1;  { 没有此端口或端口未打开 No such port or port not opened }

  SIO_OUTCONTROL    = -2;  { 无法控制此板 Can't control board }

  SIO_NODATA              = -4;  { 没有数据供读取或没有缓冲区供写入 No data to read or no buffer to write }

  SIO_OPENFAIL           = -5;   { 没有此端口或端口已打开 No such port or port has opened }

  SIO_RTS_BY_HW       = -6;  { 因为H/W流量控制而不能设置RTS Can't set because H/W flowctrl }

  SIO_BADPARM           = -7;  { 无效参数 Bad parameter }

  SIO_WIN32FAIL          = -8;  (* 调用WIN32函数失败请调用GetLastError函数以获取错误代码 Call win32 function fail, please call }

          GetLastError to get the error code *)

  SIO_BOARDNOTSUPPORT  = -9;  { 此版不支持这个函数 Board does not support this function}

  SIO_FAIL                                = -10; {  PCOMM函数执运行结果失败 PComm function run result fail }

  SIO_ABORT_WRITE              = -11; { 写入已被锁定,用户也放弃写入 Write has blocked, and user abort write }

  SIO_WRITETIMEOUT            = -12; { 已发生写入超时 Write timeout has happened }

  { 文件传输错误代码 file transfer error code }

  SIOFT_OK                     = 0;    //正确

  SIOFT_BADPORT        = -1; { 通讯端口不存在或未打开 No such port or port not open }

  SIOFT_TIMEOUT         = -2; { 协议超时 Protocol timeout }

  SIOFT_ABORT             = -3; { 用户键入的放弃 User key abort }

  SIOFT_FUNC               = -4; { 函数返回的放弃 Func return abort }

  SIOFT_FOPEN             = -5; { 无法打开文件 Can not open files }

  SIOFT_CANABORT     = -6; { YMODEM取消信号终止 Ymodem CAN signal abort }

  SIOFT_PROTOCOL     = -7; { 协议错误检测终止 Protocol checking error abort }

  SIOFT_SKIP                 = -8; { ZMODEM远程忽略此文件 Zmodem remote skip this send file }

  SIOFT_LACKRBUF      = -9; { ZMODEM接收缓冲区过小 Zmodem Recv-Buff size must >= 2K bytes }

  SIOFT_WIN32FAIL       = -10; (* 操作系统失败 OS fail }

      GetLastError to get the error code *) //调用GetLastError函数取得错误代码

  SIOFT_BOARDNOTSUPPORT  =  -11; { 此版不支持这个函数 Board does not support this function}

type

  IrqProc = procedure(port: Longint);stdcall;

  CallBackProc = function(len: Longint; rlen: Longint; buf: PChar; flen: Longint): Longint;stdcall;

{Import routine from PComm.dll}

function sio_open(port: Longint): Longint; stdcall;   (*打开通讯端口。参数需给定通讯端口号码,}

         例如使用COM1就将参数设为1;可设置的范围为1~256。*)

function sio_close(port: Longint): Longint; stdcall;   (*关闭通讯端口,此举会导致所有的传送机接收的动作

         都停止。参数为通讯端口号码*)

function sio_ioctl(port, baud, mode: Longint): Longint; stdcall; (*设置传输的参数,需给定的参数有三个,

          包括COM端口号、BaudRate、Mode(含Payity、DataBits、SotpBit三项)。

          BaudRate设置以下不同的整数代表不同的设置,如下:

         ----------

         | 整数|设置值(bps) ||整数|设置值(bps)| 整数|设置值(bps) ||整数|设置值(bps) |

         ——————————

         |0    | 50          || 5  | 300         | 10  | 4800         || 15 | 57600        |

         |1    | 75          || 6  | 600         | 11  | 7200         || 16 | 115200       |

         |2    | 110          || 7  | 1200        | 12  | 9600         || 17 | 230400       |

         |3    | 134.5        || 8  | 1800        | 13  | 9600         || 18 | 460800       |

         |4    | 150          || 9  | 2400        | 14  | 38400        || 19 | 921600       |

         ----------

         Mode参数含有三项,如下所示:

          bit_cnt(bit 0,1):

          0x00=bit_5

          0x01=bit_6

          0x02=bit_7

          0x03=bit_8

          stop_bit(bit 2):

          0x00=stop_1

          0x04=stop_2

          parity(bit 3,4,5):

          0x00=none

          0x08=odd

          0x18=even

          0x28=mark

          0x38=space

         不同的参数使用到不同的位合成,已经都将可能的数值列出,由于有三个参数混在一起,设置前需将

         每个所代表的数值先算出来,再用相加的运算加起来代入mode参数即可。*)

function sio_flowctrl(port, mode: Longint): Longint; stdcall;  (* 设置软件或硬件流量控制。有两个参数,

         第一个是通讯端口号码,第二个是流量控制的设置,如下:

         mode=bit 0:CTS flow control

          bit 1:RTS flow control

          bit 2:Tx XON/XOFF flow control

          bit 3:Rx XON/XOFF flow control(0=OFF,1=ON)  *)

function sio_flush(port, func: Longint): Longint; stdcall;    (*清空输入或输出缓冲区。有两个参数,

         第一个是通讯端口号码,第二个是清空选项,如下:

         func=flush function

          0:flush input buffer

          1:flush output buffer

          2:flush input & output buffer  *)

function sio_DTR(port, mode: Longint): Longint; stdcall;   (* 设置DTR的线路状态。有两个参数,

         第一个是通讯端口号码,第二个设0时降低DTR电压,设1时升高DTR电压 *)

function sio_RTS(port, mode: Longint): Longint; stdcall;   (* 设置RTS的线路状态。*)

function sio_lctrl(port, mode: Longint): Longint; stdcall;  (* 同时设置DTR和RTS的线路状态.有两个参数,

         第一个是通讯端口号码,第二个是DTR和RTS的组合。*)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息