serial communication in visual studio using windows.h

前端 未结 2 897
太阳男子
太阳男子 2021-01-27 13:51

I m new to the visual studio I want to trnsfer and receive some data from LPC2148 kit for thisI want to do the serial communication in Visual studio.

I have used dos.h i

相关标签:
2条回答
  • 2021-01-27 14:15

    Serial comms in Win32 is not particularly well catered for, the API is somewhat cumbersome to use but is dealt with fairly comprehensively in this article on MSDN.

    The .Net 2.0 (and later) Framework includes an excellent and easy to use serial communications class that makes the whole process much simpler, but you'll need to use C++/CLI or C# or some other .NET language to access that.

    For very simple serial I/O you can always use stdio and simply open the COM*n* device where n is the port number you wish to open. Stdio provides no means to set baud rate and framing etc., but this can easily be achieved by invoking the mode command via a system call. It is crude and lacks the flexibility of the API level interface, but may be adequate for your needs for a quick-and-dirty solution. For example:

    system( "MODE COM1: BAUD=115200 PARITY=n DATA=8 STOP=1" ) ;
    FILE port = fopen( "COM1:", "wb" ) ;
    fprintf( port, "hello, world!\n" ) ;
    fclose( port ) ;
    
    0 讨论(0)
  • 2021-01-27 14:19

    There are many articles in CodeProject with libraries for handling Serial Communication. You can start from here and here.

    May I also suggest that it will be easier to use C# for this task. You will be able to build the GUI faster and a serial port control is already provided (no need to fight with the API or find a library).

    0 讨论(0)
提交回复
热议问题