Other topics about Sample Programs
This sample program demonstrates to transfer files between the external controller and the E5071C.
This program reads out data from a specified file on the external controller (or the E5071C), then write them to a specified file on the E5071C (or the external controller).
See Managing Files for this programming.
10 DIM Src_file$[50],Dst_file$[50],Src_size_char$[50],Inp_char$[30]
20 INTEGER Direction
30 ASSIGN @Agte507x TO 717
40 !
50 CLEAR SCREEN
60 ON ERROR GOTO Direct_select
70 Direct_select: !
80 PRINT "#### File Transfer ####"
90 PRINT " 1: E507x -> Controller"
100 PRINT " 2: Controller -> E507x"
110 PRINT ""
120 PRINT "Input 1 or 2"
130 INPUT "Number?",Inp_char$
140 Direction=IVAL(Inp_char$,10)
150 IF Direction<1 OR Direction>2 THEN Direct_select
160 OFF ERROR
170 !
180 PRINT ""
190 PRINT " Input source file name. ";
200 INPUT "Name?",Src_file$
210 PRINT ": "&Src_file$
220 !
230 IF Direction=2 THEN
240 PRINT " Input source file size. ";
250 INPUT "Size[Byte]?",Src_size_char$
260 PRINT ": "&Src_size_char$&"[Byte]"
270 END IF
280 !
290 PRINT " Input destination file name. ";
300 INPUT "Name?",Dst_file$
310 PRINT ": "&Dst_file$
320 PRINT ""
330 !
340 IF Direction=1 THEN
350 Copy_to_contr(@Agte507x,Src_file$,Dst_file$)
360 ELSE
370 Copy_to_e507x(@Agte507x,Src_file$,Src_size_char$,Dst_file$)
380 END IF
390 !
400 END
410 !=============================================
420 ! File Transfer Function (E507x -> Controller)
430 !=============================================
440 SUB Copy_to_contr(@Agte507x,Src_file$,Dst_file$)
450 DIM Img$[32],Src_size_char$[10],Buff$[9],Err_msg$[100]
460 INTEGER Max_bsize,Block_size,Err_no
470 REAL Src_size
480 !
490 ON ERROR GOTO Skip_purge
500 PURGE Dst_file$
510 Skip_purge: OFF ERROR
520 CREATE Dst_file$,1
530 ASSIGN @Dst_file TO Dst_file$
540 Max_bsize=24576 ! 24KByte
550 !
560 OUTPUT @Agte507x;"*ESE 60"
570 OUTPUT @Agte507x;"*SRE 32"
580 OUTPUT @Agte507x;"*CLS"
590 OUTPUT @Agte507x;"*OPC?"
600 ENTER @Agte507x;Buff$
610 !
620 ON INTR 7 GOTO Err
630 ENABLE INTR 7;2
640 PRINT "Now Copying: "&Src_file$&"(@E507x) -> "&Dst_file$&"(@Contro ller)"
650 OUTPUT @Agte507x;":MMEM:TRAN? """&Src_file$&""""
660 WAIT .1
670 ENTER @Agte507x USING "#,A";Buff$
680 ENTER @Agte507x USING "#,A";Digit$
690 Img$="#,"&Digit$&"A"
700 ENTER @Agte507x USING Img$;Src_size_char$
710 !
720 Src_size=VAL(Src_size_char$)
730 WHILE Src_size>0
740 IF Src_size>Max_bsize THEN
750 Block_size=Max_bsize
760 ELSE
770 Block_size=Src_size
780 END IF
790 !
800 ALLOCATE Dat$[Block_size]
810 Img$="#,"&VAL$(Block_size)&"A"
820 ENTER @Agte507x USING Img$;Dat$
830 OUTPUT @Dst_file USING Img$;Dat$
840 DEALLOCATE Dat$
850 !
860 Src_size=Src_size-Block_size
870 END WHILE
880 !
890 PRINT "Done"
900 ENTER @Agte507x USING "#,A";Buff$
910 ASSIGN @Dst_file TO *
920 !
930 GOTO Skip_error
940 Err: OFF INTR 7
950 OUTPUT @Agte507x;";:SYST:ERR?"
960 ENTER @Agte507x;Err_no,Err_msg$
970 PRINT "Error occurred!!"
980 PRINT " No:";Err_no,"Description: "&Err_msg$
990 Skip_error: OFF INTR 7
1000 SUBEND
1010 !=============================================
1020 ! File Transfer Function (Controller -> E507x)
1030 !=============================================
1040 SUB Copy_to_e507x(@Agte507x,Src_file$,Src_size_char$,Dst_file$)
1050 DIM Img$[32],Header$[10],Buff$[9],Err_msg$[100]
1060 INTEGER Max_bsize,Block_size,Err_no
1070 REAL Src_size
1080 !
1090 ON ERROR GOTO File_error
1100 ASSIGN @Src_file TO Src_file$
1110 OFF ERROR
1120 Max_bsize=24576 ! 24KByte
1130 !
1140 OUTPUT @Agte507x;"*CLS"
1150 OUTPUT @Agte507x;"*OPC?"
1160 ENTER @Agte507x;Buff$
1170 !
1180 PRINT "Now Copying: "&Src_file$&"(@Controller) -> "&Dst_file$&"(@ E507x)"
1190 Header$="#"&VAL$(LEN(Src_size_char$))&Src_size_char$
1200 OUTPUT @Agte507x;":MMEM:TRAN """&Dst_file$&""","&Header$;
1210 !
1220 Src_size=VAL(Src_size_char$)
1230 WHILE Src_size>0
1240 IF Src_size>Max_bsize THEN
1250 Block_size=Max_bsize
1260 ELSE
1270 Block_size=Src_size
1280 END IF
1290 !
1300 ALLOCATE Dat$[Block_size]
1310 Img$="#,"&VAL$(Block_size)&"A"
1320 ENTER @Src_file USING Img$;Dat$
1330 OUTPUT @Agte507x USING Img$;Dat$
1340 DEALLOCATE Dat$
1350 !
1360 Src_size=Src_size-Block_size
1370 END WHILE
1380 !
1390 OUTPUT @Agte507x;"",END
1400 ASSIGN @Src_file TO *
1410 !
1420 OUTPUT @Agte507x;";:SYST:ERR?"
1430 ENTER @Agte507x;Err_no,Err_msg$
1440 IF Err_no=0 THEN
1450 PRINT "Done"
1460 ELSE
1470 PRINT "Error occurred!!"
1480 PRINT " No:";Err_no,"Description: "&Err_msg$
1490 END IF
1500 GOTO Skip_error
1510 File_error:OFF ERROR
1520 PRINT "File name NOT found!"
1530 Skip_error:!
1540 SUBEND
Line 40
Assigns a GPIB address to the I/O pass.
Lines 60 to 130
These line allow the user to return to the entry start line and re-enter the data if an error (such as an invalid entry) occurs while entering the number that indicates the transfer direction. Then, these line display the list of transfer directions and prompt the user to input a selected number.
Lines 80 to 130
These lines display the list of transfer directions, and prompt the user to choose one of the items by typing in the appropriate number.
Lines 140 to 150
Converts the entered value into an integer and stores it into the Direction variable. Returns to the entry start line if an invalid value is contained in Direction.
Lines 180 to 210
These lines obtain the name of the source file for copying from the user input, store it into the Src_file$ variable, and display the value of Src_file$.
Lines 180 to 210
These lines obtain the name of the source file for copying from the user input, store it into the Src_file$ variable, and display the value of Src_file$.
Lines 230 to 270
If Direction is equal to 2 (from the external controller to the E5071C), these lines obtain the size of the source file for copying, store it into the Src_size_char$, and display the value of Src_size_char$.
Lines 290 to 320
These lines obtain the name of the destination file for copying from the user input, store it into the Dst_file$ variable, and display the value of Dst_file$.
Line 350
If Direction is equal to 1 (from the E5071C to the external controller), these lines use the subprogram Copy_to_contr to transfer (copy) a file with the name Src_file$ on the E5071C to a file with the name Dst_file$ on the external controller.
Line 370
If Direction is equal to 2, these lines use the subprogram Copy_to_e507x to transfer (copy) a file with the name Src_file$ on the external controller to a file with the name Dst_file$ on the E5071C.
Copy_to_contr, a subprogram for transferring files from the E5071C to the external controller that appears in lines 440 to 1000, is described below.
Lines 490 to 520
If any file with the name File$ already exists, these lines delete the file and newly create a file with the name File$.
Line 530
Assigns a destination file for copying to the I/O pass.
Line 540
This line stores a maximum number of transferred data (in bytes) per one transfer, that is 24 KByte to meet the size limitation of string arrays in the HTBasic, into Max_bsize variable.
Lines 560 to 600
These lines configure the system to generate an SRQ when it cannot find a source file for copying due to an error.
Lines 620 to 630
These lines set the branch target for an SRQ interrupt to enable SRQ interrupts.
Lines 640 to 650
These lines display a message showing that the transfer has started, and execute commands for reading data from a file on the E5071C.
Lines 670 to 680
These lines read the header symbol (#) in a block data, read number of digits (characters) indicating the size of data in bytes, then store it into Digit$ variable.
Line 690
This line creates a format for reading characters in Digit$.
Line 700
This line reads the data size in byte and stores it into Src_size_char$ variable.
Line 720
This line converts Src_size_char$ to a real number and stores it into Src_size variable.
Lines 730 to 870
These lines repeat the procedures below until Src_size reaches 0.
Lines 740 to 780: If Src_size is greater than Max_bsize, these lines assign the value of the Max_bsize to Block_size variable (transferred data in bytes). If Src_size is equal or less than Max_bsize, assign the value of Src_size to Block_size.
Line 800 This line defines Dat$ string variable with the size as large as Block_size and reserves memory area.
Line 810 This line creates a format for reading characters as many as Block_size characters.
Line 820 This line reads data from the file on the E5071C, then stores them into Dat$.
Line 830 This line writes the contents of Dat$ to the file on the external controller.
Lines 840 to 860 These lines free the memory area for Dat$ and subtract Block_size from Src_size.
Lines 890 to 900
These lines display a message showing the completion of transfer, then read a message terminator at the end of the data.
Lines 940 to 980
These lines define an error handler that retrieves and displays the number and message of an error that has occurred.
Copy_to_e507x, a subprogram for transferring files from the external controller to the E5071C that appears in lines 1040 to 1540, is described below.
Lines 1090 to 1110
Assigns a destination file for copying to the I/O pass.
Line 1120
This line stores a maximum number of transferred data (in bytes) per one transfer, that is 24 KByte, into Max_bsize variable.
Lines 1140 to 1160
Clears the error queue.
Line 1180
Displays a measurement start message.
Lines 1190 to 1200
These lines create the header part indicating that data will be sent as many as Src_size_char$ bytes, then send the header part of the command and its parameters for writing the data to the file on the E5071C.
Line 1220
This line converts Src_size_char$ to a real number and stores it into Src_size variable.
Lines 1230 to 1370
These lines repeat the procedures below until Src_size reaches 0.
Lines 1240 to 1280: If Src_size is greater than Max_bsize, these lines assign the value of the Max_bsiize to Block_size variable (transferred data in bytes). If Src_size is equal or less than Max_bsize, assign the value of Src_size to Block_size.
Line 1300 This line defines Dat$ string variable with the size as large as Block_size and reserves memory area.
Line 1310 This line creates a format for reading characters as many as Block_size characters.
Line 1320 This line reads data from the file on the external controller, then stores them into Dat$.
Line 1330 This line writes the contents of Dat$ to the file on the E5071C.
Lines 1340 to 1360 These lines free the memory area for Dat$ and subtract Block_size from Src_size.
Line 1390
This line sends a message terminator at the end of data.
Lines 1420 to 1430
These lines retrieve the error number and error message from the error queue, and then store them into the variables Err_no and Err_msg$, respectively.
Lines 1440 to 1490
If Err_no is equal to 0 (no error occurred), these lines display the message indicating completion of transfer, and if Err_no is not equal to 0 (an error occurred), display Err_no along with Err_msg$.
Lines 1510 to 1520
These lines handle the case with no source file for copying is found.