October 4, 2008

USB Data Acquisition... more details

Prompted by questions from the previous post, here are some more details about using the DLP Design DLP-IO8 with a Linux NSLU2 unslung device.

The following packages were added from the available ipkg list.

perl
ntp
openssh
coreutils
libftdi
kernel-module-ftdi-sio
kernel-module-usbserial

A startup file was created at /unslung/rc.modules.

#!/bin/sh
insmod usbserial
insmod ftdi_sio
return 1

The lsmod command shows the following after the DLP-IO8 is operating.

# lsmod
Module                  Size  Used by    Tainted: P
ufsd                  164872   0 (unused)
x1226-rtc               3664   0
rbuttons                1304   0 (unused)
pbuttons                 800   0 (unused)
ftdi_sio               18500   0
usbserial              18480   0 [ftdi_sio]
ixp425_eth             17116   0 (unused)
ixp400                608216   0 [ixp425_eth]

Added the PERL ddclient from dyndns.org to create dynamic dns entry and created /opt/etc/init.d that specifies the config path for ddclient. Also added directory /var/cache.

Here are expanded details of the PERL code used. Substitute your DLP device name and port command in the variables. This code should return the data. Remember when reading temperatures, the first read returns an empty value.

The code's not pretty but should be a starting place.

#!/usr/bin/perl

$USBport = "/dev/ttyUSB0";
$Command = "-";

# set the baud rate
$stty_args = '115200 raw ignbrk -brkint -parenb -parodd cs8 \
-hupcl -cstopb clocal -echo -iexten';
$result = system("stty -F $USBport $stty_args");
sleep (1); # the DLP needs to settle down after an stty command

# open the IO device
open (DLPPORT, "+<", "$USBport"); # send the DLP ascii command syswrite(DLPPORT, "$Command", 1); # read until the end of the line until (($char =~ /\r/) or ($CharCount > 15)) {
sysread(DLPPORT, $char, 1);
$line = $line . $char;
$CharCount++;
}
close(DLPPORT);

print "data is $line\n";
exit;

Two generator monitors using this DLP-IO8 have been working flawlessly for several months now.

No comments:

Post a Comment