Menu

Com ports

2006-11-05
2012-09-26
  • Nobody/Anonymous

    How can I use Com ports - what header, what library, and maybe tutorial (manual)...
    thanks

     
    • Anonymous

      Anonymous - 2006-11-05

      There is plenty on this subject alreday on the forum, which is searchable.

      The most flexible may is to use the Win32 API communications facilities, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp for an introduction.

      For simple applications you can always use stdio or iostream to access serial I/O.

      e.g.

      FILE* comport = fopen( "COM1:", "wb+" ) ;

      This has the distinct advantage of portability (although the device name itself is not portable), but is far less powerful. You may still need to use the Win32 API to set baud rate and flow control etc., but a quick-and-dirty method is simply to invoke the mode command via a system call, e.g:

      FILE* portfp ;

      system( "mode com1: baud=115200 parity=0 data=8 stop=1 to=off xon=off" ) ;
      portfp = fopen( "com1", "wb+" ) ;
      fprintf( portfp, "Hello, world!\n" ) ;
      fclose( portfp ) ;

      Clifford

       

Log in to post a comment.

MongoDB Logo MongoDB