Any way to use HTML as an interface to a C/C++ program?
Asked Answered
A

7

14

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?

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 (I.E., just use the web browser and HTML as the GUI, with the actual processing done using C/C++)

Aesthete answered 3/10, 2010 at 13:6 Comment(2)
PHP doesn't have to be run server-side only; it's only most commonly used that way. gtk.php.netSymmetrical
exec ssi ( en.wikipedia.org/wiki/Server_Side_Includes )??? I don't know if it works, how it works, if it's good or bad ... really I don't know anything about this suggestion: so it's not an answerBaccate
F
11

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.

Felt answered 3/10, 2010 at 14:42 Comment(3)
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.Aesthete
@JamWaffles I recommend you just grab the latest SDK from the Qt website, the IDE has had some significant updates in the last versions.Felt
I'm pretty sure (98%) I'll be using Qt - thanks for the advice :)Aesthete
S
6

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.

Shurlocke answered 3/10, 2010 at 13:8 Comment(1)
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.Aesthete
A
5

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.

Arciniega answered 3/10, 2010 at 13:12 Comment(1)
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 :)Aesthete
I
2

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.

Impower answered 3/10, 2010 at 13:9 Comment(2)
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)?Aesthete
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!Impower
W
2

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 :) ).

Welladvised answered 3/10, 2010 at 14:14 Comment(2)
Thanks, but this prog needs to be cross platform, starting with UNIX stuff first, then physics.Aesthete
Erm... it appears I meant "UNIX stuff first, then Windoze". I have no idea where physics came from!Aesthete
K
1

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.

Kerstinkerwin answered 3/10, 2010 at 13:9 Comment(1)
Good idea. The only problem is there are so many different browsers I'd waste my whole life writing plugins for them! :PAesthete
B
1

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.

Butler answered 3/10, 2010 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.