Skip to content

Instantly share code, notes, and snippets.

@sgotre
Created May 31, 2017 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgotre/a5400a0a74984a01ef2a1ad1586a2f90 to your computer and use it in GitHub Desktop.
Save sgotre/a5400a0a74984a01ef2a1ad1586a2f90 to your computer and use it in GitHub Desktop.
/*
This file is part of the Evolis SDK.
The Evolis SDK is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
The Evolis SDK is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Evolis SDK. If not, see <http://www.gnu.org/licenses/>.
*/
package ethernet_example;
import java.io.*;
import java.net.*;
public class ethernetDirectComm {
public static void main(String[] args)
{
String answer = new String("");
try
{
answer = sendCommand("Rfv", "192.168.1.73", 9100, 5000);
System.out.println( "" );
System.out.println( answer );
return;
}
catch(Exception e)
{
e.printStackTrace() ;
}
}
public static String sendCommand(String cmd, String ipAdress, int port, Integer timeOut) throws IOException, InterruptedException
{
Socket socket;
String answer = new String("");
socket = new Socket(ipAdress, port);
BufferedReader plec = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
PrintWriter pred = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())), true);
pred.println("\033" + cmd + "\015"); // Send command
socket.shutdownOutput(); // The printer sends the answer only if the
// output port is closed
if ("Srs".compareTo(cmd) != 0) // Srs command don't answers
{
answer = plec.readLine(); // reading of the answer
}
pred.close(); // Exit
plec.close();
socket.close();
return answer.trim();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment