MCU_通过windows串口API控制RTS和DTR

用FLYMCU-ISP进行固件烧录的教程比较多,一直比较好奇,RTS和DTR这两个引脚是如何通过软件完成的。网上问这个问题的也不少,正确答案不多见。今天查了一下,做个备注吧!

问题

MCUISP是怎样判断并控制RTS和DTR输出的?

比如下面这个,OPENEDV上讨论得比较多的电路(以下图片均来自OpenEDV【1】),

回答

事实上这个问题很简单,通过Windows串口API即可实现,我直接把该函数列到下面【2】,

EscapeCommFunction function

  • 12/05/2018
  • 2 minutes to read

Directs the specified communications device to perform an extended function.

Syntax

C++Copy

BOOL EscapeCommFunction(
  HANDLE hFile,
  DWORD  dwFunc
);

Parameters

hFile

A handle to the communications device. The CreateFile function returns this handle.

dwFunc

The extended function to be performed. This parameter can be one of the following values.

TABLE 1
ValueMeaning

CLRBREAK

9

Restores character transmission and places the transmission line in a nonbreak state. The CLRBREAK extended function code is identical to the ClearCommBreak function.

CLRDTR

6

Clears the DTR (data-terminal-ready) signal.

CLRRTS

4

Clears the RTS (request-to-send) signal.

SETBREAK

8

Suspends character transmission and places the transmission line in a break state until the ClearCommBreak function is called (or EscapeCommFunction is called with the CLRBREAK extended function code). The SETBREAK extended function code is identical to the SetCommBreak function. Note that this extended function does not flush data that has not been transmitted.

SETDTR

5

Sends the DTR (data-terminal-ready) signal.

SETRTS

3

Sends the RTS (request-to-send) signal.

SETXOFF

1

Causes transmission to act as if an XOFF character has been received.

SETXON

2

Causes transmission to act as if an XON character has been received.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Requirements

TABLE 2
  
Minimum supported clientWindows XP [desktop apps | UWP apps]
Minimum supported serverWindows Server 2003 [desktop apps | UWP apps]
Target PlatformWindows
Headerwinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

 

参考:

【1】http://www.openedv.com/posts/list/50030.htm

【2】https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-escapecommfunction

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值