Sample Programs
Aside from actually applying a DI-159 PLC in your control application, the best way to under-
stand how easy the instrument is to use is by example. The following just scratches the surface,
but should give you a solid understanding of the range of DI-159 PLC control possibilities.
Note that explanatory comments appear in these examples on the same line as the code to con-
serve space. Since the BASIC engine supports comments using the familiar REM statement,
comments would actually appear as program lines.
Example #1 Boilerplate Code
Object
Boilerplate code that must be included at the beginning of every program that uses the specified
I/O points. *
Code
10 dim c0 as pin Ch0 for analog input
20 dim c1 as pin Ch1 for analog input
30 dim c2 as pin Ch2 for analog input
40 dim c3 as pin Ch3 for analog input
50 dim c4 as pin Ch4 for analog input
60 dim c5 as pin Ch5 for analog input
70 dim c6 as pin Ch6 for analog input
80 dim c7 as pin Ch7 for analog input
90 dim i0 as pin Di0 for digital input
100 dim i1 as pin Di1 for digital input
110 dim i2 as pin Di2 for digital input
120 dim i3 as pin Di3 for digital input
130 dim o0 as pin Do0 for digital output
140 dim o1 as pin Do1 for digital output
150 dim o2 as pin Do2 for digital output
160 dim o3 as pin Do3 for digital output
170 dim push_button as pin Pb for digital input
180 dim led0 as pin Led0 for digital output
190 dim led1 as pin Led1 for digital output
200 rem your program starts here
'map analog input 0 to BASIC variable "c0"
'map analog input 1 to BASIC variable "c1"
'map analog input 2 to BASIC variable "c2"
'map analog input 3 to BASIC variable "c3"
'map analog input 4 to BASIC variable "c4"
'map analog input 5 to BASIC variable "c5"
'map analog input 6 to BASIC variable "c6"
'map analog input 7 to BASIC variable "c7"
'map digital input 0 to BASIC variable "i0"
'map digital input 1 to BASIC variable "i1"
'map digital input 2 to BASIC variable "i2"
'map digital input 3 to BASIC variable "i3"
'map digital output 0 to BASIC variable "o0"
'map digital output 1 to BASIC variable "o1"
'map digital output 2 to BASIC variable "o2"
'map digital output 3 to BASIC variable "o3"
'map pushbutton to BASIC variable "push_button"
'map LED0 to BASIC variable "led0"
'map LED1 to BASIC variable "led1"
'
Comment
These instructions map the various DI-159 PLC analog input and digital I/0 points so the
BASIC program can use them. You can rename them as necessary (e.g. change "c0" to "Motor-
Voltage"), and you can even omit those that will not be used by your program. In this example
all I/O points have been mapped to the variable names that immediately follow the "dim" state-
ment.
* Note that for clarity this code will not be shown in all other examples, so all subsequent pro-
gramming examples begin with line 200.
71
Содержание DI-159
Страница 51: ...StickOS DI 159 PLC Hardware Manual 4 is even _ 51...
Страница 76: ...DI 159 Block Diagram 76...
Страница 77: ...Dimensional Drawing 77...