Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - comstatus() get serial port status http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 comstatus()         Get serial port status
------------------------------------------------------------------------------
 Declaration
   io.hdr

 Syntax
   func byte comstatus extern
   param value uint uPort

 Arguments
   uPort is a serial port number.

 Return
   A byte indicating the status of the port.

 Description
   The comstatus() function returns the status of a serial port in the
   following form:

   ------------------------------------------------------------------
   Bit         Description
   ------------------------------------------------------------------
   0           data ready
   1           overrun error
   2           parity error
   3           framing error
   4           break detected
   5           transmission buffer register empty
   6           transmission shift register empty
   7           time out (if set, other bits are invalid)
   ------------------------------------------------------------------

 Example
   #define EXAMPLE_IO
   #include example.hdr

   // A simple terminal program
   
   #define PORT_USED COM2
   
   proc Terminal
   para value uint nPort
   vardef
      uint uKey
   enddef
   do while .t.
      if comready( nPort )
         ?? chr( comrec( nPort ) )
      else
         uKey := inkey()
         do case
         case uKey == 0
         case uKey == K_ESC
            exit
         otherwise
            ?? chr( uKey )
            comsend( nPort, uKey )
         endcase
      endif
   enddo
   endproc
   
   proc Test_comstatus
   clear
   ? "Press Esc to finish"
   cominit( PORT_USED, COM_2400 + COM_NOPARITY + COM_STOP1 + COM_CHR8 )
   ? "COM port", istr( PORT_USED + 1 ), "status", comstatus( PORT_USED )
   comsend( PORT_USED, K_BS )      // send a backspace to initialize port
   ?? comstatus( PORT_USED )
   ?
   Terminal( PORT_USED )
   endproc

   proc main
   Test_comstatus()
   endproc

See Also: comready()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson