delphi串口编程

串口实现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 retSIO_OK then begin MxShowError('sio_ioctl',ret); Exit; end; ret := sio_flowctrl(port,hw or sw); if retSIO_OK then begin MxShowError('sio_flowctrl',ret); Exit; end; ret := sio_DTR(port,Integer(GCommData.Dtr)); if retSIO_OK then begin MxShowError('sio_DTR',ret); Exit; end; if not GCommData.Hw then begin ret := sio_RTS(port,Integer(GCommData.Rts)); if retSIO_OK then begin MxShowError('sio_RTS',ret); Exit; end; ShowStatus(); PortSet := True; end;
rar 文件大小:238.02KB