So I am trying to connect to a device that is going to acquire analogue data(Red Pitaya). It has set scpi commands that control the device. I can control these through labview and using putty.
I am trying to write and android application that can access the devices scpi server and send commands to it for the device to complete.
The device is programmed in a way in that you first have to connect to the server using a SSH connection which i have no problem doing using JSch, from there you can send a command to start the scpi server and open a connection.
Now this is the bit i am struggling with and i dont understand why, when the SCPI server has started it is accessed through the Ip of the device and a raw port of 5000, but i cannot seem to write a piece of code that connects to this and performs a SCPI command. I am not to sure whether it is the connection or the way i have sent the data.
This is the code
public class rp_command extends AsyncTask<Void,Void, Void> {
String ipAddress;
int port;
String response = "";
TextView textResponse;
rp_command(String address, int rp_port, TextView textResponse){
ipAddress = address;
port = rp_port;
this.textResponse = textResponse;
}
@Override
protected Void doInBackground(Void...arg0){
Socket socket = null;
try{
socket = new Socket(ipAddress, port);
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeByte(1);
out.writeUTF("DIG:PIN LED2,1");
out.flush();
} catch (UnknownHostException e){
e.printStackTrace();
response = "UnknownHostException:" + e.toString();
} catch (IOException e){
e.printStackTrace();
response = "IOException:" + e.toString();
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}return null;
}
@Override
protected void onPostExecute(Void result){
textResponse.setText(response);
super.onPostExecute(result);
}
}
If anyone has any advice it would be appreciated thanks
Got it working here i believe the issue was due to not ending a command with \r\n being at the end of the string here is the working test code if anyone is interested. This is for sending a string not receiving.
}
When using buttons to initiate a command i noticed that if you write the send command code in there instead of a separate function the app would time out and crash.