/dev/par1 I-O control

bridged with qdn.public.ddk.printer
Post Reply
Leandro Colen

/dev/par1 I-O control

Post by Leandro Colen » Thu May 16, 2002 9:19 pm

Hi,

i´m trying to send a simple out8() to the parallel port of my x86, i put an
osciloscope in the port to monitor the signal but i can´t see if it was
successfull.

It´s because the devc-par actually have the control of the port? And every
time that i try to send the signal the devc-par override it?

Can i disable the devc-par to do my tests?

thx

Robert Krten

Re: /dev/par1 I-O control

Post by Robert Krten » Thu May 16, 2002 9:19 pm

Leandro Colen <lcrocha@yahoo.com> wrote:
Hi,

i'm trying to send a simple out8() to the parallel port of my x86, i put an
osciloscope in the port to monitor the signal but i can't see if it was
successfull.

It's because the devc-par actually have the control of the port? And every
time that i try to send the signal the devc-par override it?

Can i disable the devc-par to do my tests?
Sure; you can kill it (slay devc-par), or simply put it on hold.

I used the parallel port under Neutrino to drive an antique paper tape reader :-)

Here's the code -- note some of the initializations, etc:

(tabstops are every 4 characters)

/*
* main.c
*
* QNX 6, main.c shell version 0.005
*
* (C) Copyright 2002, 1230599 Ontario Inc., dba PARSE Software Devices.
* All rights reserved. Use subject to terms in LICENSE file.
*
* This module represents the main module for the PR-68E paper tape
* interface program.
*
* This program will cause the paper tape reader to read characters.
*
* The hardware is organized such that it's driven off the parallel port,
* with the parallel port's STROBE signal driving the stepper motor
* circuit. The STROBE signal is inverted, so it has to be set in software
* as a 1 to 0 transition to step. The stepper motor needs 4 steps for
* one sprocket step.
*
* With a 1 ms delay, this means 2 ms elapse for each step, which means
* 8 ms elapse per sprocket step. 1/8ms = 125 Hz -- theoretically, the
* paper tape reader can do 300 Hz.
*
* 2002 04 29 R. Krten created
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>

#include <sys/neutrino.h>

#include <hw/inout.h>

#define LPT_DATA_REG 0
#define LPT_STAT_REG 1
#define LPT_CTRL_REG 2

#define MAX_TIME 200

static void optproc (int, char **);

const char *progname = "pr68";
const char *blankname= " ";
extern char *version; // version.c

int optp; // port; default 0x378
int optv;

int
main (int argc, char **argv)
{
int x;
int timeout;

optproc (argc, argv);

if (ThreadCtl (_NTO_TCTL_IO, 0) == -1) {
fprintf (stderr, "%s: can't do ThreadCtl for _NTO_TCTL_IO, errno %d\n", progname, errno);
perror (NULL);
}

out8 (optp + LPT_CTRL_REG, 0x21); // 0x20 programs the parallel port for read, LSB is the inverted STROBE pin output

while (1) {

// while sprocket hole not preset...
timeout = 0;
while ((in8 (optp + LPT_STAT_REG) & 0x20) == 0) {
out8 (optp + LPT_CTRL_REG, 0x21);
nanospin_ns (2000); // 2000 ns = 2us
out8 (optp + LPT_CTRL_REG, 0x20);
delay (1);
timeout++;
if (timeout > MAX_TIME) {
fprintf (stderr, "%s: EOT\n", progname);
exit (EXIT_SUCCESS);
}
}

// at this point the sprocket hole showed up; data must be valid
x = in8 (optp + LPT_DATA_REG);
printf ("%d%d%d%d%d%d%d%d\n", !! (x & 0x80), !! (x & 0x40), !! (x & 0x20), !! (x & 0x10), !! (x & 0x08), !! (x & 0x04), !! (x & 0x02), !! (x & 0x01));
// printf ("%d%d%d%d%d%d%d%d\n", !! (x & 0x01), !! (x & 0x02), !! (x & 0x04), !! (x & 0x08), !! (x & 0x10), !! (x & 0x20), !! (x & 0x40), !! (x & 0x80));
fflush (stdout);

// now wait for sprocket hole to go away...
timeout = 0;
while ((in8 (optp + LPT_STAT_REG) & 0x20) == 0x20) {
out8 (optp + LPT_CTRL_REG, 0x21);
nanospin_ns (2000); // 2000 ns = 2us
out8 (optp + LPT_CTRL_REG, 0x20);
delay (1);
timeout++;
if (timeout > MAX_TIME) {
fprintf (stderr, "%s: EOT\n", progname);
exit (EXIT_SUCCESS);
}
}
}

return (EXIT_SUCCESS);
}

static void
usageError (void)
{
fprintf (stderr, "%s: error in use, type \"use %s\" for usage\n", progname, progname);
exit (1);
}

static void
optproc (int argc, char **argv)
{
int opt;

if (!argc) {
usageError ();
}

optp = 0x378;

while ((opt = getopt (argc, argv, "p:v")) != -1) {
switch (opt) {
case 'p':
sscanf (optarg, "%x", &optp);
break;
case 'v':
optv++;
if (optv > 1) {
printf ("Verbosity is %d\n", optv);
}
break;
default:
usageError ();
break;
}
}

for (; optind < argc; optind++) {
printf ("additional parameters [%d] -%s-\n", optind, argv [optind]);
}
}


--
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Leandro Colen

Re: /dev/par1 I-O control

Post by Leandro Colen » Thu May 16, 2002 9:40 pm

the (slay devc-par) was enought to my tests.

thx.

"Robert Krten" <nospam88@parse.com> escreveu na mensagem
news:ac17aj$phd$1@inn.qnx.com...
Leandro Colen <lcrocha@yahoo.com> wrote:
Hi,

i'm trying to send a simple out8() to the parallel port of my x86, i put
an
osciloscope in the port to monitor the signal but i can't see if it was
successfull.

It's because the devc-par actually have the control of the port? And
every
time that i try to send the signal the devc-par override it?

Can i disable the devc-par to do my tests?

Sure; you can kill it (slay devc-par), or simply put it on hold.

I used the parallel port under Neutrino to drive an antique paper tape
reader :-)

Here's the code -- note some of the initializations, etc:

(tabstops are every 4 characters)

/*
* main.c
*
* QNX 6, main.c shell version 0.005
*
* (C) Copyright 2002, 1230599 Ontario Inc., dba PARSE Software Devices.
* All rights reserved. Use subject to terms in LICENSE file.
*
* This module represents the main module for the PR-68E paper tape
* interface program.
*
* This program will cause the paper tape reader to read characters.
*
* The hardware is organized such that it's driven off the parallel port,
* with the parallel port's STROBE signal driving the stepper motor
* circuit. The STROBE signal is inverted, so it has to be set in
software
* as a 1 to 0 transition to step. The stepper motor needs 4 steps for
* one sprocket step.
*
* With a 1 ms delay, this means 2 ms elapse for each step, which means
* 8 ms elapse per sprocket step. 1/8ms = 125 Hz -- theoretically, the
* paper tape reader can do 300 Hz.
*
* 2002 04 29 R. Krten created
*/

