Arduino-Processing Serial.send/Serial.get interaction - java

I'm trying to get my Arduino environment to send data to processing for a data visualization project.
I have managed to get the handshake working and can Serial.println(...) to print the data I need from Arduino to the Processing console. What I need now is to somehow use that data to alter a variable within Processing.
I know that neither of the methods that I mention in the title exist within the Serial class but I was hoping someone would know how to manage this functionality.
Thanks in advance!

I will assume that you are using the serialEvent method in processing. Example code:
String val = myPort.readStringUntil('\n');
Where myPort is the port that your android device is on.

Related

Reading the List of Open Networks in Cytoscape

I am trying to get a CyNetwork[] containing all of the networks open in the Cytoscape network tab. My understanding is that I need a CyNetworkReader to call CyNetworkReader.getNetworks() and to get a CyNetworkReader I need a CyNetworkReaderManager. However, I don't know how to get a CyNetworkReaderManager, nor do I know the proper InputStream or input name to use CyNetworkReaderManager.getReader(). Any help would be much appreciated.
Close. Actually, you would need a CyNetworkReader to read in a new network from disk. If you want to get the list of currently loaded networks, you would need to use the CyNetworkManager.getNetworkSet() method. To get a handle on the CyNetworkManager, you just need to get it from OSGi, so in your CyActivator, you would do something like:
CyNetworkManager cyNetworkManager = getService(CyNetworkManager.class);
That's it.
-- scooter

Java tcp connection pass value of variable (simple echo server)

I have a java code where I am making a tcp connection to a site. Then, after that, I want to pass the value of a variable so that the site will permanently display that value. For example, if I define int x = 10; in my java program, I want to pass this value to the site so that it echos that value for ever until a new value is passed. I have no idea how to do this however, is this even possible? Where should I look, in terms of both java and php? Thanks
I suppose, when you are creating a tcp-connection, means you are the client and the site you are connected to is the server. I also hope that you are the one in charge of the server here. If that is the case, then what you are looking for is a simple Java server-client system. This will get you started with that.
If, you are not in charge of the server then you'll just have to create the client part and send data. But that itself probably, won't be sufficient because the server should be able to parse your data. So, you'll have to find out in what format is the server expecting data from the client.

Java/android: combining two libraries, android file layout?

I'm using two libraries in an android app I'm trying to make. New to android. The app is for connecting to serial devices and controlling their console via a terminal.
One library is for setting up a serial connection, setting baud rate etc and can also write read/data over serial.. The other is for creating a terminal session. I have no problem running these libraries to get simple separate examples up and running. Eg, with the first library I can set up a serial connection with a router and send/receive data via textboxes which looks like this:
https://lh5.ggpht.com/R4CAJXY9ZPDVsgt8jUZg5hc-v81aa70sctiegIGDjzv2lyvuG6OZyYas_4I-h_es-4Aq
With the second library I am able to set up local terminal on a tablet and look at the directories etc. My problem lies in incorporating both of these together to have a terminal that is connected to a serial device and with the layout/passing of data.
In the terminal library I need to supply an InputStream and OutputStream to provide input and output to the terminal. So I have to call setTermIn(java.io.InputStream) and setTermOut(java.io.OutputStream) to connect the input and output streams to the emulator.
In the serial library however there are two methods for sending and receiving and these deal with arrays of bytes.
sendData(byte[] data) for sending data and a dataListener for receiving data. I have to implement this and code the method onDataReceived(int id, byte[] data) with id being the name of the device.
So my question is, how do I hook these up? Do I create java.io.InputStream/OutputStream implementations on top of sendData and OnDataReceived, just convert the arrays to streams and call the setTermIn/Out methods?
For OnDataReceived I suppose all I do is receive the byte[] data and convert it to a stream inside the method and send this to the terminalActivity?
but what about sendData, I am not implementing this, I just send an array of bytes, how do I send it as a stream instead to setTermIn?
I am also very confused about having these things happening in different activities and how that works. Because I have the serial stuff happening in one activity, so I hit connect, it reads the relevant baud rate etc and connects to the serial device, then a terminal is opened in a new terminalActivity which is currently connected to nothing, just looks like a blank terminal. I'm not sure how everything should be laid out. Like if I hit the enter key in a terminal, should the implementation for sending data over serial not be in that same activity, not the one I am initially in where I am connecting to a serial device? But to know if I am connected to a serial device in the first place I need to send/receive data...should there be implementations of these methods in both activities?! Or maybe I should simplify it and add the connection options and the terminal to the same activity?
Should I be combining these both in one activity maybe?
Simplest way was to combine into one activity.

How can I check if a specific printer is invoked?

My problem is as follows.
A set of users[lying in the same network and all using windows xp] are using a specific network printer for printing their documents.
Now, whenever someone prints something, I need to check if that file-name starts with a specific code, and if so, I need to insert a row in one of the audit tables.
The problem is, the users can open any document and try to print them using this printer. How can I track that this printer is getting used, when my own piece of code is not invoking it at all?
Is there a way to catch this event of printing on a specific printer, irrespective of any knowledge of the source that fired this event? Is it at all possible to track this using java code?
Waiting eagerly for java gurus to respond. Thanks in advance for your kind co-operation.
Regards,
animark
use some print Server like CUPSD

How to read complete data from the device using Netty?

Am developing one java application using netty .In this application it will read data from the device and put it into database .But here the problem is once the device send half data it will read and again the device is sending half data . In threads Thread.sleep() method is there to wait for complete data . In Netty am using Non Blocking Ios(NIO). Please tell me how to wait NIOs to read complete data.
Thanks
You will need to implement your own FrameDecoder which makes sure that the ChannelBuffer will only get based to your business handler once it is complete.
See [1].
[1] https://netty.io/3.9/api/org/jboss/netty/handler/codec/frame/FrameDecoder.html
You can simply use ReplayingDecoder, which will read until data is complete.
Here you can take a look for example.

Categories