I’m trying to communicate with the K8055 USB Experiment Interface Board via PHP. I’ve found no other attempt at this on any forum, but I have found other threads regarding accessing 3rd party .dll’s through PHP.
My system info is as follows:
OS: Windows 7
.NET: Framework 4
PHP: Version 5.3.4 (running in WAMP)
To start, I’ve copied the K8055D.dll file to my “C:\Windows\SysWOW64” folder and tested the device with the demo application. All hardware components are functioning properly.
From the threads I found on 3rd party .dll connections in PHP I’ve concluded the two ways to communicate with the DLL would be with the COM() object or the DOTNET() object. I’ve tried:
$obj = new COM(“K8055D”);
$obj = new DOTNET(“K8055D”, “K8055D”); // I’ve also replaced “K8055D” with “C:\path\to\K8055D.dll” in both of these examples
I’m having great difficulties figuring out what direction to take as I have had no .NET or Visual Studio experience at all up until purchasing this kit. I know I must first determine what object I need to use to call the .dll (COM or DOTNET). From there I need to know if the parameters I am passing are correct. Last, I need to know if there are extra steps I need to take with the .dll to ensure it can be used by these objects.
The questions I’ve been unable to answer are:
How can I tell if a .dll was created with the .NET framework?
In another forum (daniweb.com/web-development/ … ads/120748) I’ve seen mention that the .dll needs to be “COM-visible” for me to access this via PHP. Is there a way I can check the DLL is “COM-visible” or make only the DLL “COM-visible”? I attempted to change the K8055DemoVB_2008 project to be “COM-visible” and compiled it, but that’s as far as I get before the understanding of what is going on with the code/DLL goes over my head.
Do I have to register the .dll with regsvr32? If so, I’ve tried this with both the SysWOW64\regsvr32.exe and System32\regsvr32.exe and they both are giving me “The module “…\k8055d.dll” was loaded but the entry-point DLLRegisterServer was not found. Make sure that “…\k8055d.dll” is a valid DLL or OCX file an then try again.” errors.
I don’t think there is an easy way to do what you want without having a basic grasp on programming
In this case their are two types of files that both have the extension “.dll”:
A .NET Library Assembly
A regular Dynamic Link Library
A COM component (that can be registered with regsvr32.exe) is a Dynamic Link Library that - explained in a very simplistic way - adheres to certain rules. Most scripting languages provide a way to use these COM components, examples of scripting languages are Javascript, VBScript, etc. So far nothing you mentioned has anything to do with PHP.
And unfortunately the K8055D is not a COM component.
If I were you, I’d look more among the lines of Perl to use the DLL inside a webpage. But that will also require some programming skill and knowledge of how DLL’s are loaded in Windows…
Quoting php.net:
“The COM class allows you to instantiate an OLE compatible COM object and call its methods and access its properties.”
“The DOTNET class allows you to instantiate a class from a .Net assembly and call its methods and access its properties.”
Since you’ve established the K8055D.dll is not a COM component, I can rule out using an instance of the php COM class to call on the DLL’s functions. I’m assuming there is no way to recompile the DLL as a COM component given any of the example source files downloadable at vellemanusa.com/support/down … code=K8055 , is this correct?
Also, it was unclear from your answer as to which of the two types of DLL’s you listed (.NET or regular Dynamic Link Library) the K8055D.dll is. If the K8055D.dll is a .NET DLL, I see no reason I should not be able to use the DOTNET class to access the DLL’s methods.
These questions DO pertain to PHP, as I can not create an instance of a COM or a DOTNET object in PHP without throwing an exception if I am missing steps for DLL preparation (like registering the DLL, or verifying it is in fact a COM component). In addition, to troubleshoot, it helps to know which of the two classes I need to be choosing.
Could you please advise me as to what category of DLL the K8055D.dll falls into, as well as if there is a way to (semi-easily) convert this .dll into a .dll this is “COM-ready”.
The K8055D.dll is not a COM component and not a .NET Assembly, so no luck there. What you could do is write a COM component that is a wrapper around the existing DLL, or a .NET library that calls the functions inside the unmanaged K8055D.dll.
I’d like to mention a related side note on an attempt of this in Perl (from your suggestion earlier), for anyone who may find it useful:
I tried out using Win32::API to talk to the DLL via perl, and it reported a “Not a valid Win32 application” error. I have no doubt the same reasons you just mentioned that caused my issues in PHP caused this error. If I’m not mistaken, the wrapper solution you suggested would fix the issues in both of these languages.
For anyone who would still be interested in controlling this card via PHP (or Perl), I’ll post my solution to this next step should I not come across any other questions first.
You’d probably find it easier just to write a windows TCP server using a language like dephi and indy sockets. Then in PHP or perl you could open up a TCP connection to it and send it commands over the TCP connection.
Again, as others have said, in reality PHP isn’t going to do the job for several reasons that are not even COM or NET related:
PHP is a run once script - it executes and finishes. It will not loop and continue to run your board indefinitely (there are hacks for this but then you will not get feedback on your page unless you’re using ajax). Also if running it as a run once script, your connection to the board will be lost.
PHP is not event driven and its threads do not have high priority within windows like a normal windows application.
It’ll be ok if you want to write a complex ajax powered interface (similar to the windows service manager) with php instances running in a continual loop but thats rather complex in its own right and again you’ll have the .dll to deal with.
[quote=“tangoforce”]Yes thats the kind of thing I meant.
I’ve been meaning to get around to implementing a windows service/standalone .exe in delphi for a while but I never got around to it…
Good to see someone else has done it though![/quote]
I would appreciate help on this. If you know Pascal, C isn’t that far out there, you know.
As you might have noticed, I am more focused that modified K8055 firmware stuff. And wherever that is going, my version of the k8055server would be following. So if you would like to take that code and maintain a version for “vanilla K8055” boards, I would be more than happy to get you moving.
[quote=“MostlyHarmless”][quote=“tangoforce”]Yes thats the kind of thing I meant.
I’ve been meaning to get around to implementing a windows service/standalone .exe in delphi for a while but I never got around to it…
Good to see someone else has done it though![/quote]
I would appreciate help on this. If you know Pascal, C isn’t that far out there, you know.
As you might have noticed, I am more focused that modified K8055 firmware stuff. And wherever that is going, my version of the k8055server would be following. So if you would like to take that code and maintain a version for “vanilla K8055” boards, I would be more than happy to get you moving.
Interested?[/quote]
I know absolutely nothing about the C range unfortunately. I only ever really got into delphi and php/mysql really, bit of javascript in there too but never touched C/C++/C# although I have books for C++ and CBuilder I’ve never actually got tucked into them. I kind of shot myself in the foot in that respect as I would of liked to made drivers for usb devices and my own hardware - something that you can’t do in delphi
I do agree though that a TCP based solution is a far better idea than a wrapper someone else was creating for the .dll that could be used over a network - at least with a server you can implemnt a login should you wish etc.
A wrapper “can” be a good solution. I’m using one for my Tcl/Tk code. It is a multi-threaded interactive console application that Tcl opens via bidirectional pipe. Whenever some input changes, the program prints a line on standard output, which is read by Tcl with an asynchronous file readable event handler. In turn Tcl can send commands to the program’s standard input.
However, as you pointed out, PHP is a script execution per page load/refresh. At least under Apache, the PHP scripting engine itself is part of the Apache worker process. But unless the implementation is done as a multi-part document with server-push, executing a wrapper in this case means one process creation, USB path lookup, device open and so on per page refresh. That isn’t going to perform very well. Creating a socket to communicate with an existing server process is definitely much cheaper. Even if the card is local.
Hi,
We have quite a good experience in managing K8055 using JavaScript and PHP.
You can look at how we manage Velleman KSR10 robotic arm with K8055 USB board in our remote lab. remote-lab.fyzika.net/experiment-3.php?lng=en
JavaScript (AJAX) according to the event (mouse click, etc.) call the PHP script that communicates using TCP with K8055 Control Server (written in Pascal with the DLL)
JavaScript (AJAX) could communicate directly with the control server, but PHP will supply the necessary security.
Now I’m trying a general control server (ver 0.0.1), which can be controlled by the above method. Javascript (AJAX) send all the standard features of the K8055 DLL (OutputAnalogChannel, ClearAllAnalog … etc).
Our IT manager is very lazy and has made no provision for our school network. We can therefore run only one task.
I can disconnect my a robotic arm and prepare a general server for remote demonstration. [color=#FF0000]If you are interested[/color]. (But it will be until after Easter)