Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a way to loop with CHAIN 1

Status
Not open for further replies.

jackz15

Programmer
Jun 28, 2006
103
US
I have a code which controls a robot arm as shown:
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
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:
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
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?
 
it looks to me like 95 and 100 should be reversed in the
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
 
If I do put SYSTEM in the last line on the first code, then the robot delays before it moves(I don't know why, but it has to call SYSTEM to run immediately). That why I tried to have the second code loop the first code. But I can't even loop the second code since CHAIN stops the line after from running. I cannot find a way to make this loop work...I appreciate the help.
 
i don't really understand why you are using 2 programs anyway. Why not just go to a subroutine then return and
exit (system) when done?
 
If you are using Windows then the delay may be from the fact that the LPRINT command has to be interpreted by Windows first and may need to be sent to the print queue, before it is sent to the parallel port. Just try doing an LPRINT to send a text string to your printer. It takes a while.

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 This sends the value of port_data% to the third 
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!


 
thanks! I'll try to figure things out after Thanksgiving. I'll definitely have more questions regarding this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top