×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

a way to loop with CHAIN

a way to loop with CHAIN

a way to loop with CHAIN

(OP)
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?

RE: a way to loop with CHAIN

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

RE: a way to loop with CHAIN

(OP)
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.

RE: a way to loop with CHAIN

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?

RE: a way to loop with CHAIN

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!


RE: a way to loop with CHAIN

(OP)
thanks! I'll try to figure things out after Thanksgiving. I'll definitely have more questions regarding this.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close