发现还海康相机在linux上面焦距是固定的,不能像在windows那样直接在web端进行调焦,因此只能通过代码来给它加个控制。
/*************************************************************************
> File Name: 485.c
> Author: fqlovetb
> Created Time: Thurs September 2019 14:45:21
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <netinet/in.h>
//5004 is to port1
//IP address 192.168.1.125
const int port = 5004;
const char* ip = "192.168.1.125";
int main()
{
//create socket
int clt_sock = socket(AF_INET, SOCK_STREAM, 0);
if(clt_sock < 0)
{
perror("socket");
return 1;
}
//name is socket
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
//IPv4 address
addr.sin_addr.s_addr = inet_addr(ip);
//struct sockaddr_in peer;
socklen_t addr_len = sizeof(addr);
int connect_fd = connect(clt_sock, (struct sockaddr*)&addr, addr_len);
if(connect_fd < 0)
{
perror("connect");
return 2;
}
char red_buf[64];
char buf[8];
while(1)
{
//memset(buf, '\0', sizeof(buf));
fflush(stdout);
buf[0] = 0xFF;
buf[1] = 0x01;
buf[2] = 0x00;
buf[3] = 0x20;
buf[4] = 0x00;
buf[5] = 0x00;
buf[6] = 0x21;
printf("**Send successfully**\n");
//{0xFF,0x01,0x00,0x20,0x00,0x00,0x21,}变倍短
//{0xFF,0x01,0x00,0x40,0x00,0x00,0x41,}变倍长
sleep(30);
write(clt_sock, buf, strlen(buf));
}
close(clt_sock);
return 0;
}