Does FORTRAN 95 Support Hardware Serial Ports and Configuration?

  • Context: Fortran 
  • Thread starter Thread starter jelanier
  • Start date Start date
  • Tags Tags
    Fortran Serial
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
9 replies · 6K views
jelanier
Messages
67
Reaction score
1
Does FORTRAN support use of hardware serial ports? I need to write and read to a COM port.
If so, can you configure the port as well? (ie baud rate , parity ,data bits, stop bits )

Thanks,

Jim
 
Physics news on Phys.org
So, you can't configure the port from G95?
 
Fortran, like many other languages, offers the possibility to call functions of whatever libraries, e.g. system libraries for port access in your case; how that can be implemented has been shown in the thread gsal pointed you to. Of course, I cannot tell for sure without trying myself with g95 on your platform, but from that pov it should be theoretically possible to get suffcient port access from g95 code by the measures described there.

Theoretically.

Personally speaking I would not even think about using such a flavor of interfacing.

In doubt I would simply get myself a fancy little C or C++-library, e.g. Boost.Asio, add a lightweight C-interface callable from Fortran, link that with main program and carry on.

It could even be considered delegating the serial stuff completely to a C/C++ MPI 2 program and having Fortran spawning that and gathering the data via that MPI only.

The latter would be my approach.
 
Solkar said:
Fortran, like many other languages, offers the possibility to call functions of whatever libraries, e.g. system libraries for port access in your case; how that can be implemented has been shown in the thread gsal pointed you to. Of course, I cannot tell for sure without trying myself with g95 on your platform, but from that pov it should be theoretically possible to get suffcient port access from g95 code by the measures described there.

Theoretically.

Personally speaking I would not even think about using such a flavor of interfacing.

In doubt I would simply get myself a fancy little C or C++-library, e.g. Boost.Asio, add a lightweight C-interface callable from Fortran, link that with main program and carry on.

It could even be considered delegating the serial stuff completely to a C/C++ MPI 2 program and having Fortran spawning that and gathering the data via that MPI only.

The latter would be my approach.

I am already doing that. I am using a VB6 program to configure the port, read(by event) and write data to the serial port and passing strings to the FORTRAN program for number crunching.

Thanks anyway,

Jim
 
jelanier said:
I am already doing that.
No, you don't...

jelanier said:
I am using a VB6 program to configure the port, read(by event) and write data to the serial port and passing strings to the FORTRAN program for number crunching.
...because both architectures I mentioned neither utilize extensive string processing nor system calls for file or pipe ops but work memory-based with binary data. And for good reasons.

But your VB prog is a good starting point - VB supports COM, thus it'd be seamless to plugin a lightweight in-process (dll) COM component which simply exposes an interfaces to a shared memory chunk.

That shared memory could on the client side be accessed by a lightweight C-library linked with the Fortran executable.
 
Solkar said:
But your VB prog is a good starting point -

.

No, I am done. This already works fine. I have written many COM, client and server programs with VB6. It does fine with this. What I wrote was basically a VB GUI and I/O for the FORTRAN program. The VB does the I/O and the FORTRAN does the number crunching.

My question was whether G95 supports the hardware to the point where I didn't need the VB app at all. In this case, there is no need to use C or anything else. My VB app works fine for this purpose.

Thanks,

Jim
 
jelanier said:
I have written many COM, client and server programs with VB6.
That's fortunate, but besides the point.
The point is architecture.