Technical information
Forterm Serial Solutions
Figure 11-1. Procedure open_com.______________________________
C *******************************************************************
C * *
C * Open_com- opens com port *
C * *
C *******************************************************************
subroutine open_com
C Port parameters definition common data
integer*1 comno,baud,parity,databits,stopbits,brk
common /port/ comno,baud,parity,databits,stopbits,brk
C Port name
character*8 comname
common /port/ comname
integer io
C Binary sequential file.
open (1, file=comname, form=’binary’, iostat=io)
if( io .NE. 0 )then
call screen(’Failed to open ’//comname//’\n’C,2)
call screen(’Try different port parameters\n’C,2)
else
call screen(’Opened serial port, called ’//comname//’\n’C,2)
end if
end
Figure 11-1 shows the use of the open statement to attach a file
to unit 1. The file is opened in binary mode, as opposed to
formatted or unformatted, to minimise the extent to which
FORTRAN alters the data being transferred. The ’iostat=io’ field
allows us to check for errors during the open. Open_Com tests
the value of io, which indicates whether an error has occurred,
and if so generates an error message.
At this stage the device driver has not been accessed. The
open statement has simply allowed FORTRAN and DOS to
prepare for I/O to the port, setting up their variables and buffers.
Reading From The File._____________________
The function inpstr, Figure 11-3, reads from the serial port.
Chapter 11 Page 165