6 Jun 2008

Print Server Power Control Hack

Posted by Rhys

A few years a go I built this solid-state relay power control box.
Solidstate Relay Box

It connects to a parallel port allowing me to turn the power points on and off using software. The parallel port allows for up to 8 outputs by using data 0 through 7 (Pins 2 though 9).

DB25 Connector

I’ve had this box attached to my HTPC for the last few years; I use it to control power to my TV, subwoofer, table lamp etc.

As mentioned in my previous posts I’ve just finished building a new HTPC, and guess what, it has no parallel port! I thought it would be a simple case of using a USB to parallel adaptor but unfortunately these adaptors aren’t seen by windows as standard parallel ports; instead it appears in device manager as a “USB Printing Support” device hence can’t be addressed directly to turn the data pins on and off.

After much googling I came accross a project by Doktor Andy which uses a network print server to drive external devices. This was perfect since I had a HP JetDirect print server. I wasn’t able to get Doktor Andy’s circuit working with the JetDirect but Boyan Biandov who’s name was on Andy’s site was very helpful and told me how to get the JetDirect working. A single 74LS04 chip is all that is required to invert the strobe output and feed it back into the busy input, I’m not really a wiz with electronics but as I understand it this fools the print server in to thinking that there is a printer attached and everything is “ok”.

Print Server PCB

Printer Server PCB (Bottom)

The IC requires +5Volts and it is also nessecicary to connect +5volts to pins 10, 13 and 15. It wasn’t hard to find a +5v point on the print server board.

IC Connected to 5volts

74LS04

Connections; What needs to be connected to what:
Connections

As for the software here is simple c#.net class. Say you wanted to turn on pins 2, 4 and 6. Combine the pin values

Pin2=1
Pin3=2
Pin4=4
Pin5=8
Pin6=16
Pin7=32
Pin8=64
Pin9=128

Required value to tun on pins 2, 4 and 6 is 1+4+16=21

Call the output method specifying the port as ipaddress:port and the output value:

(Most print servers use tcp port 9100, multi port JetDirects use 9100 for port one, 9101 for port two etc)

IpPortAccess.Output(192.168.1.10:9100,21);

using System.Net;
using System.Net.Sockets;
using System;
using System.Collections.Generic;
using System.Text;

namespace PowerControl
{
class IpPortAccess
    {
        public static void Output(string port,int value)
        {
            string[] ipport = port.Split(new char[] { ':' });
            string _ip = ipport[0];
            int _port = Convert.ToInt32(ipport[1]);
            Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            soc.Connect(_ip,_port);
            byte[] sendData = new byte[1];
            sendData[0] = Convert.ToByte(value);
            soc.Send(sendData);
            soc.Close();
        }
    }
}

Watch this space for a full downloadable windows application.

All credit goes to Doktor Andy for this great idea and BIG thanks to Boyan who gave me just the right info when I was about to give up!

  • Share/Bookmark

Subscribe to Comments

9 Responses to “Print Server Power Control Hack”

  1. Hi

    I’ve been working on a similar project and will be doing another one with the 170x, can you tell me how many outputs can be controlled and also is it possible to do it via linux using command line? ie can the url 192.168.1.10:9100,21 be called and the pinouts changed?

    thanks

     

    Brian

  2. Hi Brian,

    You can control 8 outputs without additional circuitry. I guess you might be able to use some thing like a shift register chip to get more outputs but I don’t have any experience with that. The other way to get more outputs is to use a print server which with 3 parallel ports each port is accessible on different tcp port e.g. 9100,9101,9102 etc.

    As for Linux, I’ve never done it but I’m sure it’s very easy. You may be able to do something with /dev/tcp I suspect.

    Cheers,
    Rhys

     

    Rhys

  3. Hi Rhys

    Do you have a diagram or list of the 8 outputs connections? in order to control the outputs do you merly need to call the ip address, port and output value? ie could it be done via a browser for example?

     

    Brian

  4. Right, so the outputs you need to use are data0 – data7 of the parallel port, can’t remember the pins but it will be easy to find. Yes you just need the ip and port. The pins are addressed in 8 bits. data0=1, data1=2, data2=4, data3=8 etc so if you wanted to turn on data0 and data3 you would need to send a value of 9 (8+1). As for a web interface you should be able to do what you need with PHP.

     

    Rhys

  5. Ah i’m with you, does the print server need to ‘think’ it’s online before the outputs can be controlled?

     

    Brian

  6. The 74LS04 chip should fool the print server into thinking that everything is “ok” and ready to receive data.

     

    Rhys

  7. I haven’t got that chip yet however i’ve connected up the status pin and it outputs ‘online’ i’ve put an led on 3&21 and it’s lit?

     

    Brian

  8. Yea, you’ll just have to see how you go but I couldn’t get it working without inverting strobe line with the chip.

     

    Rhys

  9. Brian > try using curl to po or some php in linux to connect and post 1 byte

     

    george

Leave a Reply

Message: