×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

gfortran, read characters on USB port

gfortran, read characters on USB port

gfortran, read characters on USB port

(OP)
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 ::opened
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

RE: gfortran, read characters on USB port

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close