Categories

Categories

Archives

FreeBSD Parallel Port interface

I’m too impatient for Dallas Semi to send samples of the DS2408 so I implemented a switch using the parallel port on my FreeBSD server.

The idea is to use the DS2408 or parallel port to drive a relay to switch the HVAC “call for heat” line. This way I can cron my heating schedule.

Brian and Smart-Works were nice enough to loan me two temperature sensors and some space on their web server for the temperature log.

I thought I would be able to echo 1 > /dev/lpt0. Ha. No…

FreeBSD includes the ability to use the “geek” port. I wish I were making that up, but that’s what `man ppi` says. FreeBSD uses ioctl to access the parallel port interface. Here’s the sample from the ppi man page:

#include stdio .h
#include dev/ppbus/ppi.h
#include dev/ppbus/ppbconf.h
#include fcntl .h
//The includes above need less than greater than brackets.

int main (void)
{
int fd;
u_int8_t val;

fd = open (“/dev/ppi0”, O_RDWR);
val = 0x1;

ioctl (fd, PPISDATA, &val);
ioctl (fd, PPIGCTRL, &val);
val |= STROBE;
ioctl (fd, PPISCTRL, &val);
val &= ~STROBE;
ioctl (fd, PPISCTRL, &val);
}

I’m actually going to use some logic so that I can use more than eight devices connected to the parallel port.

4 comments to FreeBSD Parallel Port interface

  • Is this the end of the post? What did you decide on for your multiplexing? Why not use the altera cpld for all your address logic? Btw, i’m writing this response and reading the blog directly on my nokia 6230. Works great!

  • Well, even though it submitted two copies of my comment for some reason, using my nokia 6230 worked good 🙂

    Another thing to consider is that the TINI will by default only upload to the FTP server once per hour. For real-time “call for heat” controlling of your thermostat, you probably want more frequent than that.

    In that case, either use XML-RPC, increase the FTP upload frequency (and maybe even upload to your own Linux/BSD FTP server and use your watchfor scripts), or have a thermostat with an hour lag 🙂

  • erich

    It was the end of the post for the time being until I had more information to add to it.

    I wanted to add logic to it to ensure that even if the parallel port flashed some random data, it wouldn’t trigger the ‘call for heat.’ I’ve decided to use a dual four to one line multiplexer, 74F153. I chose it because it was a logic chip that I had handy.

    The 74F153 uses two enable lines, two status lines, and two data input lines to select the two Y outputs. My thought is to wire one Y output to one of the input lines.

    I just finished the logic diagram, I used to be much better at this a few years ago, and it looks like:
    Ea = L
    Eb = L
    S1 = L
    S2 = H
    I2a = H
    I2b = Ya

    This yields five inputs to the circuit from the parallel port with one output to the relay. One output from the parallel port will be used to enable, or power on, the 74F153. Two outputs from the parallel port fall under ‘don’t care.’ In this case, there will be four addresses to enable the relay. While this is not ideal because it leaves room for error, it drastically reduces the number of addresses from 128 to 4. I could add a three input AND gate to fix it, but I’m far too lazy to do that. That’s also the same reason why I choose not to use my Xilinx CPLD.

    Instead of trying to implement an XML-RPC to read from the TINI, I just wrote a quick and dirty PERL script to telnet to the TINI and cat the data to an array.

    #!/usr/bin/perl

    use Net::Telnet;

    #Initialise telnet
    $telnet = new Net::Telnet->new( Timeout=>20,Prompt => ‘/[\$%#>] $/’);
    die &Log_Message(“Can’t open telnet session to the remote host”) unless
    $telnet;

    #Telnet and login to a remote machine
    $telnet->open(“<ServerIP&amp>”);
    $telnet->login(“<Username&amp>”,”<password>”);
    print “Logged into the system \n”;

    @lines = $telnet->cmd(“cat /logs/data.txt”);
    print @lines;
    $telnet->close;

    The array @lines has the most recent temperature reading from each of the sensors. Then the PERL exec() command can execute the C program to write data, call for heat, to the parallel port. I tried to use the PERL module to access the parallel port directly, but it only seems to work in Linux not BSD.

  • The only issue with telnetting into the TINI and gettings its raw data file is that if you caught it immediately after an FTP upload, that file will not exist. In that case, I suppose you could just wait 5 minutes and try again.

    For a future version, you might look at the XML-RPC libraries for Perl. I’m sure they’re quite simple to use.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.