#include <stdio.h
#include <stdlib.h
#include <string.h
#include <unistd.h
#include <errno.h
#include <time.h

#include <sys/neutrino.h

#include <hw/inout.h

#define LPT_DATA_REG 0
#define LPT_STAT_REG 1
#define LPT_CTRL_REG 2

#define MAX_TIME 200

static void optproc (int, char **);

const char *progname = "pr68";
const char *blankname= " ";
extern char *version; // version.c

int optp; // port; default 0x378
int optv;

int
main (int argc, char **argv)
{
int x;
int timeout;

optproc (argc, argv);

if (ThreadCtl (_NTO_TCTL_IO, 0) == -1) {
fprintf (stderr, "%s: can't do ThreadCtl for _NTO_TCTL_IO, errno %d\n",
progname, errno);
perror (NULL);
}

out8 (optp + LPT_CTRL_REG, 0x21); // 0x20 programs the parallel port for
read, LSB is the inverted STROBE pin output

while (1) {

// while sprocket hole not preset...
timeout = 0;
while ((in8 (optp + LPT_STAT_REG) & 0x20) == 0) {
out8 (optp + LPT_CTRL_REG, 0x21);
nanospin_ns (2000); // 2000 ns = 2us
out8 (optp + LPT_CTRL_REG, 0x20);
delay (1);
timeout++;
if (timeout > MAX_TIME) {
fprintf (stderr, "%s: EOT\n", progname);
exit (EXIT_SUCCESS);
}
}

// at this point the sprocket hole showed up; data must be valid
x = in8 (optp + LPT_DATA_REG);
printf ("%d%d%d%d%d%d%d%d\n", !! (x & 0x80), !! (x & 0x40), !! (x & 0x20),
!! (x & 0x10), !! (x & 0x08), !! (x & 0x04), !! (x & 0x02), !! (x & 0x01));
// printf ("%d%d%d%d%d%d%d%d\n", !! (x & 0x01), !! (x & 0x02), !! (x &
0x04), !! (x & 0x08), !! (x & 0x10), !! (x & 0x20), !! (x & 0x40), !! (x &
0x80));
fflush (stdout);

