[Lazarus] Where is hwiringPi?

Marc Santhoff M.Santhoff at web.de
Sat Sep 19 19:00:04 CEST 2015

On Sa, 2015-09-19 at 18:53 +0200, Marc Santhoff wrote:
> On Fr, 2015-09-18 at 18:50 -0500, Bo Berglund wrote:
> > The hiwiringpi.pas file is an interface to something else written in C
> > if I understood the text correctly.
> > How does that work? It seems like I have to compile something in C on
> > the Pi as well and it produces an *.o file. Does that act like a dll
> > in Windows or like a lib file that gets linked into the final
> > executable?
> Yes, it does. A statically linked library (.a in contrast to a
> dynamically linked library .so) is nothing more than an archive holding
> a bunch of .o files. As long as the compiler creates the same type of
> object file (ELF mostly) thosse are the same created when compiling
> pascal files. This .o files can be linked into a pascal program.
> If using dynamical linking things are different, but in general it works
> the same as using dll files on Windows.
> I did use object files compiled from C to use some USB functions
> withstanding my translation trials vigorously. ;)

I forgot:

These C-Functions are activated in pascal files like this:

{ ---------- low level C functions ---------- }
function domotorrequest(device : integer ; motor: integer; speed: integer):integer; cdecl; external;
{$L domotorrequest.o}

function doserialrequest(device: longint; buffer: pAnsiChar):integer; cdecl; external;
{$L doserialrequest.o}

After that they can be used like any other function.
One of the C files:

#include <sys/types.h>
#include <sys/ioctl.h>
#include <dev/usb/usb.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include "usb-serial.h"

int doserialrequest(int dev, char* buffer)
        usb_device_descriptor_t devdescr;
        struct usb_string_desc stringdescr;
        int res;
        /*int dev;*/
        int i;
        bzero(&devdescr, sizeof(devdescr));
        res = ioctl(dev, USB_GET_DEVICE_DESC, &devdescr);
        if (res < 0) {
                printf("USB get_device_descriptor failed: %s\n",

        bzero(&stringdescr, sizeof(stringdescr));
        stringdescr.usd_string_index = devdescr.iSerialNumber;
        res = ioctl(dev, USB_GET_STRING_DESC, &stringdescr);
        if (res < 0) {
                printf("USB get_string_descriptor failed: %s\n",

        for (i = 0 ; i < stringdescr.usd_desc.bLength; i++ ) {
                //printf("%c", (char)UGETW(stringdescr.usd_desc.bString[i]));
                buffer[i] = (char)UGETW(stringdescr.usd_desc.bString[i]);
        return i;

Marc Santhoff <M.Santhoff at web.de>

More information about the Lazarus mailing list