Recent

Author Topic: Question about using C, Activex, Java or whatever else with a pascal program  (Read 15446 times)

wpflum

  • Sr. Member
  • ****
  • Posts: 287
I'm in the process of building up an in-house signature capture system that I can graft onto our existing Point of Sale system.  After a bit of research I've found a signature capture pad that will supposedly integrate with a linux system which is what the POS system runs on but the interface code is in languages that I'm not familiar with.  They have a Net assembly, C Library, ActiveX and a Java Bean interface.  I was looking a bit at trying to interface the C library to Lazarus so I could use it instead of C but before I start any of this I figured I'd better get a heads up first from people who know more than I do about such endeavors.  Should I try it with the C library or do something with the ActiveX or Java, I'm assuming the Dot Net stuff is right out  :D

 I wish they had some kind of Perl interface since that is my language of choice on this system but I should be able to compile a Lazarus program to run on it.

Thoughts ??

Bill 
« Last Edit: December 21, 2011, 06:04:25 pm by wpflum »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12713
  • FPC developer.
ActiveX is a Windows only fundament of .NET, so out too.

Java is, like .NET a bytecode system, and hard to interface (actually Java is harder than .NET with its pinvoke)

And anyway, yes, the C lib will be closest and easiest anyway, even if the others were somewhat practical.

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Ok, I guess I'm going with the C library the capture pad company provides.  I looked up converting C to pascal and found there should be a package already installed called h2pas but I'd have to install the h2paswizard manually.  I can't seem to find it in the system??  If I go to the Install/Unistall Packages I do not see it in the list of install-able packages and I did a search for a file with h2paswizard in it and only found a lpl file not a  lpk file on my system?? 

