视觉控制器控制光源tcp部分代码

merge-requests/5/merge
yiming 4 years ago
parent a6bf5deee8
commit 8c40948608

@ -16,7 +16,7 @@ public class HikLoginModuleImpl implements CameraControlLoginModule {
public static HCNetSDK hcNetsdk = HCNetSDK.INSTANCE;
private static int MAX_RECONNET_TIME = 100000;
private static int MAX_RECONNET_TIME = 100;
static HikExceptionCallBack hikExceptionCallBack = new HikExceptionCallBack();

@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
@ -18,7 +19,7 @@ public class HikControlSocket {
* <${},${0 1},${get\post}>
*/
public static void main(String[] args) {
String code = openLight("192.168.8.236", 2002,2,0);
String code = openLight("172.16.0.82", 9000,2,0);
System.out.println(code);
}
@ -29,13 +30,13 @@ public class HikControlSocket {
InputStream is = null;
try {
socket.connect(new InetSocketAddress(ip,port),3000);
socket.setSoTimeout(10000);
os = socket.getOutputStream();
Thread.sleep(100);
controlCmd(os,bool,index);
is = socket.getInputStream();
code = read(is);
if(code!= null){
code = code.replace("\\n","");
}
String s = read(socket.getInputStream());
} catch (IOException e) {
log.error("sick time out,ip:{},info:{}",ip,e);
}finally {
@ -84,8 +85,27 @@ public class HikControlSocket {
}
private static String read(InputStream inStream) throws IOException {
BufferedReader bd = new BufferedReader(new InputStreamReader(inStream));
return bd.readLine();
StringBuffer sb = new StringBuffer();
int start = -1;
int end = -1;
do{
int count = inStream.available();
if(count > 0){
byte [] buffer = new byte[count];
inStream.read(buffer);
String s = new String(buffer, Charset.forName("utf-8"));
sb.append(s);
System.out.println(s);
if(start < 0){
start = sb.indexOf("<");
}
if(end <= start){
end = sb.indexOf(">");
}
}
}while (start <0 || end <= start);
return sb.substring(start,end);
}
}

Loading…
Cancel
Save