// now wait for sprocket hole to go away...
timeout = 0;
while ((in8 (optp + LPT_STAT_REG) & 0x20) == 0x20) {
out8 (optp + LPT_CTRL_REG, 0x21);
nanospin_ns (2000); // 2000 ns = 2us
out8 (optp + LPT_CTRL_REG, 0x20);
delay (1);
timeout++;
if (timeout > MAX_TIME) {
fprintf (stderr, "%s: EOT\n", progname);
exit (EXIT_SUCCESS);
}
}
}

return (EXIT_SUCCESS);
}

static void
usageError (void)
{
fprintf (stderr, "%s: error in use, type \"use %s\" for usage\n",
progname, progname);
exit (1);
}

static void
optproc (int argc, char **argv)
{
int opt;

if (!argc) {
usageError ();
}

optp = 0x378;

while ((opt = getopt (argc, argv, "p:v")) != -1) {
switch (opt) {
case 'p':
sscanf (optarg, "%x", &optp);
break;
case 'v':
optv++;
if (optv > 1) {
printf ("Verbosity is %d\n", optv);
}
break;
default:
usageError ();
break;
}
}

for (; optind < argc; optind++) {
printf ("additional parameters [%d] -%s-\n", optind, argv [optind]);
}
}


--
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Leandro Colen

Re: /dev/par1 I-O control

Post by Leandro Colen » Fri May 17, 2002 6:52 pm

here i am again...

well.. yesterday, it work fine, but today when i started the tests again,
i´m back to the beginning.

Can anyone tell me the right way to disable the OS control over the paralel
port and let me do my in*() out*() work?

what i do today:

Started the QNX
slay devc-par
try to see if my program (out8(PORT,BYTE)) work. Well, it don´t work!!

Yesterday, when i see the command (slay devc-par) i just execute it and run
my program. All Works fine...
But i´ve try so many thing that maybe something is missing.

Can anyone help me again?
I´m just trying to use out*() and in*() functions using the 0x378 (paralel)

thnx
Leandro

Leandro Colen

Re: /dev/par1 I-O control

Post by Leandro Colen » Fri May 17, 2002 8:51 pm

found the problem...

my bios was set the lpt1 to ECP mode, i just select the NORMAL mode and the
program get to work again!

i don´t know really if this is the solution, but i get to work with the
program again!

bye.

P.S. thought that this is a useful information, that´s why i posted..


"Leandro Colen" <lcrocha@yahoo.com> escreveu na mensagem
news:ac3ili$ikr$1@inn.qnx.com...
here i am again...

well.. yesterday, it work fine, but today when i started the tests again,
i´m back to the beginning.

Can anyone tell me the right way to disable the OS control over the
paralel
port and let me do my in*() out*() work?

what i do today:

Started the QNX
slay devc-par
try to see if my program (out8(PORT,BYTE)) work. Well, it don´t work!!

Yesterday, when i see the command (slay devc-par) i just execute it and
run
my program. All Works fine...
But i´ve try so many thing that maybe something is missing.

Can anyone help me again?
I´m just trying to use out*() and in*() functions using the 0x378
(paralel)

thnx
Leandro

Post Reply

Return to “qdn.public.ddk.printer”