|
Post by seregio on Mar 10, 2022 7:49:30 GMT -5
Hello My org recently acquired a LKS 336 which has been connected and configured via Ethernet I can easily connect to it with python, which proves that it is correctly configured
>>>from lakeshore import Model336 >>>my_instrument = Model336(ip_address=my_id) >>> print(my_instrument.query("KRDG? 0")) +00.0000,+00.0000,+00.0000,+00.0000
However, I am unable to connect using Java. Is there any example available somewhere? My code below. It connects but it does not read anything from the device:
DataOutputStream dout = null; Socket s = null; StringBuffer buffer = new StringBuffer();
try { s = new Socket(my_ip, 7777); DataInputStream din = new DataInputStream(s.getInputStream()); dout = new DataOutputStream(s.getOutputStream()); String comand = "KRDG? 0\n"; byte[] a = comand.getBytes(StandardCharsets.UTF_8); dout.writeUTF(new String(a, StandardCharsets.UTF_8)); dout.flush(); while (din.available()>0) { System.out.println("Something available"); buffer.append(din.readUTF()); } System.out.println("Server says: " + buffer.toString()); } catch (Exception e) { System.out.println(e); } finally { if (dout != null) { dout.close(); } if (s != null) { s.close(); }
Thanks
|
|
|
Post by Lake Shore Jeff M on Mar 10, 2022 13:29:44 GMT -5
Lake Shore offers a Java based Chart Recorder application that does connect to the 336, however, that application does not work with newer versions of JAVA. To run the chart recorder application, you have to use Java version 8, build 1.8.0 Update 321.
We do not have any experience programming with Java so beyond providing the Chart Recorder application we cannot offer any additional assistance creating the application.
|
|
|
Post by Lake Shore Jeff M on Mar 10, 2022 13:45:12 GMT -5
Just to clarify, the Model 336 does not send out any information without being queried. For example, if you want to read the temperature of input A, you can send a CRDG? A query command and the instrument will respond with the temperature in Celsius. The command is ASCII Characters terminated with a Line Feed Character.
|
|
|
Post by seregio on Mar 11, 2022 12:20:09 GMT -5
Thank you for your answer, Jeff I'm not interested in chart recorder applicarion but in programming my own solution, since I want to integrate it in my java application Anyway, I found the solution and I'm pasting it here for the records:
DataOutputStream dout = null; Socket s = null; try { s = new Socket(lksIP, 7777); DataInputStream din = new DataInputStream(s.getInputStream()); dout = new DataOutputStream(s.getOutputStream()); String comand = "KRDG? 0 \n"; byte[] command_bytes = comand.getBytes(StandardCharsets.UTF_8); dout.write(command_bytes, 0, command_bytes.length); dout.flush(); int len_available = din.available(); if (len_available>0){ byte[] answer = new byte[len_available]; din.read(answer); System.out.println("Server says: " + new String(answer,StandardCharsets.UTF_8)); } } catch (Exception e) { System.out.println(e); } finally { if (dout != null) { dout.close(); } if (s != null) { s.close(); } }
|
|
|
Post by Lake Shore Jeff M on Mar 11, 2022 15:57:56 GMT -5
Seregio - Thanks for the solution.
|
|