On Tue, 20 Jun 2017 09:18:50 +0000, Mark Morgan Lloyd <markmll.fpc-pas...@telemetry.co.uk> wrote:
> >I tend to use the lower-level serial.pp unit. The patches I contributed >a couple of years ago specifically added a couple of read-with-timeout >functions. I'm back with a question: I used the serial example in the hardware access wiki: http://wiki.freepascal.org/Hardware_Access#FPC_built_in_Serial_unit as a template and I have a button on my form to open/close the serial port, but it does not work properly. Below is my button code to open and close the port depending on the state it is in, which is set by the global boolean var FComOpen. The port number is taken from a spinedit speComPort and the baud rate is from a preloaded combobox cbxBaud: procedure TForm1.btnConnectComClick(Sender: TObject); begin if FComOpen then begin //Close com port SerSync(FComH); { flush out any remaining before closure } SerFlushOutput(FComH); { discard any remaining output } SerClose(FComH); FComOpen := false; TButton(Sender).Caption:= 'Open Serial'; ledSerial.Brush.Color:= clRed; end else begin //Open com port FComPortName := 'COM' + IntToStr(speComPort.Value) + ':'; FComFlags := [ ]; FBaud := StrToInt(cbxBaud.Text); FComH := SerOpen(FComPortName); if FComH <> 0 then begin FComOpen := true; SerSetParams(FComH,FBaud,8,NoneParity,1,FComFlags); TButton(Sender).Caption:= 'Close Serial'; ledSerial.Brush.Color:= clLime; end; end; end; The problem I have is that it seems only to work for COM1 or COM3, as soon as I use a higher numbered port like COM33 then it fails. What have I missed here? Is serial only able to work with the low numbered ports (single digit)? -- Bo Berglund Developer in Sweden _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal