Welcome, Guest. Please login or register.

Author Topic: Printer port control?  (Read 1724 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline haywirepcTopic starter

  • Hero Member
  • *****
  • Join Date: Sep 2009
  • Posts: 1331
    • Show only replies by haywirepc
Printer port control?
« on: January 21, 2012, 09:27:53 PM »
Can someone tell me, can you turn off or on the printer port lines in amiga basic,
or some other programming language easily?

I have an idea for a simple home automation project, I just need to be able to turn the lines of the printer port low or high.

I know how to do this on a pc, but I never tried it on an amiga.

Any help or doc files would be greatly appreciated.

Thanks,

Steven
 

Offline gertsy

  • Lifetime Member
  • Hero Member
  • *****
  • Join Date: May 2006
  • Posts: 2318
  • Country: au
  • Thanked: 1 times
    • Show only replies by gertsy
    • http://www.members.optusnet.com.au/~gbakker64/
Re: Printer port control?
« Reply #1 on: January 21, 2012, 11:35:14 PM »
Yes, but I don't know how.   Basic can make system calls so you should be able to do it.  I have a book on PC automation with basic programs but its PC based.
I'll pull it out and have a look but I guess it wont translate to Amiga Basic.
 

Offline gertsy

  • Lifetime Member
  • Hero Member
  • *****
  • Join Date: May 2006
  • Posts: 2318
  • Country: au
  • Thanked: 1 times
    • Show only replies by gertsy
    • http://www.members.optusnet.com.au/~gbakker64/
Re: Printer port control?
« Reply #2 on: January 21, 2012, 11:55:00 PM »
Okay. No INP() or OUT() commands in Amiga Basic but I think this might help:

http://code.activestate.com/recipes/577750-for-amiga-heads-only-par-as-a-volume-in-read-mode-/

Arex or Python is the way to go.  Be much faster than ABasic in any case.  i guess.
« Last Edit: January 21, 2012, 11:57:21 PM by gertsy »
 

Offline mechy

Re: Printer port control?
« Reply #3 on: January 21, 2012, 11:59:05 PM »
Quote from: haywirepc;676860
Can someone tell me, can you turn off or on the printer port lines in amiga basic,
or some other programming language easily?

I have an idea for a simple home automation project, I just need to be able to turn the lines of the printer port low or high.

I know how to do this on a pc, but I never tried it on an amiga.

Any help or doc files would be greatly appreciated.

Thanks,

Steven


Might check here http://aminet.net/package/misc/misc/3DHome

There were some cool packages out there to control x-10 stuff, like EZHOME, if you can find it. maybe these have some insight on how they did it. article here thats interesting:
http://www.hometoys.com/htinews/aug98/reviews/hines/AmigaHA.html

this gives a arexx port i think:  http://aminet.net/package/driver/other/ARexX-10

which leads to this: http://marrickltd.com:8090/_files/Manuals/MAN105_120.PDF

Mech
« Last Edit: January 22, 2012, 12:03:35 AM by mechy »
 

Offline Castellen

Re: Printer port control?
« Reply #4 on: January 22, 2012, 12:09:47 AM »
There's an 8-bit data direction register (DDR) that controlls the direction of the 8 data lines plus an 8-bit register that you read/write input/output states.

There's also three "control" lines which can also be set in direction and read the input state or change the output state.

All of these 8+3 lines can be individually set as inputs or outputs as you want them.

Example in C:

Code: [Select]

// Amiga register addresses
#define PARALLEL_DDR 0xBFE301    // System address of parallel port data direction register
#define PARALLEL_DATA 0xBFE101   // System address of paralled port data register
#define PAR_CTRL_DDR 0xBFD200    // System address of parallel port control line data direction register
#define PAR_CTRL_DATA 0xBFD000   // System address of parallel port control line data register    

// Amiga register values
#define PARALLEL_DATA_OUTPUT 0xFF    // Set parallel data direction to output
#define PARALLEL_DATA_INPUT 0x00     // Set parallel data direction to input
#define PARALLEL_CTRL_OUTPUT 0x07    // Set sel, pout, busy as outputs  


/**********************************************************
write_data_latch
Writes single byte of data to programmer data latch


Arguments: unsigned char data_to_write
Return: none
Working:
**********************************************************/

void write_data_latch(unsigned char data_to_write)
{
    // Write data to port
    *parallel_ddr = PARALLEL_DATA_OUTPUT;
    *parallel_data = data_to_write;
   
    // Toggle data latch LE
    *par_ctrl_data = *par_ctrl_data & (~DATA_LATCH_ON);
    *par_ctrl_data = *par_ctrl_data | LATCH_IDLE;
}      


Reading input lines is as simple as reading from system address 0xBFE101

Lines that are set as inputs will have a state of 1 or 0 depending on the 5V or 0V input state.  If some lines are set as outputs, their current output state will be read in reads to 0xBFE101


That will work just like that, but to be "system friendly", you should declare to have the hardware resource open, then close it when the program exits.

e.g.
Code: [Select]

// Allocate the parallel port
    if (MiscBase=OpenResource(MISCNAME))
    {
        pport_bits_owner = AllocMiscResource(MR_PARALLELBITS,"Your program name");
        pport_port_owner = AllocMiscResource(MR_PARALLELPORT,"Your program name");
       
        // If parallel port was successfully allocated
        if ((pport_bits_owner==NULL) && (pport_port_owner==NULL))
        {
            // Here's where your program does its thing....
         }
         
         // Else the parallel port is busy
         else
         {
             printf(" Can't allocate parallel port resources!\n");
             printf(" The port may be in use by another application.\n\n");
         }

         // Clean up resources - do this when your program exits
         if (pport_bits_owner==0){FreeMiscResource(MR_PARALLELBITS);}
         if (pport_port_owner==0){FreeMiscResource(MR_PARALLELPORT);}
   
    }  
 



Should be easy enough do to in BASIC as well.  Been a few years, but I guess it'd be something like:

REM set data lines as outputs
poke(hBFE301, hFF)

REM set output line states to 10101010
poke(hBFE101, hAA)

I can't remember how you state hex numbers in BASIC.


Look on Aminet as well, Barry Walker wrote some demo stuff that shows how to do the same sort of thing in ARexx.
« Last Edit: January 22, 2012, 12:13:23 AM by Castellen »
 

Offline Zac67

  • Hero Member
  • *****
  • Join Date: Nov 2004
  • Posts: 2890
    • Show only replies by Zac67
Re: Printer port control?
« Reply #5 on: January 22, 2012, 10:36:39 AM »
Keep in mind that since there's no resource tracking, the parallel port is likely to stay allocated if you break the program.
 

Offline haywirepcTopic starter

  • Hero Member
  • *****
  • Join Date: Sep 2009
  • Posts: 1331
    • Show only replies by haywirepc
Re: Printer port control?
« Reply #6 on: January 22, 2012, 10:44:29 AM »
Thanks for everyone's help...

Today, I found out how to use the joystick ports as digital inputs and can read them in amiga basic fine. This means an amiga can make quite an effective burglar alarm...

On the printer port...

I am sure what I need to do can be done, it will require some research. Essentially, I want to hook leds to the the 8 lines and be able to turn them on or off in basic or some other language. I  can use some photocells and relays and other electronics to turn on and off whatever I want. I thought this might be a cool use for an a500 I have sitting around not doing much. I had some old hardware projects like this saved from magazines in a binder somewhere, wish I could find that binder now!

Steven
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: Printer port control?
« Reply #7 on: January 22, 2012, 11:05:49 AM »
@Haywirepc

Slightly off topic, but have you looked at the Arduino? That might be a more fun way to get started :)

Offline Heinz

  • Full Member
  • ***
  • Join Date: Nov 2005
  • Posts: 154
    • Show only replies by Heinz
    • http://amidevcpp.amiga-world.de
Re: Printer port control?
« Reply #8 on: January 22, 2012, 12:11:02 PM »
@haywirepc

It would be probably easier to use the serial port for your Projekt.
You can use the Standard System APIs and with a serial Relay card like this:
http://www.velleman.eu/products/view/?id=351282

You can switch whatever you like, without destroying your Amiga.
 

Offline haywirepcTopic starter

  • Hero Member
  • *****
  • Join Date: Sep 2009
  • Posts: 1331
    • Show only replies by haywirepc
Re: Printer port control?
« Reply #9 on: January 22, 2012, 11:19:07 PM »
http://www.velleman.eu/products/view/?id=351282

Did you mean this? Do you think I can control that via the amiga's serial ports by sending serial strings through basic? I saw something like that before where you'd send 8 characters through the serial port (one for each relay). like 00000000 - all off 11111111 - all on. 00000001 - all off but 8 and so on...

Bloodline, yes I just recently saw those arduino boards. I'm very behind on microcontrollers, last one I played with alot was a basic stamp 2. That arduino is like having 3 or 4 basic stamp 2's in one, its really slick. I'm a bit intimidated by the programming language it uses, but I think it may be worth learning for all the options that tiny board has...

Thanks for everyone's suggestions. How do you control leds, lights, relays, whatever using an aimga? Any suggestions welcome!

Steven