Pcomm.dll(串口通訊庫)中流控函數操作的說明手冊


參數常量定義:
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的組合。*)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章