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 - comrec() receive a character from a serial port http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 comrec()            Receive a character from a serial port
------------------------------------------------------------------------------
 Declaration
   io.hdr

 Syntax
   func byte comrec extern
   param value uint uPort

 Arguments
   uPort is a serial port number.

 Return
   A character received by the serial port.

 Description
   The comrec() function receives a character from a serial port.

 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_comrec
   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_comrec()
   endproc

See Also: cominit() comsend()

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