views:

122

answers:

7

I'm developing a product that is interfaced over USB. I want to write a control app for it, but I cannot program a GUI for poo, so I came up with the idea of using a web page (local to the app's install directory) as the interface to the program.

So, the line of communication would be: User --> HTML page (not hosted - it's local) --> C++ program --> USB port

I'd like to do it this way because it's portable, at least UI wise, and I can write HTML fluently.

My question is this: would it be possible to use an HTML page to talk to the USB port through a C++ program?

If not, I'll learn GTK - it's portable enough.

PS. Would this be possible with PHP, or (eugh) Java?

Thanks,

James

EDIT: Just realised PHP is a server-side language - it wouldn't work in my situation because the page needs to be run as a program (IE, just use the web browser and HTML as the GUI, with the actual processing done using C/C++)

+4  A: 

I have used mongoose to control a server through HTTP/HTML. I generated the pages directly in C++, but I don't see why you couldn't invoke the PHP interpreter to render page contents.

Ferruccio
Nice idea - I'll give mongoose a look. As for the PHP functionality, it wouldn't be needed in this situation - I just need SOME way of controlling USB etc, which is done by C.
JamWaffles
+1  A: 

If you'd want to do that - your C++ program would have to take a role of http server. AFAIK - lots of router configuration utilities work this way (except for Apple's Airport Express/Extreme) - they have small httpd running with html pages served via CGI.

Eimantas
That's an idea. Would you know of a server that's cross platform and can run as an application (not something like Apache - I mean something small and lightweight)?
JamWaffles
Not really, but I'm pretty sure you could implement them yourself using simple system calls. Also - others are recommending mongoose. I'd suggest you take a shot!
Eimantas
+1  A: 

The closest thing I can think of is writing a Firefox/Chrome/IE/Safari plugin and have the user install it on his/her browser to run your GUI to control your device.

Pablo Santa Cruz
Good idea. The only problem is there are so many different browsers I'd waste my whole life writing plugins for them! :P
JamWaffles
+4  A: 

Unless you write a browser plugin (not very portable), a browser viewing a web page can't just call functions in your C++ program.

If you're going to control a device from a browser, basically your C++ program needs to incorporate a web server. So, when a link or a button is clicked, the C++ program will receive a connection on a socket it's listening to, and can do whatever.

That's a perfectly respectable thing to learn to do (probably using some third-party libraries to help with the web server aspect), but so is learning to write a GUI app, and the latter is more directly to the point here ;-)

Certainly Java can do the same thing. You can even run PHP from the command line and implement your server in PHP, although that's sort of inside out from the way PHP is normally used.

Steve Jessop
Thanks for that :) Based on what I've read, I should definitely learn GTK or something - it would be much more beneficial in the long run, as well as getting this app to work :)
JamWaffles
+1  A: 

You could embed a simple http server (for example http://code.google.com/p/mongoose/) that exposes a REST interface to your apps functionality and serves a HTML page which can make calls to the interface.

milan1612
+1  A: 

Check out HTMLayout. The low-level component, HTMLayout itself, is free. It's Windows-only at the moment, as far as I know, but the work is in progress to port it to Linux and Mac. (A Windows Mobile port already exists). They also have Sciter, which is built around HTMLayout and contains scripting facilities. Check out the demos, they are impressive!

(Sorry if it sounded like a plug. I'm not affiliated with them, but I really like HTMLayout :) ).

atzz
Thanks, but this prog needs to be cross platform, starting with UNIX stuff first, then physics.
JamWaffles
Erm... it appears I meant "UNIX stuff first, then Windoze". I have no idea where physics came from!
JamWaffles
+2  A: 

You can actually create web applications in C++ using a toolkit called Wt (similar API to Qt). There is a standalone browser as well as a module for Apache. This way you can use C++ as your programming language the same way you would C# with ASP.NET, and thus you can also use your existing C++ code. It's not really elegant though.

I'd actually recommend you learn Qt and write the whole application on top of it. It's incredibly portable and has an extensive API for just about everything - it's an application framework; GTK+ does just the UI, and in C, although the GTKmm wrapper for C++ is nice. Check it out at http://qt.nokia.com - it's available under the GNU LGPL.

iconiK
Thanks for the info about GTK - I thought it was a toolit kind of thing. I'll definitely stick with Qt then. I've dipped my toes in it before, so I'll dust off the Qt IDE and get developing.
JamWaffles
@JamWaffles I recommend you just grab the latest SDK from the Qt website, the IDE has had some significant updates in the last versions.
iconiK
@iconiK I'm pretty sure (98%) I'll be using Qt - thanks for the advice :)
JamWaffles