MED PC Programmers Manual
MED PC Programmers Manual
IV
PROGRAMMERS MANUAL
SOF-700W
DOC-003
Rev. 3.0
Copyright 1999-2006 Med Associates I nc & Thomas A. Tatham
All Rights Reserved
Med Associates, I nc.
P.O. Box 319
St. Albans, Vermont 05478
Trademarks: MED-PC, WMPC, MED-PC I V, MedState Notation; Med Associates I nc.
Registered Trademarks: MED-PC; Med Associates I nc, Turbo Pascal; Borland I nternational, I nc.
MED ASSOCI ATES I NC. MED- PC I V PROGRAMMER S MANUAL
iii
TABLE OF CONTENTS
Chapter One . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Welcome To Programming I n MedState Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter Two . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
An I ntroduction to the Basic Concepts of Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter Three . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
An I ntroduction to #R, SX, ADD, and SHOW Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Chapter Four . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Controlling the Beginning and End of a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Chapter Five . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Creating a Program for an FR Schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
(An I ntroduction to Z-Pulses and Adding a Counter to I nputs) . . . . . . . . . . . . . . . . . . . . . . 21
Chapter Six . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Establishing Default Values for Variables and Using a Variable Time I nput . . . . . . . . . . . . . . 25
(An I ntroduction to the SET and #T Commands) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Chapter Seven . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Decisions, Decisions, Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
(I ntroducing the I F Statement) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Chapter Eight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
An I ntroduction to Arrays, Part One . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Chapter Nine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Array Commands As Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
(An introduction to the LI ST, RANDI , AND RANDD commands) . . . . . . . . . . . . . . . . . . . . . . 45
Chapter Ten . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
An I ntroduction to the VAR_ALI AS Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Chapter Eleven . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
The Data Has Been Collected, Now What? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
(An introduction to Print and Disk Commands) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Chapter Twelve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
So How Does This Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
(The MED-PC: Theory Of Operation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Chapter Thirteen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
An I ntroduction to Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
MED ASSOCI ATES I NC. MED- PC I V PROGRAMMER S MANUAL
iv
Appendix A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
I nput Section Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Output Section Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Turning Outputs On and Off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Coordinating Events Across State Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Coordinating Events Across Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Mathematical Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Statistical Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Decision Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Data Handling Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Stopping the Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Miscellaneous Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Listing of Special I dentifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Commands that Come Before the First State Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Appendix B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Appendix C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
I nline Pascal Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Background Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
I mporting I nline & Background Pascal Code from Earlier MED-PC Versions . . . . . . . . . . . . . 164
MED-PCs I nternal Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
I NDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
MED ASSOCI ATES I NC. MED- PC I V PROGRAMMER S MANUAL
1
CHAPTER ONE
Welcome To Programming I n MedState Notation
I ntroduction
This newly revised manual has been designed to aid all users of the state notation language, MedState
Notation (MSN), used with MED-PC
Version I V.
The novel user will find that each of the following chapters introduces a couple of commands in
MedState Notation and then presents example programs using those new commands. Each chapter
builds on one another, so it is recommended that the manual be read from cover to cover, taking the
time to try each Tutorial. There should be no concerns about having to set aside large blocks of time
to read the manual; the manual has been written in such a way that no one chapter should take very
long to read. To get the most from each chapter it is recommended that the reader type in each
program in the Tutorial to test their new knowledge. Also, make sure to save the files with the names
suggested (or at least keep track of the substituted names). The reason is that the following Tutorials
build on the previous ones. Not only will this make it easier to switch from one Tutorial to the next, it
will also help create the habit of going back to old code for ideas and/or shortcuts in programming.
The intermediate user may find the chapters of some use, but if already familiar with most of the
commands, it is possible to just flip to the Tutorials at the end of each chapter to brush up on
MedState Notation.
The experienced user, who is switching from MED-PC for DOS or WMPC to MED-PC
Version I V may
want to look at the first Tutorial to see the differences in translating and compiling in MED-PC
Version
I V and any refreshers needed for codes can be answered in Appendix A. There is also a new chapter
on how to write and use Macros.
Software Backup
I n this age of hard drives and CD ROMS, many people overlook the need to back up their software.
We at Med Associates, however, advise everyone to make a backup of their programs and/or data on a
daily or weekly basis.
Before Getting Started
I n order to get the most out of the Tutorials at the end of each chapter, we recommend that MED-PC
Version I V be installed on the hard drive and configured for the existing hardware before starting to
read this manual. I f necessary, consult the MED-PC