a way to loop with CHAIN
a way to loop with CHAIN
(OP)
I have a code which controls a robot arm as shown:
This code basically lets me press certain keys on the keyboard to move the arm. Unfortunately, the robot responds very slowly if I take out "SYSTEM". When i use SYSTEM, it exits the program regardless of the loop. I want the code to stay in the loop until i decide it to stop, so I thought about using CHAIN:
but the code doesn't work. I have a very premature understanding of qbasic and I've never really found a good documentation, so sorry if this problem is really basic. Anyone know of a solution?
CODE
10 K# = 0
20 DO
30 DO: A$ = INKEY$
40 LOOP UNTIL A$ <> ""
50 IF ASC(A$) = 68 THEN LPRINT "DW -10,0,0"
60 IF ASC(A$) = 65 THEN LPRINT "DW 10,0,0"
70 IF ASC(A$) = 87 THEN LPRINT "DW 0,10,0"
80 IF ASC(A$) = 83 THEN LPRINT "DW 0,-10,0"
90 IF ASC(A$) = 27 THEN K# = 1
95 SYSTEM
100 LOOP UNTIL K# <> 0
20 DO
30 DO: A$ = INKEY$
40 LOOP UNTIL A$ <> ""
50 IF ASC(A$) = 68 THEN LPRINT "DW -10,0,0"
60 IF ASC(A$) = 65 THEN LPRINT "DW 10,0,0"
70 IF ASC(A$) = 87 THEN LPRINT "DW 0,10,0"
80 IF ASC(A$) = 83 THEN LPRINT "DW 0,-10,0"
90 IF ASC(A$) = 27 THEN K# = 1
95 SYSTEM
100 LOOP UNTIL K# <> 0
CODE
10 K# = 0
20 DO
30 DO: A$ = INKEY$
40 LOOP UNTIL A$ <> ""
50 CHAIN "move.bas"
90 IF ASC(A$) = 27 THEN K# = 1
100 LOOP UNTIL K# <> 0
20 DO
30 DO: A$ = INKEY$
40 LOOP UNTIL A$ <> ""
50 CHAIN "move.bas"
90 IF ASC(A$) = 27 THEN K# = 1
100 LOOP UNTIL K# <> 0
RE: a way to loop with CHAIN
first example snippet. That is, System should come after
the last loop statement.
Otherwise it's always going to quit after a$ equals anything but null.
in the second example it will never get to line 90. It will either give an error if there is no move.bas or start move.bas
RE: a way to loop with CHAIN
RE: a way to loop with CHAIN
exit (system) when done?
RE: a way to loop with CHAIN
The SYSTEM command may seem to speed it up because it is closing all open files and immediately returning control to Windows.
You might find a better solution in using the INP and the OUT commands to control the robot. INP is used to get information from a COM device and OUT is used to send information to a COM device. The syntax is something like:
INP (port%)
OUT (port%, data)
The hexadecimal addresses for the COM and printer ports follow:
COM1 3F8-3FF
COM2 2F8-2FF
LPT1 378-37A
LPT2 278-27A
Alternate address may be LPT1 is 3BC-3BF and LTP2 is 378-37A
To show a Hex constant in QB use &h as a prefix for the address. I’m not sure what all of the pin addresses are but I am sure that you can find them in some old DOS books or even older electronics or computer books. You could try something like this:
CODE
REM pin of the COM1 port.
port_add% = &h3F8
OUT (port_add% + 3, port_data%)
Again I’m not sure of the details but maybe this can get you thinking in a different direction about how to do what you want to do. There may even be other alternative commands that will help you to control your robot. But as long as you use LPRINT you are going to have to wait for the results.
Hope this helps!
RE: a way to loop with CHAIN