Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gfortran, read characters on USB port

Status
Not open for further replies.

AdrianRB

Technical User
Jul 1, 2020
1
EE
usbport = "/dev/ttyACM0"
INQUIRE(FILE=usbport, EXIST=flag)
IF(.NOT. flag) usbport= ("/dev/ttyACM1")
OPEN(UNIT=11, FILE= trim(usbport), STATUS="OLD", ACCESS="STREAM",form='unformatted',iostat=istat)
FLUSH(11)
call selcommand(cmdstr)
call crcheck(cmdstr,crc)
allocate( character(len(CHAR(start)//trim(cmdstr)//CHAR(crc)//CHAR(msgend))) :: message )
message = CHAR(start)//trim(cmdstr)//CHAR(crc)//CHAR(msgend)
print *, "message length ", len(message), " Message ", message
write(*,3) (ichar(message(i:i)), i=1,len(message))
! do i = 1, len_trim(message)
! call fputc(11,message(i:i))
! end do
WRITE(11) message
.
.
.
call readline(11,response)
.
.
.
subroutine readline(iunit,line)
!! Reads a line from serial port
!====================================================================!
integer :: iunit !! File ID number
integer :: istat !! Error Status
integer :: filesize
character(len=1) :: n
character(len=*), intent(out) :: line !! Character string to read the line into
logical ::eek:pened
inquire(unit=iunit, size=filesize, iostat=istat,OPENED=opened)
print *, "READ: iostat is", istat, " file size ", filesize, "OPENED ", opened

do
! print *, " read char "
! istat = fgetc(iunit,n) ! read character byte
read(iunit, iostat=istat) n
print *, "char read, istat ", istat, " char ",n, " integer ",ichar(n)
if (istat /= 0) exit
line = line//n
line=adjustl(line)
print *, "*", line, "*"
end do
end subroutine readline
A short message can be sent to device on USB port but reading fails. Strace show that it is waiting for a character.
gfortran on ubuntu 20.04
 
Is this a RS232 base item or some other device? You might need to set some of the termios flags. Can you post what strace says starting from the OPEN command
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top