CHAPTER 4 USING MiniMINC WITH SERIAL ASCII EQUIPMENT This chapter gives a general description of how MiniMINC com- municates with serial ASCII equipment and describes how to use LISSJU.BAS, a demonstration program that creates Lissaj- ous figures on an interactive plotter. SERIAL ASCII EQUIPMENT MiniMINC can communicate with instruments that transmit characters according to EIA standard RS—232C. This standard sets the protocol for serial transfer by which most terminals (in- cluding the MiniMINC terminal) and some other instruments, such as interactive plotters and analytical balances, transmit and receive ASCII characters (see Appendix A in Book 2: MINC Programming Fundamentals for a table of ASCII codes). Serial transfer is a method of data transmission in which the compo- nents of a data word are transmitted one after another (serially) along a single pair of lines from a sending to a receiving device. MIniMINC’s SLU PORTS You connect devices to MiniMINC via the six SLU (Serial Line Unit) ports located on the back panel of the chassis (see Figure 16). MR-S-190-79 Figure 16. Back of the MiniMINC Chassis 37 INTRODUCTION TO MiniMINC The ports and their uses are: MODEM for sending and receiving data with the MINC NFT option via modems (devices used in long distance trans- mission of digital data), acoustic couplers, or direct cable PRINTER for sending data to a printing de- vice (printer) CONSOLE for communication with the MiniMINC terminal TERMINAL #3 TERMINAL #2 TERMINAL #1 for communication with most ter- minals, printers, and other serial ASCII equipment conforming to EIA standard RS—232C The MODEM, PRINTER, and CONSOLE ports perform only their designated functions; the TERMINAL #3, TERMINAL #2, and TERMINAL #1 ports are identical, general-purpose ports that function with a variety of devices. Chapter 2 of the MiniMINC Supplement provides information and illustrations regarding the connection and use of serial ASCII equipment with MiniMINC. SERIAL ASCII ROUTINES Communication between MiniMINC and a device depends on programs that include a set of special MiniMINC routines. These routines (SET-SERIAL, CIN, and COUT) transfer char- acters between MiniMINC and a connected serial ASCII device and determine the speed at which the characters travel, how they are represented, and the method to be used for checking their-integrity. Chapter 2 of the MiniMINC Supplement de- scribes the routines in detail. THE SERIAL ASCII DEMONSTRATION PROGRAM LISSJU, a serial ASCII program, creates Lissajous figures on a Tektronix 4662 interactive digital plotter. Description of LISSJU When the program starts, you supply five values that determine what kind of Lissajous figure LISSJU will create. The program computes the graph coordinates for your Lissajous figure and then chains to PLOT, a program that controls the plotter. PLOT causes the plotter to draw a border, the labels, and then the Lis- sajous figure. 38 USING MiniMINC WITH SERIAL ASCII EQUIPMENT Lissajous figures are frequency patterns commonly generated on an oscilloscope by connecting a source of known frequencies to one set of deflection plates and an unknown frequency to the other set. A recognizable pattern results when one frequency is a harmonic or integral multiple of the other, thus revealing the unknown frequency. _ The following line in LISSJ U contains the parametric equations used in computing the graph coordinates (REM is the RE- MARK statement. It distinguishes a comment from the execut- able portion of a program. See Book 3: MINC Programming Ref- erence for a description): X=SIN(X1*M*I+X2)\Y=SIN(Y1*M*I+Y2)\REM THE LISSAIOUS EQUATIONS where: X1 is the horizontal multiplier Y1 is the vertical multiplier X2 is the horizontal phase in radians Y2 is the vertical phase in radians M is 2PI divided by one less than the number of points N I is an integer that progresses from 1 to N The ratio of X1 to Y1 determines the actual shape of the Lissaj— ous figure. These multipliers are the frequencies of the X and Y sine waves that combine together to form the Lissajous figure. The phase shift resulting from the combined effects of X2 and Y2 causes the figure to "rotate" so that if you created a series of Lissajous drawings with identical multipliers (X1 and Y1), each drawing would be a different view of the same figure. Figures 17 through 19 show the rotation of a Lissajous figure with a 1/3 frequency ratio. PLOT’s Serial ASCII Routines The SET_SERIAL routine in the PLOT program sets the at- tributes of the serial line connecting MiniMINC with the plotter. This routine adjusts the serial line each time you run the pro- grams to create a Lissajous figure. Chapter 2 of the MiniMINC Supplement explains the SET-SERIAL routine in detail. The COUT serial ASCII routines in PLOT signal the plotter when to print text and when to plot points. They then direct the 39 INTRODUCTION TO MiniMINC 40 USING MiniMINC WITH SERIAL ASCII EQUIPMENT plotter’s pen to the proper coordinates, creating the final figure. Chapter 2 of the M iniMIN C Supplement also describes this rou- tine and its use. The Procedure Power up MiniMINC and the plotter (you can find the plotter’s switch settings documented inside the PLOT and LISSJU pro- grams). Next, insert the demonstration diskette into MiniMINC’s drive unit 0 and engage the system. Then type: RUN LISSIU [RET] LISSJ U responds: LISSJU creates Lissajous figures on an interactive digital plotter (see Chap. 4, Introduction to MiniMINC). Note that LISSJU produces a figure of almost any frequency ratio and phase shift. However, to produce high-quality drawings, please confine your responses to the following ranges: 1. Ratio between horz/vert multipliers not to exceed 40:1 2. Phases of O to 360 3. No. of points no greater than 295 HORIZONTAL MULTIPLIER? For the purpose of this demonstration, type the following values: HORIZONTAL MULTIPLIER? 5 [RET] VERTICAL MULTIPLIER? 6 [RET] HORIZONTAL PHASE ANGLE IN DEGREES? 18 [RET] VERTICAL PHASE ANGLE IN DEGREES? 18 [RET] NO. OF POINTS TO USE (0-295)? 250 [RET] LISSJU then verifies your answers with the following messages: LISSAIOUS FIGURE WITH 5/6 RATIO MADE WITH 250 POINTS MULTIPLE OF 5 - PHASE OF 18 DEG MULTIPLE OF 6 - PHASE OF 18 DEG Approximately 50 to 60 seconds will pass before the plotter be- 41 INTRODUCTION TO MiniMINC gins to draw. If you entered the values recommended for this ex- ample, the plotter will produce a figure like the one in Figure 20. MR-S-193-79 A Figure 20. Lissajous Figure — Plotter Sample You can examine the LISSJU and PLOT programs with the OLD and LIST commands. Type: OLD LISSJU [RET] or OLD PLOT [RET] When MiniMINC responds with READK type: LIST [RET] If you have a printer connected to the MiniMINC, type: COPY LISSJU LP: [RET] or COPY PLOT LP: [RET] 42 CHAPTER 5 A MiniMINC PROGRAMMING PRIMER This chapter describes how programs are used in MiniMINC and suggests a method you can use for developing programs. Book 2: MIN C Programming Fundamentals discusses the MINC BASIC language and how to program in it. PROGRAMS - A DESCRIPTION A program is a set of computer instructions or symbolic state- ments combined to perform some task. MiniMINC has two types of programs: system programs that make up the programming system and user programs (also known as application programs) that perform the special tasks required by the user. There are programs of both types supplied with MiniMINC — system programs and some user programs that demonstrate MiniMINC’s capabilities. MiniMINC system programs are machine language programs that are immediately intelligible to the computer without the in- tervention of a translating facility (the high—level MINC BASIC language requires interpretation before execution). System pro- grams control and direct the computer’s activities. MiniMINC user programs are series of MINC BASIC state- ments combined to perform tasks required by users. Such tasks include data processing, graphic displays, and serial ASCII data transfers. CREATING USER PROGRAMS Writing a program to run on MiniMINC requires a program- ming method and knowledge of the MINC BASIC language and program structure. Book 2: MINC Programming Fundamentals 43 INTRODUCTION TO MiniMINC explains MINC BASIC and this chapter explains a program- ming method. There are probably as many ways to write a program as there are programmers, but not every method results in an efficient and effective program. This chapter describes one method that works. Note that the following pages describe steps to take be- fore finally writing the program in the MINC BASIC language. Defining a Program's Objective First determine what you want the program to do. Suppose you want a program that arranges names in a list. There are some basic questions you must answer before you can write the program. For instance: • How should the names be ordered (alphabetically, ran- domly, order of importance)? • In what form should the names appear (full name, last name only, last name and first initial)? • How many names will the list contain (fixed or varia- ble number)? • How will the computer receive the names (typed at the terminal or from a file on diskette)? • In what form should the results appear (on the ter- minal screen, in a file, or on paper from a printer)? The answers to questions like these help to clarify the program’s objective. A definition of the program’s objective can help you to judge the program’s feasibility in terms of available time and resources. For instance, your potential program may require a printer when your system lacks one or you may not have the time neces- sary to type long lists of names should they be required. What- ever the limiting factor or factors (computer memory size, lim- ited time, unavailable equipment, or insufficient data), you can adjust your program’s objective accordingly. Thus a compre- hensive definition at the outset of your project can save you time and frustration later on while you’re programming. Pretend, for the sake of illustration, that you need a program to sort a list of names. Your requirements are for a program that will: 44 A MiniMINC PROGRAMMING PRIMER • accept up to 1000 names from the terminal • use names in the form of last name and first initial • sort names alphabetically • display the names in correct order on the terminal screen This program already exists as the demonstration program ALPHA. The remainder of this chapter traces ALPHA’s devel- opment up to the final programming effort. Outlining a Solution The next step in building a program is to establish your pro- gramming strategy. Create an outline for your program by describing the program’s method of operation in general terms. Your outline should in- clude every process required by your program to achieve its ob- jective. The processes should account for the input of data, data processing, and the output of data. When creating the outline, list the processes according to their sequence in the program. For example, you can outline ALPHA in the following way: 1. Input names 2. Reorder names 3. Output reordered names . This outline represents everything the program must do. Step 1 is data entry, Step 2 is data processing, and Step 3 is the result. Outlining a solution increases the likelihood that you will de- velop an effective program. If you are satisfied that the outline contains all the processes required by the program’s objective, then proceed to the next step. The ability to define a process will develop as you learn the MINC BASIC program structure described in Book 2: MIN C Programming Fimdameritalsr Constructing an Algorithm An algorithm is a fixed series of vvell—defined procedures that solves a problem in a finite amount of time. It is the essence of a program. An algorithm summary is the written representation of an algo- rithm. The summary often takes the form of brief English sen- tences or statements that succinctly describe each procedure 45 INTRODUCTION TO MiniMINC within the algorithm. These sentences or statements appear in the summary in the same order as the procedures they describe. Consider the outline for ALPHA. The first process, input- ting the names, uses an algorithm described in the following summary: 1. Create array for storing unordered names 2. Receive name from terminal 3. If no more names, then go to Step 6 4. Store name in unordered array 5. Go to Step 2 6. Stop The procedures are performed in numerical order. However, some procedures override this order by directing control to a specific procedure as in steps 3 and 5. Step 3 switches control to Step 6 when you are finished typing names. The switching pro- cedure in Step 3 reflects a MIN C BASIC programming tech- nique called a conditional branch. Step 5 always passes control to Step 2. This switching procedure reflects an uncondition- al branch. You should always take care to limit the number of branches of either kind. Algorithm summaries (and programs) can become confusing unless most of the activity is performed in simple numerical order. You may wonder why there are so many steps in this algorithm summary This is because each procedure corresponds to a MINC BASIC statement or set of statements that you will learn about in Book 2. For the moment, concentrate on the form of the algorithm sum- mary Mentally test the algorithm. The more you remember of its pattern, the better you’ll understand the discussions on pro- gram structure in Book 2. This is true because a program is an algorithm translated into action by the use of a programming language. The following algorithm summaries show how ALPHA reor- ders and then outputs names. 46 A MiniMINC PROGRAMMING PRIMER REORDER NAMES 1. Create array to store ordered names 2. Take next name from unordered array 3. Compare name with next name in unordered array I 4. Take name with lowest alphabetical position, switching po- sition of names if necessary 5. If name compared with last element of unordered array, then go to Step 7 6. Go to Step 3 7. Insert name in first open position of ordered array 8. If every name in unordered array tested for alphabetical order, then go to Step 10 9. Go to Step 2 10. Stop OUTPUT ORDERED NAMES 1. Display next name in ordered array 2. If end of ordered array, then go to Step 4 3. Go to Step 1 4. Stop NOTE The word "next" in the algorithm summaries can also mean "first." This practice reflects how the BASIC language handles arrays. Examine these algorithm summaries carefully. Notice how ex- plicit they are. This exactness is required because programs di- rect the computer’s operation, and computers perform only as directed. If you write a program based on an ambiguous algo- rithm, you must compensate for the ambiguity while program- 47 INTRODUCTION TO MiniMINC ming. However, because programming involves much more de- tail than constructing algorithms, allowing ambiguity into your algorithm summary greatly increases your work load. The three algorithm summaries given in this chapter should be combined into one summary to represent the entire ALPHA program. The resulting algorithm summary for ALPHA is: 1. Create array for storing unordered names 2. Receive name from terminal 3. If no more names, then go to Step 6 4. Store name in unordered array 5. Go to Step 2 6. Create array to store ordered names 7. Take next name from unordered array 8. Compare name with next name in unordered array 9. Take name with lowest alphabetical position, switching po- sition of names if necessary 10. If name compared with last element of unordered array, then go to Step 12 11. Go to Step 8 12. Insert name in first open position of ordered array 13. If every name in unordered array tested for alphabetical order, then go to Step 15 14. Go to Step 7 15. Display next name in ordered array 16. If end of ordered array, then go to Step 18 17. Go to Step 15 18. Stop 48 A MiniMINC PROGRAMMING PRIMER Notice that the "stops" formerly at the end of each process algo- rithm are missing. They were needed because a loop (a repeat- ing sequence of events) inside each process terminated itself and the process by sending control to a stop. Now that the processes are combined, control passes to the next process instead of ter- minating at a stop. The stop at Step 18 remains to terminate the A ALPHA algorithm. The algorithm described for ALPHA is only one of several algo- rithms capable of the same function. In fact, there is almost al- ways more than one solution to any given programming prob- lem. Keeping this in mind, you should evaluate your program objectives carefully in order to construct the most efficient and effective algorithms possible. A useful technique that can im- prove your understanding of a process, as well as the quality of the final algorithm, is to develop several algorithms for the same program. Testing an Algorithm After constructing an algorithm, and in its early stages of devel- opment, you should test the algorithm for integrity of design or soundness. To be sound, an algorithm must solve a problem in a finite amount of time with a fixed series of well-defined processes. Every process required to solve the problem must therefore be included within the algorithm and occur in proper sequence. There must also be a point in time when all the processes are fin- ished and the problem is solved. A method for appraising an algorithm’s design integrity is to mentally trace the path of several data items through the algo- rithm, one item at a time. You can detect flaws with this method that you would probably overlook in a general inspection. Try this method on ALPHA’s algorithm. Perform each step in the algorithm separately and in the indicated order. For now, and whenever you test an algorithm in this manner, suspend youryintuition and perform each step exactly as described. Using a piece of paper as the unordered array, write down a name each time you encounter Step 4, until you’ve entered four or five names (any names will do). When you’ve entered all the names, Step 3 directs you to Step 6. Continue with the algorithm until you reach the stop in Step 18. Use additional paper to rep- resent the ordered array and ALPHA’s output. This simple test method should work for all programming algo- 49 INTRODUCTION TO MiniMINC rithms. Proceed to the next stage in program development, im- plementing the algorithm, when you are convinced of the algorithm’s soundness. Implementing an Algorithm An implemented algorithm is a program. The writing of a pro- gram requires knowledge of a programming language and pro- gram structure. You should next read Book 2: MINC Programming Fundamen- tals. This book explains what you need to know to begin pro- gramming in MINC BASIC. The other MiniMINC manuals (Book 3: MIN C Programming Reference, Book 4: MIN C Graphic Programming, and the MiniMIN C Supplement) describe the MINC BASIC commands, statements, and routines. SUMMARY The MiniMINC system uses two types of programs: system and user programs. System programs control and direct the computer’s operations and thus form part of the MiniMINC sys- tem. User programs are created by MiniMINC users to perform tasks with the system. The system programs are machine lan- guage programs and the user programs are high-level language programs. There are many ways to create user programs. This manual demonstrates one of them. The steps involved are: Define a program’s objective Outline a solution Construct an algorithm Test the algorithm Implement the algorithm Book 2: MIN C Programming Fundamentals explains how to im- plement an algorithm with the MINC BASIC language. 50 CHAPTER 6 DIRECTIONS FOR READING THE MiniMINC MANUALS EXPERIENCED PROGRAMMERS If you are an experienced programmer in a language other than BASIC, we recommend that you follow the reading order sug— gested below for novice users. If you are familiar with BASIC, but not MINC BASIC, you should at least skim Books 2 and 3 for new commands and the MiniMINC approach to standard commands. NOVICES Book 2: MINC Programming Fundamentals continues your edu- cation in MiniMINC programming, but concentrates on more practical matters such as file creation and editing. It teaches MINC BASIC fundamentals in a thorough, uncomplicated manner using examples. You should find Book 2 and Chapter 5 of this manual sufficient preparation for programming on your own. You will probably need to review sections of Book 2 before you fully understand MINC BASIC as a "language." Review and practice are the keys to a functional understanding of MINC BASIC or any other programming language. Only by gaining experience will you achieve programming proficiency. You should find Book 3: MINC Programming Reference useful once you start programming. Book 3 and the MiniMINC Sup- plement together describe every command, statement, function, and routine in MINC BASIC. Book 4: MINC Graphic Programming teaches the concepts un- derlying graphics and conducts you through some demonstra- tions. Its second half serves as a reference manual for graphic 51 INTRODUCTION TO MiniMINC routines once you begin graphic programming. We recommend that you read it thoroughly beforehand. Reserve the MiniMINC Supplement for last. This book contains technical information for connecting MiniMINC to printers and other devices, testing your equipment, and correcting prob- lems that may arise. The Supplement also describes new fea- tures that Books 1 through 4 don’t point out. 52