Note that there are some explanatory texts on larger screens.

plurals
  1. POFind the serial port settings in Delphi
    primarykey
    data
    text
    <p>Hi I have the need to find the Baud rate and other settings for a serial port, Looking about on the web, it looks like I should be using <a href="http://msdn.microsoft.com/en-us/library/aa363256%28VS.85%29.aspx" rel="nofollow noreferrer">GetCommConfig</a>, This returns a TCommConfig record with what I assume is the data I need. The problem is the function I wote returns the wrong values.</p> <p>The code below looks like it is working, but the baud rate is always 1200, which looking in windows device manager (and altering port settings), is wrong.</p> <p>I have tried calling it like so:</p> <pre><code>ComPort('com1'); ComPort('COM1'); ComPort('COM1:'); ComPort('COM4'); ComPort('COM9'); </code></pre> <p>the first 4 are valid but return 1200 and the 5th is invalid and returns 0</p> <pre><code>function ComPort(l_port:String):TCommConfig; {Gets the comm port settings} var ComFile: THandle; PortName: array[0..80] of Char; size: cardinal; CommConfig:TCommConfig; begin FillChar(Result, SizeOf(TCommConfig), 0);//blank return value try StrPCopy(PortName,l_port); ComFile := CreateFile(PortName,GENERIC_READ or GENERIC_WRITE,0,nil,OPEN_EXISTING,0{ FILE_ATTRIBUTE_NORMAL},0); try if (ComFile &lt;&gt; INVALID_HANDLE_VALUE) then begin FillChar(CommConfig, SizeOf(TCommConfig), 0);//blank record CommConfig.dwSize := sizeof(TCommConfig);//set size //CommConfig.dcb.DCBlength := SizeOf(_dcb); size := sizeof(TCommConfig); if (GetCommConfig(ComFile,CommConfig,size)) then begin Result := CommConfig; end; end; finally CloseHandle(ComFile); end; except Showmessage('Unable to open port ' + l_port); end; end; </code></pre> <p>Stepping through the code, the first 4 always hit the line <strong>Result := CommConfig;</strong>, so the GetCommConfig is retuning a valid code, so I must be missing something.</p> <p>I have tryed verious other things, such as setting the length of the dcb record, but all have the same result, as baud of 1200.</p> <p>Does anyone know where I am going wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload