I have been trying to create a module to read/write to a serial port and the
code I write builds fine on its own but the second I let xs get at it, it
bails. Please help me. The Auto-generated code has something wrong with it.

ERROR - out.make

make[1]: Entering directory
`/home/ibothwel/PERL/GENCOM/_Inline/build/GENCOM_b553'
/usr/local/bin/perl -I/usr/local/lib/perl5/5.6.1/i686-linux
-I/usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/5.6.1/ExtUtils/xsubpp
-typemap /usr/local/lib/perl5/5.6.1/ExtUtils/typemap  GENCOM_b553.xs >
GENCOM_b553.xsc && mv GENCOM_b553.xsc GENCOM_b553.c
g++ -c -I/home/ibothwel/PERL/GENCOM -I/usr/include/g++-3
-I/usr/include/g++-3 -O2   -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" -fpic
-I/usr/local/lib/perl5/5.6.1/i686-linux/CORE  GENCOM_b553.c
GENCOM_b553.c: In function `void XS_GENCOM_OpenSerialCon(CV *)':
GENCOM_b553.c:132: implicit declaration of function `int OpenSerialCon(...)'
GENCOM_b553.c: In function `void XS_GENCOM_CloseSerialCon(CV *)':
GENCOM_b553.c:147: implicit declaration of function `int
CloseSerialCon(...)'
GENCOM_b553.c: In function `void XS_GENCOM_ReadFromSerial(CV *)':
GENCOM_b553.c:162: implicit declaration of function `int
ReadFromSerial(...)'
GENCOM_b553.c: In function `void XS_GENCOM_WriteToSerial(CV *)':
GENCOM_b553.c:179: implicit declaration of function `int WriteToSerial(...)'
make[1]: *** [GENCOM_b553.o] Error 1
make[1]: Leaving directory
`/home/ibothwel/PERL/GENCOM/_Inline/build/GENCOM_b553'


GENCOM.PM
package GENCOM;

use 5.006;
use strict;
use warnings;
use Carp;

require Exporter;
require DynaLoader;
use AutoLoader;
use Inline      (CPP => Config =>
                        INC => '-I/usr/include/g++-3',
                        LIBS => '-lusr/unclude',
                        CCFLAGS => '-I/usr/include/g++-3',
                        );
our @ISA = qw(Exporter DynaLoader);

# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

# This allows declaration       use GENCOM ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(
) ] );

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our @EXPORT = qw(
);
our $VERSION = '0.01';

sub AUTOLOAD {
    # This AUTOLOAD is used to 'autoload' constants from the constant()
    # XS function.  If a constant is not found then control is passed
    # to the AUTOLOAD in AutoLoader.

    my $constname;
    our $AUTOLOAD;
    ($constname = $AUTOLOAD) =~ s/.*:://;
    croak "& not defined" if $constname eq 'constant';
    my $val = constant($constname, @_ ? $_[0] : 0);
    if ($! != 0) {
        if ($! =~ /Invalid/ || $!{EINVAL}) {
            $AutoLoader::AUTOLOAD = $AUTOLOAD;
            goto &AutoLoader::AUTOLOAD;
        }
        else {
            croak "Your vendor has not defined GENCOM macro $constname";
        }
    }
    {
        no strict 'refs';
        # Fixed between 5.005_53 and 5.005_61
        if ($] >= 5.00561) {
            *$AUTOLOAD = sub () { $val };
        }
        else {
            *$AUTOLOAD = sub { $val };
        }
    }
    goto &$AUTOLOAD;
}       

bootstrap GENCOM $VERSION;

# Preloaded methods go here.

use Inline CPP => <<'END';
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <unistd.h>

#define MAX_BUF 255

class GenSerialIO {

        protected:
                int fd;

        public:
                char *modemdevice;
                speed_t sbaudrate;
                struct termios oldtio,newtio;
                char readbuf[MAX_BUF];
                
                GenSerialIO ( char * mdev ) {
                        modemdevice = mdev;
                        sbaudrate = B19200;
                }

                ~GenSerialIO () {
                        tcsetattr(fd,TCSANOW,&oldtio);
                        if (fd>=0) {
                                CloseSerialCon();
                        }       
                }

int OpenSerialCon() {
    
    this->fd = open(this->modemdevice, O_RDWR | O_NOCTTY );
    if (fd <0) {return this->fd;}

    tcgetattr(this->fd,&this->oldtio); 

    this->newtio.c_cflag = this->sbaudrate | CRTSCTS | CS8 | CLOCAL | CREAD;
    
    this->newtio.c_iflag = IGNPAR | ICRNL;
    
    this->newtio.c_oflag = 0;
    
    this->newtio.c_lflag = ICANON; 
    
        this->newtio.c_cc[VINTR]    = 0;     /* Ctrl-c */ 
    this->newtio.c_cc[VQUIT]    = 0;     /* Ctrl-\ */
    this->newtio.c_cc[VERASE]   = 0;     /* del */
    this->newtio.c_cc[VKILL]    = 0;     /* @ */
    this->newtio.c_cc[VEOF]     = 4;     /* Ctrl-d */
    this->newtio.c_cc[VTIME]    = 0;     /* inter-character timer unused */
    this->newtio.c_cc[VMIN]     = 1;     /* blocking read until 1 character
arrives */
    this->newtio.c_cc[VSWTC]    = 0;     /* '\0' */
    this->newtio.c_cc[VSTART]   = 0;     /* Ctrl-q */
    this->newtio.c_cc[VSTOP]    = 0;     /* Ctrl-s */
    this->newtio.c_cc[VSUSP]    = 0;     /* Ctrl-z */
    this->newtio.c_cc[VEOL]     = 0;     /* '\0' */
    this->newtio.c_cc[VREPRINT] = 0;     /* Ctrl-r */
    this->newtio.c_cc[VDISCARD] = 0;     /* Ctrl-u */
    this->newtio.c_cc[VWERASE]  = 0;     /* Ctrl-w */
    this->newtio.c_cc[VLNEXT]   = 0;     /* Ctrl-v */
    this->newtio.c_cc[VEOL2]    = 0;     /* '\0' */

    tcflush(this->fd, TCIFLUSH);
    tcsetattr(this->fd,TCSANOW,&newtio);

    return this->fd;

}


int CloseSerialCon() {
        int res;
        res = close(this->fd);
        return res;
}       

int ReadFromSerial() {
        int res;
        res = read(this->fd,this->readbuf,MAX_BUF); 
        this->readbuf[res]=0;             
        return res;
}       

int WriteToSerial( char* keypress, int keylength) {
        int res;
        tcflush(this->fd, TCIFLUSH);
        res = write(this->fd,keypress,keylength);
        return res;
}       

};

END

# Autoload methods go after =cut, and are processed by the autosplit
program.

1;

__END__



Makefile.PL

use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
$CC = 'g++';
WriteMakefile(
    'NAME'              => 'GENCOM',
    'VERSION_FROM'      => 'GENCOM.pm', # finds $VERSION
    'PREREQ_PM'         => {}, # e.g., Module::Name => 1.1
    ($] >= 5.005 ?    ## Add these new keywords supported since 5.005
      (ABSTRACT_FROM => 'GENCOM.pm', # retrieve abstract from module
       AUTHOR     => 'I. N. Bothwell <[EMAIL PROTECTED]>') : ()),
    'LIBS'              => [''], # e.g., '-lm'
    'DEFINE'            => '', # e.g., '-DHAVE_SOMETHING'
        # Un-comment this if you add C files to link with later:
    # 'OBJECT'          => '$(O_FILES)', # link all the C files too
        'CC'                    => $CC,
        'LD'                    => '$(CC)',
        # Insert -I. if you add *.h files later:
    'INC'               => '-I/usr/include/g++-3', # e.g.,
'-I/usr/include/other'
        'XSOPT'                 => '-C++',
);






Reply via email to