【问题标题】:How to read serial port data in DOS environment [closed]DOS环境下如何读取串口数据
【发布时间】:2019-01-31 13:51:00
【问题描述】:

我正在从事与 DOS 相关的项目。我想使用 C 从 DOS 中的串口读取数据。

【问题讨论】:

标签: c dos


【解决方案1】:

我记得在过去的美好时光中使用了一款名为 Async Pro 的产品。如果我没记错的话,它提供了在 Turbo Pascal 中链接的库。

【讨论】:

    【解决方案2】:

    DOS 将串行端口称为 COM 端口。不幸的是,您不能像在 Linux 中那样在 C 中将它用作文件名,而在 DOS 提示符下您可以使用 COM1 来访问它。我假设你有 Turbo C(我们有 DOS 的 gcc 吗?可能没有),你需要一些“BIOS”库来使用 COM 端口。记得很多年前我写了一个访问并口(LPT1)的程序,接口大致相同。 This是我发现最接近我记忆的链接,代码如下:

    #include <sdio.h>
    #include <bios.h>
    #define com1 0
    #define settings (0xE3)
    main ( )
    {   /* declare PORTA and DOUT as integer numbers */
        int PORTA,DOUT ;
        /* set DOUT to integer 255 */
        DOUT=255;
        /* configure com1 9600 baud, 8 bit words, no parity */
        bioscom (0,settings,com1);
        /* send CPA00000000 command to ADR101 on com1 */
        fprintf (stdaux,"CPA00000000 \xD");
        /* send MAddd (ddd=DOUT) command to ADR101 on com1 */
        fprintf (stdaux,"MA %d \xD",DOUT );
        /* send PA command to ADR101 on com1 */
        fprintf (stdaux,"PA \xD");
        /* initialize com1 buffer */
        fscanf (stdaux,"%d",&PORTA );
        /* print data on screen */
        rewind (stdaux);
        /* read data from com1 and store at address of PORTA */
        printf ("PORT A is %d DECIMAL \n",PORTA);
    }
    

    【讨论】:

    • DJGPP 可用于 DOS,这是 gcc 的旧端口。
    猜你喜欢
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 2015-12-31
    • 2013-05-17
    相关资源
    最近更新 更多