Browse Source

Add files via upload

master
kenmartin-unix 4 years ago
committed by GitHub
parent
commit
ab97429958
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 34 deletions
  1. +39
    -1
      READMEFIRST
  2. +2
    -0
      alloff.inp
  3. +9
    -0
      allon.inp
  4. +5
    -0
      profile.bas
  5. +64
    -33
      relays.bas
  6. +4
    -0
      relays.pro

+ 39
- 1
READMEFIRST View File

@@ -1,4 +1,4 @@
4-16-2020
4-16-2020 Updated 4-19-2020

This should work under most any Linux and Linux under
WSL (Ubuntu, Debian) for windows at the command prompt.
@@ -54,3 +54,41 @@ in INFO.

All should work fine. But as usual no guarentee is implied.

4-19-2020

I have included some runtime files and sample input files.
Place profile.bas in your current working directory and
relays.pro and allon.inp and alloff.inp. The file examples
will let you to by example turn off all relays alloff.inp.
To do this you would enter at the command line:

bwbasic --profile relays.pro --tape alloff.inp relays.bas

To turn all relays on:

bwbasic --profile relays.pro --tape allon.inp relays.bas

To work interaactive you would:

bwbasic relays.bas

Once you get a handle on relays.bas commands you can
create you own .inp files and reference them by

bwbasic --profile relays.pro --tape <your file.inp > relays.bas

All the above can placed into a simple script file.

The purpose of relays.pro is to redirect standard and error
outputs to files relays-stdout.txt and relays-error.txt and
to tuen off ANSI so the output is easily readable without
escape codes. Using relays.pro then gives you a quiet display
suitable when scripts via .inp is executed.

The purpose of profile.bas which is used by default is to
enable ANSI control sequences so the command 'cls' works
and to set the normal editor to nano which if desired can
bet set to vi. The editor comes into play when creating
or changing a .bas file. To use while running bwbasic you
would issuse the command edit.


+ 2
- 0
alloff.inp View File

@@ -0,0 +1,2 @@
ao
x

+ 9
- 0
allon.inp View File

@@ -0,0 +1,9 @@
1
20
1
7
1
112
1
115
x

+ 5
- 0
profile.bas View File

@@ -0,0 +1,5 @@
OPTION TERMINAL ANSI
OPTION EDIT "nano"
OPTION DISABLE COMMAND "renum"
OPTION RENUM ""


+ 64
- 33
relays.bas View File

