I think the problem is that you are passing a ref to 0x03 when you want to pass the value itself. I have no idea if your conversion leads to &PCICARD_SET_REGISTER returning a value. This is simply an integer, so given you can check the value in your working C code, and check what you have in your Perl would be a good sanity check. Obviously these values need to be the same. Also you don't check your file open worked although I don't see why it should fail given you have sufficient permissions to do the open in your C. I would suggest:

#!/usr/bin/perl require 'sys/ioctl.ph'; require '_h2ph_pre.ph'; sub PCICARD_IOC_NUM () { ord('0'); } sub PCICARD_SET_REGISTER () { &_IOR( &PCICARD_IOC_NUM, 1, 'int' ); } sub PCICARD_GET_REGISTER () { &_IOW( &PCICARD_IOC_NUM, 2, 'int' ); } # Sanity check..... print "PCICARD_SET_REGISTER is %d\n", &PCICARD_SET_REGISTER; # you may need $value = pack 'C', 0x03 # as this will pack 0x03 into an unsigned 8 bit (char) value $value = 0x03; open(PCI, '+</dev/pcimax') or die "Can't open card $!\n"; ioctl(PCI, &PCICARD_SET_REGISTER, $value) or die "ioctl error $!\n"; close(PCI);

As a last resort you could just dump your working C code into an Inline::C function. Sometimes this is the easiest thing to do.

cheers

tachyon


In reply to Re: Help using ioctl to write a PCI device by tachyon
in thread Help using ioctl to write a PCI device by p-rex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.