×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

Take image with python script

  • Posts: 49
  • Thank you received: 20
Hey patdut,
I tried your code at it works on my system. I startet indiserver with indi_simulator_ccd
$ indiserver -v indi_simulator_ccd
2016-06-09T14:13:29: startup: indiserver -v indi_simulator_ccd 
2016-06-09T14:13:29: Driver indi_simulator_ccd: pid=11789 rfd=3 wfd=6 efd=7
2016-06-09T14:13:29: listening to port 7624 on fd 4
2016-06-09T14:13:29: Driver indi_simulator_ccd: snooping on Telescope Simulator.EQUATORIAL_EOD_COORD
2016-06-09T14:13:29: Driver indi_simulator_ccd: snooping on Telescope Simulator.TELESCOPE_INFO
2016-06-09T14:13:29: Driver indi_simulator_ccd: snooping on CCD Simulator.FILTER_SLOT
2016-06-09T14:13:29: Driver indi_simulator_ccd: snooping on CCD Simulator.FILTER_NAME
2016-06-09T14:13:29: Driver indi_simulator_ccd: snooping on Telescope Simulator.EQUATORIAL_PE
2016-06-09T14:13:29: Driver indi_simulator_ccd: snooping on Focuser Simulator.FWHM

and your code gives me:
$ python test.py 
1280.0
0.0
0.0
1.0
1280.0
1280.0
20.0
500.0
0.0
0.0
500.0
500.0
30.0
29.0020008087
28.0020008087
27.0009994507
26.0
24.9990005493
23.9979991913
22.9969997406
21.9950008392
20.9939994812
19.9930000305
18.9920005798
17.9909992218
16.9899997711
15.9890003204
14.9879999161
13.9870004654
12.986000061
11.9849996567
10.984000206
9.98299980164
8.98200035095
7.98099994659
6.98000001907
5.97900009155
4.97800016403
3.97699999809
2.97600007057
1.97500002384
0.973999977112
0.0
0.0
30.0
...

Can you debug your code to see at what position in newBLOB() the error occurs? Maybe it can't start the thread?!

Edit: and it saves the CCD simulator images to the directory as expected :)
Last edit: 7 years 10 months ago by fehlfarbe.
7 years 10 months ago #8724

Please Log in or Create an account to join the conversation.

  • Posts: 19
  • Thank you received: 0

Replied by SB on topic Take image with python script

Hello;

(Sorry for my bad English)
I have just compiled Pyindi successfully and I am able to run the examples . It was not easy because there is in internet a lot of versions which did not work in my computer, so in case It can help to somebody, I followed this recipe:
Warning: Spoiler!


I am new using these types of cameras and using wrappers. I can take photo from my camera (SBIG STL-11000) using EKOS and I can run the examples of pyindi. My doubt is: how can I control the camera with python? I guess I have to run in an independent console the command 'indiserver indi_v4l2_ccd', with the result:
2016-08-22T12:34:06: startup: indiserver indi_v4l2_ccd
2016-08-22T12:34:06: Driver indi_v4l2_ccd: Using default decoder 'Builtin decoder'
2016-08-22T12:34:06: Driver indi_v4l2_ccd: Supported V4L2 formats are:
2016-08-22T12:34:06: Driver indi_v4l2_ccd: Y16 NV21 BA81 YU12 NV12 YV12 BYR2 RGB3 RGGB JPEG MJPG RGBO RGBP YVYU YUYV GREY VYUY UYVY

after that, I run in my IDLE the modified timelapse script I found here: indilib.org/develop/tutorials/151-time-l...ith-indi-python.html
with the result of:
2016-08-22 13:35:24,188 creating an instance of PyQtIndi.IndiClient
Connecting and waiting 2secs
Server connected (localhost:7624)
2016-08-22 13:35:24,190 new device V4L2 CCD
2016-08-22 13:35:24,191 new property CONNECTION for device V4L2 CCD
2016-08-22 13:35:24,191 new property DRIVER_INFO for device V4L2 CCD
2016-08-22 13:35:24,191 new property DEBUG for device V4L2 CCD
2016-08-22 13:35:24,192 new property CONFIG_PROCESS for device V4L2 CCD
2016-08-22 13:35:24,192 new property ACTIVE_DEVICES for device V4L2 CCD
2016-08-22 13:35:24,192 new property DEVICE_PORT for device V4L2 CCD

