forked from Rduivenvoorden/VCSBC360_camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_camera.py
65 lines (50 loc) · 1.83 KB
/
run_camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
### run_camera.py ###
# - establishes connection to VCSBC360 camera on IP 192.168.0.65
# - uses telnet on port 2002 to start server program on camera and start video live mode
# (see http://www.vision-components.com/en/ Getting Started document for telnet communication with VC cameras)
# This python script is meant for Odroid XU4, and should work for all VC cameras
import telnetlib
import os
import sys
import socket
# VCSBC360 default IP address and TCP/IP port number
HOST = "192.168.0.65"
SOCKET_PORT = 2002
telnet_timeout = 10 # seconds
### Ping IP address to initialize and obtain connection ###
### NOTE: Keep this section in here to ensure XU4 recognizes camera
ping_response = os.system("ping -c 3 " + HOST)
if ping_response == 0:
print "\nVCSBC360 camera is connected\n"
else:
print "\nERROR: VCSBC360 camera not connected. Check camera power ON, and ethernet cable\n"
sys.exit()
### Setup camera using Telnet to run TCP server program ###
tn = telnetlib.Telnet(HOST,"23")
# write three carriage returns for login (+ margin)
tn.read_until("password ?")
tn.write("\r\n")
tn.read_until("\n")
tn.write("\r\n")
tn.read_until("\n")
tn.write("\r\n")
# read when shell is ready for user input
tn.read_until("$")
# start TCP server program img2b.c, and run in background
tn.write("img2b &\n")
print tn.read_until("port 2002", telnet_timeout)
# write another carriage return to go back to shell
tn.write("\r\n")
#print tn.read_until("\n")
#tn.write("\r\n")
#print tn.read_until("$")
# set exposure (shutter speed) in microseconds, minimum 34 max 2000000
tn.write("sh 600\n");
# start live video mode
tn.write("vd -l\n")
print tn.read_until("live", telnet_timeout)
tn.write("\r\n")
print "Camera is running as server on port 2002, and is taking images\n"
# close Telnet connection
tn.close()
print "TCP Connection to VCSBC360 has been closed\n"