How do I use commands in .dylib file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Simon Knight
Posts: 470
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

How do I use commands in .dylib file

Post by Simon Knight » Sun Mar 18, 2012 1:00 pm

Hi,
I would like to communicate with a FTDI module that I own. FTDI provide what they call a library, which is a file that ends with the extension .dylib. How do I access the commands contained in the file from within a Livecode application?

Having read the guide and the tutorials I am left with the sinking feeling that I will have to have the code recompiled into a Livecode external - is this the case?

Details of the device I am attempting to use may be found here : http://www.ftdichip.com/Products/ICs/FT2232H.htm
and the following is from the FTDI help file :
Installation

Installing the library is a relatively simple operation which involves copying a file and making a symbolic link.
Use the following steps to install (these assume you have copied all of the distribution files to the desktop):

1. Open a Terminal window (Finder->Go->Utilities->Terminal).
2. If the /usr/local/lib directory does not exist, create it (sudo mkdir /usr/local/lib)
3. if the /usr/local/include directory does not exist, create it (sudo mkdir /usr/local/include)
4. Copy the dylib file to /usr/local/lib (sudo cp Desktop/D2XX/bin/libftd2xx.1.1.0.dylib /usr/local/lib/libftd2xx.1.1.0.dylib)
5. Make a symbolic link (sudo ln -sf /usr/local/lib/libftd2xx.1.1.0.dylib /usr/local/lib/libftd2xx.dylib)
6. Copy the D2XX include file (sudo cp Desktop/D2XX/Samples/ftd2xx.h /usr/local/include/ftd2xx.h
7. Copy the WinTypes include file (sudo cp Desktop/D2XX/Samples/WinTypes.h /usr/local/include/WinTypes.h)
8. You have now successfully installed the D2XX library.
Thanks in advance.

Simon
best wishes
Skids

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2747
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: How do I use commands in .dylib file

Post by mwieder » Mon Mar 19, 2012 4:29 am

Having read the guide and the tutorials I am left with the sinking feeling that I will have to have the code recompiled into a Livecode external - is this the case?
Looks that way. Or more correctly, you'd have to create a LiveCode external which would be a wrapper around the library calls. The only examples I could see on the web site are for Windows. I don't know whether you're on linux or OSX... does this lesson help any?

http://lessons.runrev.com/s/lessons/m/4 ... ib-library

Simon Knight
Posts: 470
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How do I use commands in .dylib file

Post by Simon Knight » Mon Mar 19, 2012 10:20 am

Thanks for the reply and the link to the lesson - I understood step 1 :wink: but then it was mostly double dutch. I realise that I am on a steep learning curve. I am one of the Livecode users who took one look at the "hello world" tutorial in "C" with its braces and "includes" and thought yuk - I'll buy Livecode!

Understanding the terminology is a challenge.

I expanded my research to include DLLs as there seems to be more written about them than Apple's dylibs files. I seem to have three options :

1) Give up !

2) Re-write the dylib file into the "externals" format that Livecode understands. - This is hard work especially if the source code is unavailable (ok impossible)

3) Write the wrapper external that you describe. Is the role of such a wrapper external "just" provide a number of function calls that when called, by a livecode stack, just pass the call to the vendor supplied dylib/dll - is this what is meant by a wrapper?

sorry if these are dumb questions.

best wishes
Simon
best wishes
Skids

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5132
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How do I use commands in .dylib file

Post by Mark » Mon Mar 19, 2012 11:14 am

Hi Simon,

Dutch is my native language. Maybe I can help? ;-)

Can you point me to the examples/source code on the website?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2747
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: How do I use commands in .dylib file

Post by mwieder » Mon Mar 19, 2012 5:34 pm

Dutch is my native language. Maybe I can help? ;-)
rotfl

Mark-

theperl example here http://www.ftdichip.com/Support/Softwar ... tforms.htm in testftdi_perl.zip looks pretty straightforward. There seem to be only five functions in the library, and creating the LC glue for them shouldn't be a big deal.

Simon-

Again, what platform are you on? The external library to wrap around the FTDI library calls (yes, you're correct about the definition of wrapper) can not be cross-platform, so it makes a difference.

Simon Knight
Posts: 470
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How do I use commands in .dylib file

Post by Simon Knight » Mon Mar 19, 2012 5:43 pm

Hi Mark,

At present I'm on a Livecode "Externals" crash course. The link that mweider listed lost me on step two. I have no understanding of the foundations of using the "Externals API". However, I have just watched a talk given at RevLive09 about the new Externals API which demonstrated how to code simple functions but unfortunately did not explain how to set up to create an external i.e. where do I write my C or C++ code - I'm hoping that other tutorials will explain. The presentation was given on a mac, but no mention was made of xcode.

The other part I am unclear on is how do I include or access a 3rd party dynamic library such as the one I linked to in my first post. Also why is the location of the file so important?

I was just about to post and I found the next reply from mwieder:

I am using an Apple but would probably want to use a PC version of any application some time in the future.

best wishes

Simon
best wishes
Skids

Simon Knight
Posts: 470
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How do I use commands in .dylib file

Post by Simon Knight » Mon Mar 19, 2012 5:54 pm

I just found the following thread : http://forums.runrev.com/viewtopic.php?t=8967&p=48482

Perhaps I should not be looking at the RevLive09 lectures. Have / were the new externals API introduced in Livecode v4.x ?

best wishes

Simon
best wishes
Skids

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2747
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: How do I use commands in .dylib file

Post by mwieder » Mon Mar 19, 2012 5:58 pm

Perhaps I should not be looking at the RevLive09 lectures. Have / were the new externals API introduced in Livecode v4.x ?
Sadly, not yet. We're still waiting.

But I think there's better news. The FTDI devices have drivers for various operating systems that make the device appear as a serial port. That way you can just talk to it and don't need an external library.

http://www.ftdichip.com/Drivers/VCP.htm
http://www.ftdichip.com/Support/Documen ... Guides.htm

Simon Knight
Posts: 470
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How do I use commands in .dylib file

Post by Simon Knight » Mon Mar 19, 2012 6:38 pm

The problem with using the virtual Comm port is that not all the functions of the card are made available via the port (so I believe).

I have just had a look at the programmers guide and there are around 80 odd functions that the D2XX library provides. I also had a peek at the pearl code example :

Code: Select all

#!/usr/bin/perl
# Demonstrate direct io control using ftd2xx.dll
use strict;
use Win32::API;
use Carp;
use warnings;

Win32::API->Import( 'ftd2xx', 'ULONG FT_Open(ULONG FT_Open(int iDevice, LPHANDLE handle)');
Win32::API->Import( 'ftd2xx', 'ULONG FT_SetBitMode(HANDLE handle, UCHAR mask, UCHAR mode)');
Win32::API->Import( 'ftd2xx', 'ULONG FT_Read(HANDLE handle, LPCTSTR Buffer, DWORD BytesToRead, LPDWORD BytesRead)');
Win32::API->Import( 'ftd2xx', 'ULONG FT_Write(HANDLE handle, LPCTSTR Buffer, DWORD BytesToWrite, LPDWORD BytesWritten)');
Win32::API->Import( 'ftd2xx', 'ULONG FT_Close(HANDLE handle)');
I am curious of how the Win32::API->Import call is doing. Is each ftd2xx function an atomic piece of machine code that is identified and then loaded into memory where it is accessed by the handle?

Simon
best wishes
Skids

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”