Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

USB Read

JohnNichols
Valued Contributor III
2,904 Views
Dear Steve:

How do I connect to a USB port from Fortran.

Regards

John Nichols
0 Kudos
14 Replies
Steven_L_Intel1
Employee
2,904 Views
Typically there is a device driver that interacts with the USB port - you don't read the port directly. What sort of device are you using? Sometimes the device driver will create a COM port that maps to the USB device and you can open that with FILE="COM4:", etc., but you would need to understand what the specific device's driver provides.
0 Kudos
JohnNichols
Valued Contributor III
2,904 Views
Steve:

A small company in Iowa has a nice device that I would like to communicate with directly as I noted before. I went looking and found a device driver INF file which notes that they are using WINUSB as the interface package, as shown in the attached file.

I would like to access this from Fortran, can I do it? Or do i ahve to use something like C#

Regards

JMN
0 Kudos
Paul_Curtis
Valued Contributor I
2,904 Views
MS provides detailed instructions on how to access a WinUSB device:
http://msdn.microsoft.com/en-us/windows/hardware/gg487341.aspx

Once the initialization is done, you get a file handle for the device and then use the standard ReadFile() and WriteFile() API functions. All of this can be done directly from IVF, but you may have to create your own F90 interfaces for the WinUSB API functions.
0 Kudos
JohnNichols
Valued Contributor III
2,904 Views
Paul:

Thanks a lot for the help.

life was simpler when one only had 2 floppies, a serial port, a printer port and black hair.

Did you all know that the first Mirosft Fortran could run on two 5.25 inch floppies on the original compaq portable sewing machine. (It looked like a sewing machine.)

Those were better times, one had time to drink a beer in comfort as the program was compiling.

Ah for a simple life.

JMN
0 Kudos
Steven_L_Intel1
Employee
2,904 Views
Heck, I rememeber running DEC PDP-11 FORTRAN-D from an 8-inch floppy under RT-11. In 40K of core. No USB ports back then.
0 Kudos
anthonyrichards
New Contributor III
2,904 Views
40k of core?
You were LUCKY!
0 Kudos
Les_Neilson
Valued Contributor II
2,904 Views
At my age I just wish I could remember anything :-)

Les
0 Kudos
jparsly1
New Contributor I
2,904 Views
IBM 1620, 20K digits
The Fortran II compiler was on a deck of cards.
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,904 Views
For me DEC PDP-8I running TSS/8 with 4K word (12-bit) virtual machines and programming in FORTRAN-D.
We also ran FORTRAN-II in O/S 8 on that same machine, initially with 12K word of Core memory. We had 3 fixed head hard drives each 256KB (you read it right KB). We also ran the FORTRAN-D on a 4K word PDP-8L with "mass storage" as 10 character per second paper tape. In those days you kept your programs short (short symbol name choice) and you tended to program without error.

Now I have to have at least 1,000,000 as much memory anddisk. You couldn't run what we do now but the point to drive home is you can get a lot done in a small amount of memory.

Jim Dempsey
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,904 Views
>>The Fortran II compiler was on a deck of cards.

I bet it was a lot of fun if you dumped that sucker on the floor.
Usually you would diagonal mark the edge with a majic marker but you had to hand sort it in the event of the oops.

Jim
0 Kudos
Steven_L_Intel1
Employee
2,904 Views
That's what sequence numbers and a card sorter were for.
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,904 Views
That's what sequence numbers and a card sorter were for.


I will bet the FORTRAN-II compiler was in binary format as opposet to text (Hollerith). Binary cards did not have sequence numbers.

At shool we also had a card reader on our PDP-8I and you could load binary programs. The cards had 12 rows which fit in nicely with the 12-bit word length of that machine. You would toggle in a few word program to suck in the first card and overwrite the code you toggled in. That 80-word program would be a larger loader program that read in the rest of the loader, then loader was followed by a control program that managed the compiler.

Our FORTRAN-II compiler (on paper tape)was a three pass compiler which wrote assembly source code to an output device (paper tape or card punch). The load process was toggle in a smallbootstrap that would load in a tape containing the RIM loader (Read In Mode), this tape was followed by the BIN (Binary)loader, then you loaded the tape with the FORTRAN-II compiler. Three passes of your source code through the compilerto produce a tape with assembler source.Then you had to toggle in the loader again and load in the SABR assembler, three passes later again and your had the binary for the program (six passes now plus the tree tapes to get the compiler going and the three tapes to get the assembler going). Next you had to toggle in the loader again, and load in your binary program together with runtime libraries. On a 10cps paper tape it could be several hours before you get to see your program burp and crash. This is why you tended to do your coding right the first time. I am glad I do not have to go through that any more.

Jim Dempsey

0 Kudos
paulwdent
Beginner
2,904 Views
Yes I also remember using the PDP8 Fortran in 4K x 12bits. a 2-pass compiler. Previously my programs were on 5-hole paper tape pepared on Creed teleprinters. So a first task was to write a program to read 5-hole tape on an 8-hole tape reader and do conversion from Murrsay Code to ASCII. This program I entered on the front panel on the switches - bit at a time!

Now back to USB via FORTAN:

I have a USB-GPIB interface to some lab instruments. It works fine with Agilent's software, but I want to address the instruments via Compaq Visual Fortran which is somewhat the same as IVF.

Agilent only gives examples in C++ or VB, which might as well be Latin as far as enlighteniing me any!

They say write ID = iopen ("gpib0,23") in either VB or C++

They don't give the value or type of the variable gpib0, or how it gets defined.

I guess this translates to a Fortran OPEN statement, but what would the arguments in a Fortran OPEN statement be?

All clues are appreciated.
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,904 Views
If you have a C++ sample program that works, then convert it or a portion of it into a function (remove C/C++ main/winmain,...) and make the entry point have C calling convention.

Then you can call the C function form your Fortran code.

Once you can call the sample program (as subroutine) from fortran, then you can start modifying it.
The sample program can do something simple like identyfy device.

iopen is likely a function included in the Agilent library (which you may be able to link with your Fortran application).

Jim Dempsey
0 Kudos
Reply