Universal Robots Forum

Can't get tool_digital_out signal to show up on my simulation I/O

Here is the code I used for the TCP/IP communication and the method for sending ur script. Is it because I am sending the script as a string? Please let me know if any of you have some insight. thanks!

// localhost IP
private String TCP_IP = “127.0.0.1”;
// Port for secondary client
private int TCP_port = 30002;

	public void sendClose(String whichOut, String signal1){
		sendToSecondary("set_tool_digital_out("+whichOut+", "+signal1+")");
	}
	public void sendOpen(String whichOut2, String signal2){
		sendToSecondary("set_tool_digital_out("+whichOut2+", "+signal2+")");
	}
	
	private void sendToSecondary(String command){
		try{
			Socket sc = new Socket(TCP_IP, TCP_port);
			if (sc.isConnected()){
				System.out.println("Connected to UR Secondary Client");
			}
			
			DataOutputStream out;
			out = new DataOutputStream(sc.getOutputStream());
			
			String thisCommand = "def myCustomCode():\n "+command+"\n end\n";
			
			out.writeUTF(thisCommand);
			System.out.println("Send this: "+thisCommand);
			out.flush();

			out.close();
			sc.close();
			System.out.println("Disconnected from UR Secondary Client");
		} 
		catch (IOException e){
			System.out.println(e);
		}
	}

}

You have to send it as secondary program, but this is very inefficient way of setting output value.
It would be much more robust to use RTDE interface to control IO state.

Create a background thread that subscribes to tool_digital_output, and tool_digital_output_mask and set values there. You should also subscribe to receive actual_digital_output_bits to confirm actual value set.

Thanks for the input! I will try switching over to the RTDE. I am new to URCaps so its a learning process at the moment. I tried using very similar code in the sample for Sending URScript with Buttons and it worked for me there to use a button to move the robot to a pose so I am confused about why it would work for that, and then not work for setting the tool output? In the meantime I will start working on implementing the RTDE.