So, I guess now python is connected with the camera. However, the command line in python is blocked as well as the command line in the console and nothing more occur. How can I control the camera?
For example, If I want to take a photograph with 5 seconds of exposition, can somebody provide an example?

Thank you very much for all your previous post They helped me a lot.


I am using this script in python:
import sys, time, logging
import PyIndi
 
class IndiClient(PyIndi.BaseClient):
    device = None
    def __init__(self):
        super(IndiClient, self).__init__()
        self.logger = logging.getLogger('PyQtIndi.IndiClient')
        self.logger.info('creating an instance of PyQtIndi.IndiClient')
    def newDevice(self, d):
        self.logger.info("new device " + d.getDeviceName())
        if d.getDeviceName() == "CCD Simulator":
		self.logger.info("Set new device CCD Simulator!")
		# save reference to the device in member variable
		self.device = d
    def newProperty(self, p):
        self.logger.info("new property "+ p.getName() + " for device "+ p.getDeviceName())
        if self.device is not None and p.getName() == "CONNECTION" and p.getDeviceName() == self.device.getDeviceName():
		self.logger.info("Got property CONNECTION for CCD Simulator!")
		# connect to device
		self.connectDevice(self.device.getDeviceName())
		# set BLOB mode to BLOB_ALSO
		self.setBLOBMode(1, self.device.getDeviceName(), None)
        if p.getName() == "CCD_EXPOSURE":
		# take first exposure
		self.takeExposure()
    def removeProperty(self, p):
        self.logger.info("remove property "+ p.getName() + " for device "+ p.getDeviceName())
    def newBLOB(self, bp):
        self.logger.info("new BLOB "+ bp.name.decode())
	# get image data
	img = bp.getblobdata()
	import cStringIO
	# write image data to StringIO buffer
	blobfile = cStringIO.StringIO(img)
	# open a file and save buffer to disk
	with open("frame.fit", "wb") as f:
		f.write(blobfile.getvalue())
	# start new exposure for timelapse images!
	self.takeExposure()
    def newSwitch(self, svp):
        self.logger.info ("new Switch "+ svp.name.decode() + " for device "+ svp.device.decode())
    def newNumber(self, nvp):
        self.logger.info("new Number "+ nvp.name.decode() + " for device "+ nvp.device.decode())
    def newText(self, tvp):
        self.logger.info("new Text "+ tvp.name.decode() + " for device "+ tvp.device.decode())
    def newLight(self, lvp):
        self.logger.info("new Light "+ lvp.name.decode() + " for device "+ lvp.device.decode())
    def newMessage(self, d, m):
        self.logger.info("new Message "+ d.messageQueue(m).decode())
    def serverConnected(self):
        print("Server connected ("+self.getHost()+":"+str(self.getPort())+")")
    def serverDisconnected(self, code):
        self.logger.info("Server disconnected (exit code = "+str(code)+","+str(self.getHost())+":"+str(self.getPort())+")")
    def takeExposure(self):
        self.logger.info("<<<<<<<< Exposure >>>>>>>>>")
	# get current exposure time
        exp = self.device.getNumber("CCD_EXPOSURE")
	# set exposure time to 5 seconds
        exp[0].value = 5
	# send new exposure time to server/device
        self.sendNewNumber(exp)
 
 
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
 
# instantiate the client
indiclient=IndiClient()
# set indi server localhost and port 7624
indiclient.setServer("localhost",7624)
# connect to indi server
print("Connecting and waiting 2secs")
if (not(indiclient.connectServer())):
     print("No indiserver running on "+indiclient.getHost()+":"+str(indiclient.getPort())+" - Try to run")
     print("  indiserver indi_simulator_telescope indi_simulator_ccd")
     sys.exit(1)
time.sleep(1)
 
# start endless loop, client works asynchron in background
while True:
	time.sleep(1)
Last edit: 7 years 7 months ago by SB.
7 years 7 months ago #9740

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 20
Hey student,

the example script takes images with the CCD Simulator driver. You have to change the device name in line 12 to your device name (V4L2 CCD):
if d.getDeviceName() == "CCD Simulator":
to
if d.getDeviceName() == "V4L2 CCD":

To understand the example: You create an Indiclient object that connects to the indiserver. The methods in the object are called asynchronous and non-blocking. So there is a endless loop at the end of the script to prevent the program terminating.
The methods in the IndiClient object are called when values changed. For example IndiClient.newDevice when a new device was connected or IndiClient.newProperty when a new property was found.

