×

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
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.

  • Posts: 19
  • Thank you received: 0

Replied by SB on topic Take image with python script

I have an update. I re-installed all the programs: INDI and pyindi and now its working !
For the records, the name of the camera that one have to write in line 12 of the script can be found in ekos. Also, in the same place it can be found the drivers which that camera use, in order to use them when start the INDI server in the console (i.e. indiserver indi_sbig_ccd.

I dont know where the problem was.
Thank you very much

One last thing. Now, when you call the script, it enters in an endless loop and so, the command line is blocked. Can you guess some way to do that the script only take a photo and release the command line in order to wait for others instructions?
7 years 7 months ago #9871

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

  • Posts: 49
  • Thank you received: 20
finally :)

You could add a boolean variable to the IndiClient class that gets true/false when the image is ready and check the variable it in the endless loop.
7 years 7 months ago #9873

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 very much. The code works perfectly
Now, it is the very last question. How can I change the binning of the camera?

Really, thank you very much for share your code with the rest of us.
7 years 7 months ago #9940

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

  • Posts: 49
  • Thank you received: 20
When you start the Python script there should be a list of camera properties (new Property XXX) in your log. There should be the property CCD_BINNING or something similar. Just set a new value the same way you start a new exposure:
def newProperty(self, p):
    if p.getName() == "CCD_BINNING":
	    bin = self.device.getNumber("CCD_BINNING")
            bin[0].value = 5
            self.sendNewNumber(bin)
Last edit: 7 years 7 months ago by fehlfarbe.
7 years 7 months ago #9983

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

  • Posts: 1
  • Thank you received: 0
Thanks for your tutorial

Actually I get the "bus error" message after running test-indiclient.py

I'm running it on Raspberry Pi 3
any idea what's wrong?

Thanks :)
5 years 10 months ago #26541

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

  • Posts: 49
  • Thank you received: 20
Can you post the full error message?
5 years 10 months ago #26551

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

Time to create page: 1.048 seconds