User Tools

Site Tools


using_serial_ports_in_linux

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revision Both sides next revision
using_serial_ports_in_linux [2022/03/03 11:20]
richardrussell created
using_serial_ports_in_linux [2022/03/04 15:04]
richardrussell
Line 11: Line 11:
 So to avoid your BASIC program 'blocking' in a statement like INPUT# whilst it waits for data to arrive, there needs to be some way to test how much data is 'waiting' in an input buffer.  Then the program can continue to perform useful tasks whilst it waits. So to avoid your BASIC program 'blocking' in a statement like INPUT# whilst it waits for data to arrive, there needs to be some way to test how much data is 'waiting' in an input buffer.  Then the program can continue to perform useful tasks whilst it waits.
  
-//BBC BASIC for Windows// provides built-in features to configure a serial port (as an extension of the **OPENUP** function) and to test for how much data is waiting in an input buffer (**EXT#** function), but //BBC BASIC for SDL 2.0// does not (because SDL 2.0 itself, which BBCSDL relies on to provide the cross-platform abstraction layer, doesn't). +To configure and open a serial port in Linux you should use code similar to the following (in this case the port **/dev/ttyUSB0** is being configured for 1 stop bit, 8 data bits, no parity and a speed of 9600 baud).  Note the addition of a trailing dot in the OPENUP function to suppress appending a **.bbc** extension:
- +
-To configure and open a serial port in Linux you should use code similar to the following (in this case the port **/dev/ttyUSB0** is being configured for 1 stop bit, 8 data bits, no parity and a speed of 9600 baud):+
  
 <code bb4w> <code bb4w>
Line 21: Line 19:
 </code> </code>
  
-To test how much data is 'waiting' in an input buffer, and can therefore be read safely without blocking, use function similar to this:+To test how much data is 'waiting' in an input buffer, and can therefore be read safely without blocking, use the EXT# functionsimilar to this:
  
 <code bb4w> <code bb4w>
-      DEF FNavail(N%) +      WHILE EXT#serial
-      LOCAL F%  +        byte& = BGET#serial% 
-      SYS "fileno", @hfile%(N%)!28 TO F% +        REM Do something with the data here 
-      SYS "ioctl", F%, &541B, ^N% : REM FIONREAD +      ENDWHILE 
-      = N%+      REM Continue with any background tasks
 </code> </code>
  
using_serial_ports_in_linux.txt · Last modified: 2022/03/06 22:15 by richardrussell