@@ -1,30 +1,32 @@
2 rem Relay control program in bwbasic 3.2 4-15-2020 Ken.
3 rem As of 4-13-2020 Debian apt get install bwbasic installs an old 2.2.
4 rem Assumes bwbasic 3.2. bwbasic 2.2 has issues see changelog.
5 rem Download 3.2a tar file. Untar then cd bwbasic-3.2a then sh compile
8 rem Set terminal to ANSI mode. Only 3.2 or newer
10 option terminal ANSI
12 rem Clear screen on initial startup. Only 3.2 or newer
15 cls
16 print : print "=== Relay games on ";DATE$;" at ";TIME$;" ===" : print " ";
17 shell "cat /etc/dogtag"
2 rem Relays control program in bwbasic 3.2 4-18-2020 Ken.
3 rem 4-18-2020 Added hardware check. Error traps and help.
5 rem As of 4-13-2020 Debian apt get install bwbasic installs an old 2.2.
6 rem Assumes bwbasic 3.2. bwbasic 2.2 has issues see changelog.
7 rem Download bwbasic-3.2a.tar file. Untar then cd bwbasic-3.2a then sh compile
8 rem Set terminal to ANSI mode. Linux and Windows. Only 3.2 or newer
9 rem option terminal ANSI
11 call cls : rem Clear screen on initial startup. Only 3.2 or newer
12 call close : rem Close any open files. Again 3.2 or newer.
13 rem Trap errors
14 on error gosub 10000
15 gosub 9000 : rem Get Dogtag & Model & see if it's allowable hardware.
16 print : print "=== Relay games on ";DATE$;" at ";TIME$;" ===" : print " ";d$
17 print " ";o$
18 print
19 rem If an error occurs gosub to line 1000
20 on error gosub 1000
24 rem b$ = Base address Beaglebone Black Debian 10.3 3-26-2020
30 let b$="/sys/class/gpio/gpio"
40 call close
24 rem b$ = Base address as of Beaglebone Black Debian 10.3 3-26-2020
25 let b$="/sys/class/gpio/gpio"
50 print "0 Off, 1 On, s State, sa State All,";
52 print " ao All Off, l Label or x Exit "; : input m$
52 print " ao All Off, l Label, h for Help or x Exit "; : input m$
60 IF m$ = "0" or m$ = "1" or m$ = "l" or m$ = "s" then goto 70
63 IF m$ = "x" or m$ = "e" then end : rem Stop program
64 IF m$ = "sa" then gosub 500 : goto 16 : rem State all
65 IF m$ = "ao" then gosub 600 : goto 16 : rem All Relays off
66 print "Mode error. Only 0, 1, s, l, ao All Off, sa State All ";
67 print "or x allowed" : goto 50
63 IF m$ = "x" or m$ = "e" then system : rem Stop program. Exit to system.
64 IF m$ = "sa" then print:print "Currently:":gosub 500:goto 16 : rem State all
65 IF m$ = "ao" then print:print "Was:":gosub 500:print "Now:":gosub 600:goto 16
66 IF m$ = "q" then print "Bye" : stop : rem Stop program
67 IF m$ = "h" then gosub 1000 : goto 16
68 print "Mode error. Only 0, 1, s, l, ao All Off, sa State All ";
69 print "h Help or x allowed" : goto 50
70 print "Relay # = gpio: 1 = 20, 2 = 7, 3 = 112, 4 = 115 or r to Return. ";
71 print "Enter gpio # ";
72 input s$
71 input "Enter gpio # ";s$
75 IF s$ = "20" or s$ = "7" or s$ = "112" or s$ = "115" then goto 80
76 IF s$ = "r" then goto 16 : rem Start over
78 print "Relay gpio number error. Only 20, 7, 112, 115 or r" : goto 70
@@ -32,7 +34,7 @@
82 IF m$ = "l" then gosub 400 : goto 16 : rem l = Label
84 IF m$ = "s" then gosub 300 : print : goto 16 : rem s = State
86 IF m$ = "0" or m$ = "1" then gosub 100 : goto 16 : rem Change Relay state
90 print : print "Error. Code fall through at line 90" : print : end
90 print : print "Error. Code fall through at line 90" : print : stop
100 rem Change state of a Relay.
101 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
102 let p$=b$ + s$ + "/value"
@@ -51,7 +53,7 @@
300 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
304 let p$=b$ + s$ + "/value"
310 call open("I",#1,p$) : rem Open for Input
350 read #1,x : rem Read numeric result
350 read #1,x : rem Read numeric result
355 call close(#1)
360 gosub 700
396 return : rem Start over
@@ -63,14 +65,12 @@
430 print "Label for gpio ";s$;" is ";l$
440 return
500 rem Display the state of all Relays 'sa'
505 print
510 let s$ = "20" : print "#1 "; : gosub 300
520 let s$ = "7" : print "#2 "; : gosub 300
530 let s$ = "112" : print "#3 "; : gosub 300
540 let s$ = "115" : print "#4 "; : gosub 300
550 return
600 rem Turn all Relays off 'ao'
610 print
612 let m$ = "0" : rem Set mode to '0' off
620 let s$ = "20" : gosub 100
624 let s$ = "7" : gosub 100
@@ -83,9 +83,40 @@
780 IF x = 1 then print " On"
790 IF x > 1 or x < 0 then print " Error"
799 return
999 rem Trap errors here. Hopefuly you will not get here.
1000 print : print "Error code ";err;" Error line ";erl
1040 print
1060 rem CLOSE will fail on 2.2 and loop but not 3.2+
1070 call close : rem Just in case something is open.
1100 end : rem Stop program
1000 rem Give them some help
1010 print:print "Information" : print
1020 print "To change the state of a relay use 0 for Off or 1 for On"
1022 print " Then enter the gpio number 20, 7, 112 or 115":print
1024 print "To check the state of a single relay use s"
1026 print " Then enter the gpio number":print
1028 print "To get the associated label (header pin) use l"
1030 print " Then enter the gpio number":print
1032 print "To get the state of all relays use sa": print
1034 print "To turn all relays off use ao":print
1035 print "For the latest updates goto:"
1036 print "https://github.com/kenmartin-unix/Bwbasic-3.2a-for-BeagleBone"
1040 print : input "Press enter ? ",h
1099 return
9000 rem Get Model & Dogtag d$ = Dogtag 0$ = MOdel. Check for Beaglebone 'Black'
9002 rem If we fail here we should not. This only runs once at startup.
9004 call open("I",#1,"/etc/dogtag") : rem Open dogtag file
9008 read #1,d$ : call close(#1)
9014 call open("I",#1,"/proc/device-tree/model") : rem Open model info
9018 read #1,o$ : call close(#1)
9020 rem Lets see if it's a 'Black'
9025 IF (instr(1,o$,"Black") > 0) then return
9055 print : print "Warning: It appears this is not a BeagleBone 'Black'" : print
9056 print "It appears to be : ";o$
9057 print "Running : ";d$
9058 system
10000 rem Trap errors here. Hopefuly you will not get here.
10020 print : print "Error code ";err;" Error line ";erl
10040 print
10041 IF (err = 2) then print "A program syntax error." : print : system
10042 IF (err = 5) then print "Trouble working with files." : print :system
10043 IF (erl > 9000) then print "Trouble during initial setup." : print : system:
10044 IF (err = 62) then print "Reading past the end of file attempted." : print
10048 IF (err = 64) then print "Invalid path. Verify open paths." : system
10060 rem CLOSE will fail on 2.2 and loop but not 3.2+
10070 call close : rem Just in case something is open.
11100 system : rem Stop program

+ 4
- 0
relays.pro View File

@@ -0,0 +1,4 @@
OPTION STDERR "relays-stderr.txt"
OPTION STDOUT "relays-stdout.txt"
OPTION TERMINAL NONE


Loading…
Cancel
Save