So at first the IndiClient.newDevice method is called and we look for the specific device (in your case "V4L2 CCD"). We save the device object to a member variable (self.device). Then the IndiClient.newProperty method is called. We look if it's the CONNECTION property for our device and we connect to the device and set the BLOB mode (line 20-23):
# connect to device
self.connectDevice(self.device.getDeviceName())
# set BLOB mode to BLOB_ALSO
self.setBLOBMode(1, self.device.getDeviceName(), None)
Later the method gets called again because the CCD_EXPOSURE property is found. If we set a new value to this property the camera starts a new exposure (line 24-26 and 55-62):
        if p.getName() == "CCD_EXPOSURE":
            # take first exposure
            self.takeExposure()
and the takeExposure() method:
    def takeExposure(self):
        self.logger.info("<<<<<<<< Exposure >>>>>>>>>")
        # get current exposure time
        exp = self.device.getNumber("CCD_EXPOSURE")
        # set exposure time to 5 seconds
        exp[0].value = 5
        # send new exposure time to server/device
        self.sendNewNumber(exp)
While exposure is in progress you get some periodical IndiClient.newNumber method calls where you get the left exposure time. After exposure is done the IndiClient.newBLOB method is called with the image data as parameter. To restart the exposure you have to set a new value for CCD_EXPOSURE. The example script saves the image data to a FITS file and starts a new exposure.
The following user(s) said Thank You: Jasem Mutlaq, SB
7 years 7 months ago #9741

Please Log in or Create an account to join the conversation.

  • Posts: 19
  • Thank you received: 0

Replied by SB on topic Take image with python script

Dear fehlfarbe

Thank you very much for your response. It take me a few days to test the method because I lend the camera.
Now, I think that I understand the method. However, changing the line 12 to
if d.getDeviceName() == "V4L2 CCD":
raise a new error:

Warning: Spoiler!


When I type ls /dev/vid*, it says there is no device connected as video:

Warning: Spoiler!



I can see that the camera is connected in the USB port 1, device 5. This is the result of 'lsusb':

Warning: Spoiler!


I guess that I have to change in someway the way the script search for the camera, but I can find the script line in the pi/INDI folder I created during installation of the wrappers and in anywhere. Any suggestions?

Thank you
7 years 7 months ago #9844

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 20
Hey student,

this has nothing to do with the INDI Python script. It seems that you don't have a V4L2 driver for this camera, so Linux doesn't create an /dev/video device.
I think you need to start indiserver with SBIG camera drivers:
indiserver indi_sbig_stv
and then change the device name in your Python script.
7 years 7 months ago #9845

Please Log in or Create an account to join the conversation.

  • Posts: 19
  • Thank you received: 0

Replied by SB on topic Take image with python script

thank you,

And, one more (sorry), how can i know the name of the device that I have to write in python?. I tried, without success:

SBIG STV
SBIG_STV
SBIG stv
SBIG_stv
sbig stv
sbig_stv
sbig STV
sbig_STV

and:
SBIG CCD (this is the name of the device in ekos)
sbig ccd
indi_sbig_ccd(this is other name of the device in ekos)
INDI_SBIG_CCD
SBIG STV CCD
sbig_ccd
SBIG_CCD
7 years 7 months ago #9849

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 20
My bad, I didn't have the INDI SBIG drivers on my notebook. Start the indiserver with:
indiserver indi_sbig_ccd
and then start your Python script. The device name should appear in the output text:
2016-08-22 13:35:24,190 new device DEVICE NAME
The following user(s) said Thank You: SB
7 years 7 months ago #9850

Please Log in or Create an account to join the conversation.

  • Posts: 19
  • Thank you received: 0

Replied by SB on topic Take image with python script

Dear fehlfarbe:
Thank you very much for your comments. I started the indiserver with
indiserver indi_sbig_ccd
, but did not work. when I start the python script nothing occur.
I wrote "prints" and flush in the script, in order to know where is the error. This is the script:
import sys, time, logging
import PyIndi
 
print('1')
sys.stdout.flush()         
 
 
class IndiClient(PyIndi.BaseClient):
    device = None
    def __init__(self):
 
        super(IndiClient, self).__init__()
        self.logger = logging.getLogger('PyQtIndi.IndiClient')
        self.logger.info('creating an instance of PyQtIndi.IndiClient')
        print('2')
        sys.stdout.flush()                 
 
    def newDevice(self, d):
        print('3')
        sys.stdout.flush()     
 
        self.logger.info("new device " + d.getDeviceName())
 
        if d.getDeviceName() == "SBIG CCD":
		self.logger.info("Set new device CCD Simulator!")
		# save reference to the device in member variable
		self.device = d
    def newProperty(self, p):
        print('4')
        sys.stdout.flush()            
 
        self.logger.info("new property "+ p.getName() + " for device "+ p.getDeviceName())
        if self.device is not None and p.getName() == "CONNECTION" and p.getDeviceName() == self.device.getDeviceName():
		self.logger.info("Got property CONNECTION for CCD Simulator!")
		# connect to device
		self.connectDevice(self.device.getDeviceName())
		# set BLOB mode to BLOB_ALSO
		self.setBLOBMode(1, self.device.getDeviceName(), None)
        if p.getName() == "CCD_EXPOSURE":
		# take first exposure
		self.takeExposure()
    def removeProperty(self, p):
        print('5')
        sys.stdout.flush(             
 
        self.logger.info("remove property "+ p.getName() + " for device "+ p.getDeviceName())
    def newBLOB(self, bp):
        print('6')
        sys.stdout.flush() 
 
        self.logger.info("new BLOB "+ bp.name.decode())
	# get image data
	img = bp.getblobdata()
	import cStringIO
	# write image data to StringIO buffer
	blobfile = cStringIO.StringIO(img)
	# open a file and save buffer to disk
	with open("frame.fit", "wb") as f:
		f.write(blobfile.getvalue())
	# start new exposure for timelapse images!
	self.takeExposure()
    def newSwitch(self, svp):
 
        self.logger.info ("new Switch "+ svp.name.decode() + " for device "+ svp.device.decode())
    def newNumber(self, nvp):
        self.logger.info("new Number "+ nvp.name.decode() + " for device "+ nvp.device.decode())
    def newText(self, tvp):
        self.logger.info("new Text "+ tvp.name.decode() + " for device "+ tvp.device.decode())
    def newLight(self, lvp):
        self.logger.info("new Light "+ lvp.name.decode() + " for device "+ lvp.device.decode())
    def newMessage(self, d, m):
        self.logger.info("new Message "+ d.messageQueue(m).decode())
    def serverConnected(self):
        print("Server connected ("+self.getHost()+":"+str(self.getPort())+")")
    def serverDisconnected(self, code):
        self.logger.info("Server disconnected (exit code = "+str(code)+","+str(self.getHost())+":"+str(self.getPort())+")")
    def takeExposure(self):
        self.logger.info("<<<<<<<< Exposure >>>>>>>>>")
	# get current exposure time
        exp = self.device.getNumber("CCD_EXPOSURE")
	# set exposure time to 5 seconds
        exp[0].value = 1
	# send new exposure time to server/device
        self.sendNewNumber(exp)
 
 
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
 
# instantiate the client
indiclient=IndiClient()
# set indi server localhost and port 7624
indiclient.setServer("localhost",7624)
# connect to indi server
print("Connecting and waiting 2secs")
print("7")
sys.stdout.flush()        
 
if (not(indiclient.connectServer())):
     print("No indiserver running on "+indiclient.getHost()+":"+str(indiclient.getPort())+" - Try to run")
     print("  indiserver indi_simulator_telescope indi_simulator_ccd")
     print("8")
     sys.stdout.flush()          
 
     sys.exit(1)
time.sleep(1)
 
# start endless loop, client works asynchron in background
while True:
	time.sleep(1)

And the output is:
1
2
Connecting and waiting 2secs
7


So, it seems that the script enters in the endless loop, runs the _init_(self) function but nothing more (It did not print '3', and went directly to '7'). It seems like it did not try to get the device name.
Last edit: 7 years 7 months ago by SB.
7 years 7 months ago #9852

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 20
Does it work when you open your camera with EKOS?
7 years 7 months ago #9853

Please Log in or Create an account to join the conversation.

  • Posts: 19
  • Thank you received: 0

Replied by SB on topic Take image with python script

Yes, without any problem
7 years 7 months ago #9854

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 20
And does the Python script work when you open your camera with EKOS? :)
7 years 7 months ago #9855

Please Log in or Create an account to join the conversation.

  • Posts: 19
  • Thank you received: 0

Replied by SB on topic Take image with python script

No, and the kernel died every time I have tried :-(

1
2
Connecting and waiting 2secs
7
It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.
Last edit: 7 years 7 months ago by SB.
7 years 7 months ago #9856

Please Log in or Create an account to join the conversation.

Time to create page: 0.817 seconds