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 :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
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
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 :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
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