DPRG List  

Απ: DPRG: dos.bat files driving motors

Subject: Απ: DPRG: dos.bat files driving motors
From: George Vastianos sebastian at matrix.kapatel.gr
Date: Mon Nov 22 13:01:52 CST 1999

Hello dprgers

Please read first the following 2 messages and after go down to
read my opinion...
- ---------------------------------------- Message
>From: Irene Moore & Tom Lohre <moorei at email.uc.edu>
Theme: DPRG: dos.bat files driving motors
>Dear Group,
> Is there a way out there to drive motors, receive data etc using
>individual dos.bat files? I am trying to think out a robot that uses Robby
>Garners Albert2 to ask and take questions while it preforms various motor
>functions and receives data from the environment. Albert2 can be directed
>to run batch files from prompts from within the discussion.
> Sincerely,
> Tom Lohre

- ------------------------------------- Message
>From: Robert L. Jordan <rljordan at airmail.net>
Theme: Re: DPRG: dos.bat files driving motors
>The parallal port is a good way to control the outside world. Peter H.
>Anderson and others have written good text on it. To control things on it
>the batchfiles, you could call "text" files to "print" or copy to the port.
>Obvilusly the files should have the string of characters you want to send
>the parallal port in them.
>Try this in DOS on the serial port to see how it works. Parallal port works
>similiar to this.
>1. mode com2:9600,n,8,1  (or Com1:)
>    (mode com2:9600,n,8,1,p if you want it to
>    wait for response from the port. This locks
>    up if the hardware does not respond though)
>2. Copy filename.ext com2:
>    any file name, most any extension
>    Copy autoexec.bat com2:
>3. Type filename.ext>com2:
>    This "pipes" the contents of the file
>    out of the com2: port
>4. These work to the parallal port
>    but need no Mode ... command
>EX: Copy filename.ext LPT1:
>    Type filename.ext>LPT1:
>Best wishes
>Robert L. Jordan
>DPRG Sec. 1999
- ----------------------------------------------------------------------------
- -------------

Ok Tom.

First of all

using batch files to control your pc based robot is a very good
idea because:
a) you can write algorithms only with an editor and you dont need
a compiler for your program!!!
b) the size of the batch file is only some bytes!!!

the problem in this case is that the dos cant give you access to

my opinion about the "copy <file> lptx:" and "mode:lptx" commands
is just "useless"

when we say "communication via ports" we may mean two diff.
thinks: a) communication via protocoll or b) communication via
access to port controller's registers.

so when you type in basic "out &h378,&hFF" you communicate
via access to the first register of lpt controller and when you
type "lprint chr$(&hFF)" you communicate via printer's protocoll.

you must never forget that the lpt and com ports designed for
communication with printers, modems, mouses e.t.c.

so when you communicate via protocolls your pc thinks that the
devices that are connected on its ports are printers, modems,
mouses e.t.c.

the commands that robert suggested are for protocoll

for example if you control a relay from the D7 of lpt port
you must write the number 128dec in 378hex address.

if you type "out &h378,128" your relay will be activated
but if you type "lprint chr$(128)" or just "copy <file> lpt1:"
(the <file> has size 1 byte and contains the 128 ascii char.)
then your pc thinks that on lpt there is a printer so starts
to check the busy, paper empty and other pins before activate
your relay..... and because there is no printer at all it will write you:

E:\>copy test lpt1:
Write fault error writing device LPT1
Abort, Retry, Ignore, Fail?

(cool ha?) but useless because your relay will never activated.....

now you can realize that dos commands are only for protocoll
communication and cant control your circuits

if you want to activate your relay via protocoll you can ... BUT
you must cheat your pc and make it thinking that your relay board
is a printer. there is a tip where some of control pins are pulled low
and some other pulled up and the pc "sees" a printer but this
technique is stupid because offers you only outputs and no inputs

t o   s o l v e   y o u r   p r o b l e m
you need some help from the assembly

you can make some very small  com files  using the debug of dos
to control each pin of your lpt port

to turn on D0 write these lines in a small com file:

- -ntest.com
- -a
1AC1:0100 MOV     DX,0378
1AC1:0103 IN      AX,DX
1AC1:0104 OR      AL,01
1AC1:0106 OUT     DX,AX
1AC1:0107 MOV     AH,4C
1AC1:0109 MOV     AL,00
1AC1:010B INT     21
- -r cx
CX 0000
- -w
writed 0000D bytes
- -q

now you have the test.com (13bytes) file that activates your relay in D0

some explanations:

first read all pins D0 to D7:
MOV     DX,0378
IN      AX,DX
after make only D0 "1" and left the other unchanged
 OR      AL,01
and the out the result
prepare your pc to return to dos
MOV     AH,4C
MOV     AL,00
calling int21and returning to dos
INT     21

in case that you want to turn off D0 you must do "anding"
so use the same program and use instead of
OR      AL,01
the following
(FEh = FFh-01h)

if you want to have input use IN command to check if a pin
is "1" or "0" and change the errorlevel before your exit to dos

this returns errorlevel 0
MOV     AH,4C
MOV     AL,00
INT     21

this returns errorlevel 5
MOV     AH,4C
MOV     AL,05
INT     21

with using "if errorlevel" command in your batches you will do
the job

Thats all guys...... just playing now!

George Vastianos
Electronics Department
Technological Educational Institute of Piraeus
robofreak at technologist.com
sebastian at matrix.kapatel.gr

P.S. Dont forget that in batch files your pc will allways use the drive
to run the .com files so if you use floppies you will have long delay
responce from your robot!!!!!!!!!!


More information about the DPRG mailing list