串口 实现 function TFTransForm.OpenPort:Boolean; var ret:Integer; begin OpenPort := false; ret := sio_open(GCommData.Port); if ret <> SIO_OK then begin MxShowError('sio_open',ret); Exit; end; if PortSet() = false then begin sio_close(GCommData.Port); Exit; end; OpenPort := true; GbOpen := true; SwitchMenu(); ShowStatus(); end; procedure TFTransForm.ClosePort; begin sio_close (GCommData.Port); GbOpen := False; SwitchMenu(); ShowStatus(); end; function TFTransForm.PortSet:boolean; var port : LongInt; mode : LongInt; hw,sw : LongInt; ret : LongInt; begin port := GCommData.Port; mode := GCommData.Parity or GCommData.ByteSize or GCommData.StopBits; PortSet := false; if GCommData.Hw then hw := 3 { bit0 and bit1 } else hw := 0; if GCommData.Sw then sw := 12 { bit2 and bit3 } else sw := 0; ret := sio_ioctl(port,GCommData.BaudRate,mode); if ret<>SIO_OK then begin MxShowError('sio_ioctl',ret); Exit; end; ret := sio_flowctrl(port,hw or sw); if ret<>SIO_OK then begin MxShowError('sio_flowctrl',ret); Exit; end; ret := sio_DTR(port,Integer(GCommData.Dtr)); if ret<>SIO_OK then begin MxShowError('sio_DTR',ret); Exit; end; if not GCommData.Hw then begin ret := sio_RTS(port,Integer(GCommData.Rts)); if ret<>SIO_OK then begin MxShowError('sio_RTS',ret); Exit; end; end; ShowStatus(); PortSet := True; end;
- 1
- 粉丝: 5
- 资源: 12
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
- 1
- 2
前往页