GaTk has asked for the wisdom of the Perl Monks concerning the following question:

I have a CP290 X10 interface connected via a Prolific USB serial adapter. The device is recognized by my PCLINUXOS and is assigned to ttyUSB0. I have modified Bruce Garlocks serial port data logger to use Device::Serial. The code appears to run correctly in that it opens and initializes the port. To contact the CP290 and receive data I must send the following hex string:
$clock = pack('H34','FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF05');
<<<<< Is the above statement correct ????

I use the following command to send the string:

$ob->write($clock);
<<<<< Will this write send the $clock string ???

I do not get a response from the CP290. The CP290 works very well via a DOS QBASIC program when connected directly to a comport.

Thanks for any suggestions

Ted in Atlanta

Replies are listed 'Best First'.
Re: Device::Serial CP290
by toolic (Bishop) on May 02, 2008 at 13:34 UTC
    Welcome to the Monastery.

    Please use code tags for your code snippets.

    Is the above statement correct ????
    That depends on what you want $clock to contain. If you want it to simply be the string FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF05, then the following should be sufficient:
    $clock = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF05';
    If you try to print out the value of $clock in your code, you might get:
    use warnings; use strict; my $clock = pack('H34','FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF05'); print "clock:$clock:\n"; for (split //, $clock) { print "$_:", ord $_, ":\n"; }

    outputs (unprintable characters):

    clock:\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uff +ff\uffff\uffff\uffff\uffff\uffff: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: \uffff:255: :5:

    Take a look at pack.

    Update: By the way, a more compact way to assign a value to $clock uses the "repetition operator" (see perlop). These 2 lines are equivalent:

    $clock = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF05'; $clock = 'F' x 32 . '05';
      Thanks for the responses to my CP290 code example...(sans code tags ) The pack H definition is what I needed to send a the string of hex Fs... The Device::SerialPort module I'm using is the one that came with PCLINUXOS. I still get no response from the CP290 ... This is a hobby so I don't mind experimenting... I spend a lot of time on the forums and believe me the help I've gotten would fill a good sized howto. Thanks again Ted in Atlanta
Re: Device::Serial CP290
by starbolin (Hermit) on May 03, 2008 at 06:37 UTC

    I can't say about Device::Serial as I haven't used it. The 'H' pattern will pack the bytes in Little-endian order. This may not be what your driver wants. The 'N' pattern will pack your bytes into Network order which is more universal. It would seem a well written driver would do this conversion for you so I'm a little suspicious of the API.

    I googled and did a CPAN search and didn't come up with any module named Device::Serial; could you message me a link to the source? Write() would not be the correct call under native perl but the module author may have used it that way I really won't know till I read the source.

    Debugging this kind of hardware/software things can be nigh on impossible without the right tools. You certainly need something to monitor the output of your serial port to verify that it is sending something and to check baud-rate and format. You at least need to loopback the TX to the RX and verify that you can read what you wrote.


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}