2022年4月26日 星期二

如何使用 Win32 API 存取 RS232

 http://www.finetech.idv.tw/techdoc/bcbrs232/bcbrs232.htm

 https://stackoverflow.com/questions/820817/low-level-control-of-rs232-com-port-rts-cts-dtr-dsr-possible

Win32 API Communication Functions  

BOOL SetCommState(
    HANDLE hFile,    // handle of communications device
    LPDCB lpDCB            // address of device-control block structure
   );

 
    Windows App Win32 API System Services Winbase.h

SetCommState function (winbase.h)

 
http://delphi-kb.blogspot.com/2009/03/how-to-communicate-with-com-port.html
https://docs.microsoft.com/zh-tw/windows/win32/api/winbase/nf-winbase-setcommstate 


unit ComPort;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TComPort = class(TObject)
  private
    ComID, ComError: Integer;
    DcbOld: TDCB;
    CommTimeoutsOld: TCommTimeouts;
  protected
  public
    function Open(PortNo: integer): boolean;
    procedure Close;
    function Config(Baudrate: DWORD; ByteSize, StopBits, Parity: Byte): boolean;
    function ReadBlock(var Ch: array of char; BlockSize: dword): integer;
    function ReadChar(var Ch: char): boolean;
    function WriteBlock(var Ch: array of char; BlockSize: dword): boolean;
    function WriteChar(Ch: char): boolean;
    procedure Purge;
    function Error: integer;
    constructor Create;
  published
  end;



https://docs.microsoft.com/en-us/previous-versions/ms810467(v=msdn.10)?redirectedfrom=MSDN

Serial Communications in Win32
multiple threading and synchronization in Win32. In addition, a basic understanding of the Win32 heap functions is useful to fully comprehend the memory management methods used by the Multithreaded TTY (MTTTY) 

spcomm mscomm Tcomm Cport CnRS232 MScom SPCOM

Delphi串口通信技术与工程实践

 

https://github.com/MHumm/ComPortDriver

https://github.com/CWBudde/ComPort-Library

https://github.com/joelsernamoreno/WSD/blob/master/tools/nodemcu-flasher-master/SPComm.pas

https://torry.net/pages.php?id=198

http://www.tetraedre.com/advanced/serial/msdn_serial.htm

powershell "$port= new-Object System.IO.Ports.SerialPort

https://theitbros.com/how-to-delete-com-ports-in-use/

Docs Windows Server Windows 命令 參考
mode
顯示 [系統狀態]、[變更系統設定] 或 [重新設定埠] 或 [裝置]。 如果使用時不含參數,則 模式 會顯示主控台和可用 COM 裝置的所有可控制屬性。

https://docs.microsoft.com/zh-tw/windows-server/administration/windows-commands/mode

沒有留言: