How to make Haxe communicate with Java(Processing 2) / Arduino? - java

I'm currently using Haxe with Flash target for a project.
What I want to do is to send a serial signal to my Arduino board, I couldn't find a way using only Haxe so I'm using Processing 2(http://processing.org/) which gets the job done.
The problem now is to make Haxe and Processing communicate, I've tried looking into memory mapped files, but Haxe and Java seem to work differently with those (Haxe needs an Int for address and Java uses a file).
And even creating a file to be read by processing and written by Haxe isn't working (Java gives a FileNotFound execption).
The main goal is to make Haxe send a signal to Arduino, I'm just using Processing 2 as a bridge, but any solution is welcome.
Do any one know a good way to solve this problem?
Thank you for the attention.

You can use sockets to communicate between software. Typically they are used over the internet, but it works great locally as well. For Processing, you would use the Network library, and it appears Haxe has a library as well.

Related

Trying to communicate to a USB port/Device in Java on Mac

I have a basic understanding of network programming but i have never had anything to do with USB ports.
This is what i am trying to achieve
I need to write a program in Java, to communicate to a device which is connected to USB port and then later send commands.
I tried terminal as follows earlier but it didn't quite work
ls -l /dev/tty.*
screen /dev/tty.usbserrial-FTYRDSX7 9600
The above didn't work out.
So if someone can just guide with what Java classes i should be looking into and if there are any APIs that should help me get started
Unless you're required to build it from the ground up, use a library such as usb4java (also here). Trying to manage it as a block device and interpreting whatever protocols etc., etc is not worth the effort unless there something very unique to your problem.
So i ended up using jssc which is much easier to use with strait forward syntax and methods

java: Send method through socket

I'm trying to write a program that would send a function to several nodes, those nodes will receive the function and execute it, replying a result (through serialization). I've searched around a bit, but found nothing of help. An alternative might be to send a .class file over the socket and load it on the node, but i'm interested if anyone has found a simpler way
Edit: I'm trying to make a cluster with this client/server. And I want the client to always run on the nodes and accept any kind of work without having to recompile the client node code
Solution: seems there's no way around not sending a .class file. Have to send it, then load it at runtime
Java is not like some (mostly interpreted) languages where code is data. In order to do what you want with java source code, you would have to send the source code over the wire, compile it to a class file at the other end, and then load the class file. Apart from loading a class file, there is no other way to get new code into a running JVM.
P.S.: Opening up a port on your machine where you accept arbitrary code, and then execute whatever the client sends to you is like owning a Jewelry store, and leaving it un-locked and un-staffed every day when you go out for lunch.
P.P.S.: You could embed an interpreter in your application. E.g., you could embed JRuby, and then the client could send you Ruby code.
Try Hadoop Map/Reduce Framework:
http://hadoop.apache.org/docs/r1.2.1/mapred_tutorial.html

Is it possible to record audio from client to server in PHP- or JAVA-based online web application?

I am building an online web application which offers clients to test their language skills.
The application consists of series of different test the clients can freely do. One of these tests is one where the client sees a sentence on the web-page and then is required to speak the sentence to a microphone. The idea would be to record the audio stream, send it to server and save it there to a file.
Is this possible using PHP, Java, or something similar to them?
Thank you for any help :)
I know you asked for PHP, I'm guessing that's your language of choice, but have you considered using html5 to record your audio? Note: browser support is still lacking but it might be worth looking into depending on your requirements.
Check out this tutorial; it uses the GETUSERMEDIA API to access you camera and microphone hardware.
Update: Here is another good tutorial on the subject.
The only realistic solutions for solving the problem are with flash, as suggested by another answer, or a java applet. In a year or two that will hopefully change and you'll be able to use javascript and HTML5, but this is now.
I would say this is a problem better and more easily solved with flash, but for java, You need to write a java applet to do the recording. Here are some hints to get you started:
http://docs.oracle.com/javase/tutorial/deployment/applet/
http://www.java2s.com/Tutorial/Java/0120__Development/CapturingAudiowithJavaSoundAPI.htm
http://www.jsresources.org/
You do not need java speech API or JMF, just java sound. You might WANT JMF to compress the audio file to make uploading go faster, but you can get this working without. Note that you may need to "sign" your applet in order to record audio in a browser.
If you are averse to flash, you could also use haxe to write your flash code.
Not 100% what you're looking for but I think it'll at least give you some ideas.
How to record streaming audio to the server
It is possible to solve this problem using Flash and Java both. You can use Flash component to record sound and send it in chunks to server side which can be implemented using java.
Pros to create sound recorder in Flash are many.
Flash is widely installed plugin in Browser
Java Applet gives warning before running it which many times turns off users.
Numerically checked, most media applications are created using Flash thereby providing you nice support.
Java Applets are used where thick client has to fit into browser and must also be secure. You will still find many real time treading applications are written in java applets.
Here are couple of tutorials to create Sound Recorder in Flash
http://active.tutsplus.com/tutorials/actionscript/create-a-useful-audio-recorder-app-in-actionscript-3/
Adobe record sound and save
This collected stream of sound can be stored in chunks on client side and can be synced with backend server(any server side language shall be fine.).
Implementing your server in Java has advantage. If tomorrow need arises, you can stream the same sound using Red5 server which is implemented in Java.
See more here: http://www.red5.org/
There is an audio recording SDK for this which is written in PHP, Flash and HTML5. http://recordmp3online.com
I am actually the author of that SDK (full disclosure)

SendMessage() is sending multiple messages instead of only one

I'm addapting a IR TV controller to the computer. So far I managed to read the controller data, map the keys and assign a great number of functions using JAVA robot class and prompt commands.
I want now to create play/pause, stop volume+ and volume - functions. Problem is it can't be done diretly through java. I know the right way to do it is by using JNI, but I just don't have the time to learn it right now.
The solution I found is to create exe files containing only the SendMessage function. For example, the code por the Play/Pase function would be:
#include <windows.h>
#define WM_APP_COMMAND 0x319
#define PLAY_PAUSE 0xE0000
int main() {
SendMessage((HWND)(~0), WM_APP_COMMAND, 0, PLAY_PAUSE);
return 0;
}
The program works, but instead of sending only one single message it keeps sending non-stop.
I have to question. The first, of course, is why the code is not working properly. Is there a break comand missing or something?.
Second is what does assigning ~0 (or 0xFFFF) to the windows handler means.
Thanks, i'm open to any kind of solution.
MSDN SendMesage:
If this parameter is HWND_BROADCAST ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
Broadcasting with SendMessage synchronously sends to all those windows. How this message is handled is app-dependent.
Yes - this approach is as risky as it sounds. Can you find another way to do what you want without HWND_BROADCAST ?
Rgds,
Martin
Ive come across the same problem trying to write a java webserver to control my media PC running mediaportal using only a web browser on the local network as the client but I'm limited to what is in the java.robot class only.
I think the idea of using an exe called from Java is the right one, maybe look at a program that does all the messages instead of having individual exe files.
I think this might be like what you are looking for:
http://wiki.team-mediaportal.com/index.php?title=1_MEDIAPORTAL_1/17_Extensions/System_%26_Utilities/SendMessage
~0 is HWND_BROADCAST. The message is sent to all top-level windows in the system. This program sends the message exactly once. Possibly the program is executed many times, or message is handled in multiple windows.
Use Spy++ to investigate this. Spy++ is part of Microsoft SDK and Visual Studio.

web-browser based GUI

I am working on an application in Linux which will interfaces with hardware. One of the requirements is to create the GUI in Web-browser . the application will be c++ based. I m not familiar with web realted stuff so i want to know Is it possible to do such a thing (currently it's a console application take input from txt file/cmd line). gui will be simple using button and showing output messages on browser from the application. i want to know which technologies/languages are involved and how can it be done. some of the idea i read but havn't found anything concrete yet. if u have any idea about these or a better suggestion please share
run the app in background and communicate with browser ?
call library functions directly from browser ?
any other idea ?
I would start by setting up a regular HTTP server, like lighttp or Apache httpd.
You say you already have a command line program that does the actual work - As a first step, I would reuse that, and configure the web server to call your program using CGI - see forexample http://httpd.apache.org/docs/2.2/howto/cgi.html for apache
Finally, I'd pick some javascript framework like jQuery or YUI with Ajax capabilities to do requests to the server to call the CGI script from within a webpage. You could also create a form-based web application without ajax or any framework, but that would require you to stuff all kinds of logic in your program to generate HTML pages. By using Ajax, you can leave the command line application as is, and parse any responses it gives with javascript, and then use that to dynamically change the webpage in a way that would make sense to the user.
If this all works, then I would try to figure out how to package all these components. Perhaps you just want to create a simple archive with all the programs inside, or maybe you want to go as far as actually embedding the webserver in your program. Alternatively, you may want to do it the other way around and rewrite your program as an ISAPI module that you can plug into your webserver. Or if that's not integrated enough still you could write your own (partial) HTTP server. That's really up to you (I'd probably spend time and energy on searching for the leanest, meanest existing open source http serverr and use that instead)
At any rate, the prior steps won't be lost work. Most likely, developing the web page is going form a substantial part of the work, so I would probably create a quick and dirty working solution first using the age-old CGI trick, and then develop the webpage to my satisfaction. At that point you can already have an acceptable distributable solution by simply putting all programs in a single archive (of course you would have to tweak the webserver's configuration too, like changing the default port so it won't interfere with existing webservers.) Only after that I would spend time on creating a more integrated fancy solution.
I ended up using Wt though I'd update for future reference.
These are how I thought of doing this, in order of complexity for me:
Create a simple server-side-language (PHP/Python) website that can communicate with (ie launch and process the return of) your application
Modify your application to have a built-in webserver that just punched out HTML (command line parameters taken through the URL)
Modify the app to publish JSON and use javascript on a simple HTML page to pull it in.
You could write a Java applet (as you've tagged this thread) but I think you'd be wasting time. This can be quite simple if you're willing to spend 10 minutes looking up a few simple commands.
After 12 years, web browser-based GUI started to appear, WebUI is one of them.

Categories