What am i doing stupid now??  :-[

Bill

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12713
  • FPC developer.
Ok, I guess I'm going with the C library the capture pad company provides.  I looked up converting C to pascal and found there should be a package already installed called h2pas but I'd have to install the h2paswizard manually.  I can't seem to find it in the system??  If I go to the Install/Unistall Packages I do not see it in the list of install-able packages and I did a search for a file with h2paswizard in it and only found a lpl file not a  lpk file on my system?? 

What am i doing stupid now??  :-[

No idea, but just run it on the cmdline. Be warned though, it is only a tool that helps with conversion, not somethign that delivers an functioning automated conversion. Editing by sb with appopriate knowledge is typically necessary.

avra

  • Hero Member
  • *****
  • Posts: 2584
    • Additional info
For c to pascal conversion tips take a look at this topic:
http://www.lazarus.freepascal.org/index.php/topic,12763.msg66330.html#msg66330
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

wpflum

  • Sr. Member
  • ****
  • Posts: 287
I'm not all that familiar with C so to aid with this question I attached the library zip I was sent for the hardware interface so people can see what I'm talking about, I stripped out the upper level windows stuff and just left in the Linux folder.  To get it to fit I used 7z compression and broke it into two files, I hope this works  :-\  I also had to rename them by adding '.7z' to the end so the files would be recognized, just remove the last .7z to get them to work. I'll post the second part of the archive in a following post, again I hope.....

  Looking at the file structure in the zip I'm befuddled where to start??  Do I use the upper lever INCLUDE directory for the header conversion or do I go further down??  I've tried to compile the examples using make and get errors so I'm not even sure where to start to get the samples to work  even using C and C++

Will I have to compile something in C first before I can use it in a Lazarus program or if I just get the headers converted can I just add in those headers and Lazarus will use gcc to compile the C bits?? 

Right now I just need a better idea of where the starting point is.

Help  :-[
« Last Edit: December 21, 2011, 06:05:47 pm by wpflum »

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Here's the 2nd half of the archive.


« Last Edit: December 21, 2011, 06:07:03 pm by wpflum »

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Tap, Tap, Tap, is this thing on??

I'm guessing all of the big brains are in holiday mode and not available.  :D

Just thought I'd touch this to keep it current.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Quote
Tap, Tap, Tap, is this thing on??
Info to help you convert C headers to pascal was provided. If you are you expecting a good soul to stand up and do the job for you, I suggest you create a bounty http://wiki.lazarus.freepascal.org/Bounties  ;D

I had a quick look at the interface but the signature related stuff is CPP instead of C. You can't use CPP libraries directly from pascal. A C wrapper is needed. So, no easy way to connect this signature pad to pascal.

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Did you understand what I was asking about??  You seem to have a assumption about something I didn't ask about.

I'm not looking to convert the code to pascal nor am I looking for someone to 'do the job for me', what I was asking for was some direction on where to start with linking this c code to a pascal program.  I'm not familiar with C or CPP to any great extent so I wasn't even sure what directory to start from to run the header conversion program.  I'm assumming I have to create the c wrapper for each .h program and then link them with the h2pas program so I'll have pascal code I can access but again I'm back to what directory do I start in??  Whats worse is that even just trying to compile this with it's own make files to see where that leads seems to fail so I guess I'm missing something rather big somewhere.   :o

ludob

  • Hero Member
  • *****
  • Posts: 1173
Quote
Did you understand what I was asking about??
Yes, I did.
Quote
what I was asking for was some direction on where to start with linking this c code to a pascal program
Did you read the links provided earlier?  Did you understand them? I'm asking, because you continue to ask the same questions and they are answered in the links.
Quote
I'm assumming I have to create the c wrapper for each .h program and then link them with the h2pas program
No. h2pas says what it does: convert .h to .pas. To access a library, from any programming language, you need to now its exported functions and how they are defined. In C this definitition is traditionally done with .h files. h2pas translates c function definitions found in .h files to their pascal equivalents, ie procedure/function definitions with the external keyword.  Since .h files typically also contain type definitions (structures, unions) and constants, h2pas does convert them also to pascal records and constants.
What h2pas can't do is convert CPP class definitions to pascal. Simply because cpp classes are implemented differently from pascal classes and, in most cases, they simple can't talk to each other. That is where the c wrapper is coming in. The c wrapper is an intermediate layer that converts the cpp object into a series of c functions. This requires quite some c knowledge to accomplish. The result is a second, intermediate library that can be linked, after header translation, with pascal. More info here: ftp://ftp.freepascal.org/fpc/docs-pdf/CinFreePascal.pdf
Quote
Whats worse is that even just trying to compile this with it's own make files to see where that leads seems to fail so I guess I'm missing something rather big somewhere.
Running make in HidTest compiles without any problems on Ubuntu. The resulting program doesn't find a tablet but that is normal since I don't have one. Obviously you need to have the necessary build tools installed but that is not for a pascal/lazarus forum.

In the Lib directory you'll find SigLib.a. That is what eventually you need to pass to pascal to link with. No need to re-compile this.

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Now I see some light, I guess I'm missing something in my ubuntu setup to compile the hidtest since that is what I started out first trying and had it fail.

From my perspective I'm not asking the same question, I'm trying to find out what the starting point in the driver directory would be to even begin to do something with the code and since I was/am having problems just 'making' this I figured I was missing a key point somewhere. I wasn't sure which include directory with .h files to use so I wasn't sure what I was supposed to be converting in the first place so a tutorial on conversion will not help me much.

So then is the SigLib.a is the actual compiled code that the .h files point to??  This is starting to make more sense.

This is helping a great deal.  :-[

ludob

  • Hero Member
  • *****
  • Posts: 1173
Quote
So then is the SigLib.a is the actual compiled code that the .h files point to??
Yes. The .h files in Include and Linux/Include define the interface to the SigLib.a library.

When you run 'nm --defined-only SigLib.a' you'll find all the functions exported by the library. When you see functions with a name like '_ZN12UsbIoIFLinuxC1EP15TabletInterface', you're looking at a CPP class function. In this case this is the cpp mangled name for the UsbIoIFLinux constructor that has a TabletInterface* parameter. Remember: you can't call these functions from pascal.

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Great now I have a better understanding of which way to go  ;D

One last question, you said you were able to compile the hidtest on a Ubuntu system, was this a stock system??  I set up a Stock Ubuntu server to use as a test bed and the running make in the hidtest directory gave me an error, I think it couldn't find a library or something, which is why I was confused on where I was starting at I'd thought I'd missed something.  I'd like to get this to compile so I have a starting point of making sure the tablet is seen on the system correctly. I know this isn't a C forum but I'd just like to know if you added any software to the stock setup to get it to compile.

Thanks

ludob

  • Hero Member
  • *****
  • Posts: 1173
Quote
I'd just like to know if you added any software to the stock setup to get it to compile
I had already 'build-essential' installed. This is a meta-package that pulls in everything needed to build debian packages.

 

TinyPortal © 2005-2018