×

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
Yes, that's right!

I modified the timelapse.py to a singleframe.py. Instead of starting a new capture it disconnects from the server and stops the script after the first image (look at newBLOB method)

Edit: Attachment doesn't work, so here is the python-code for singleframe.py:
import sys, time, logging
import PyIndi
 
DEVICE_NAME = "QHY CCD QHY5-0-M-"
 
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() == DEVICE_NAME:
		    self.logger.info("Set new device %s!" % DEVICE_NAME)
		    # 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 %s!" % DEVICE_NAME)
		    # 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())
	pass
    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()
	# disconnect from server
	self.disconnectServer()
    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())
	pass
    def serverConnected(self):
        print("Server connected ("+self.getHost()+":"+str(self.getPort())+")")
	self.connected = True
    def serverDisconnected(self, code):
        self.logger.info("Server disconnected (exit code = "+str(code)+","+str(self.getHost())+":"+str(self.getPort())+")")
	# set connected to False
	self.connected = False
    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)
 
if __name__ == '__main__':
	# 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, loop stops after disconnect
	while indiclient.connected:
		time.sleep(1)
Last edit: 9 years 3 weeks ago by fehlfarbe.
9 years 3 weeks ago #3802

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

  • Posts: 15
  • Thank you received: 0
Thank you! That helped me a little further.

However, it seams that the program stops when waiting for the "CCD_EXPOSURE" property.

I have chosen my Device_name = "ASI CCD"
The scripts just stops and nothing happens after:
...
new property SIMULATION for device ASI CCD
new property CONFIG PROCESS for device ASI CCD
new property Available Cams for device ASI CCD

Any suggestions? When running the test-indiclient.py script everything seems ok compared to the output shown above...
9 years 3 weeks ago #3811

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

  • Posts: 49
  • Thank you received: 20
I only tried the script with INDI CCD Simulator and a QHY5. Maybe the property CCD_EXPOSURE has another name for ASI CCD? Can you post the whole output of test-indiclient.py?
9 years 3 weeks ago #3813

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

  • Posts: 15
  • Thank you received: 0
Here it is:
pi@raspberrypi ~/swig-indi-python $ python test-indiclient.py
2015-03-31 19:33:59,207 creating an instance of PyQtIndi.IndiClient
Connecting and waiting 2secs
Server connected (localhost:7624)
2015-03-31 19:33:59,227 new device ASI CCD
2015-03-31 19:33:59,236 new property CONNECTION for device ASI CCD
2015-03-31 19:33:59,258 new property DRIVER_INFO for device ASI CCD
2015-03-31 19:33:59,265 new property DEBUG for device ASI CCD
2015-03-31 19:33:59,270 new property SIMULATION for device ASI CCD
2015-03-31 19:33:59,277 new property CONFIG_PROCESS for device ASI CCD
2015-03-31 19:33:59,283 new property Available Cams for device ASI CCD
List of devices
ASI CCD
List of Device Properties
-- ASI CCD
> CONNECTION
CONNECT(Connect)= Off
DISCONNECT(Disconnect)= On
> DRIVER_INFO
DRIVER_NAME(Name)= ASI CCD
DRIVER_EXEC(Exec)= indi_asi_ccd
DRIVER_VERSION(Version)= 1.0
DRIVER_INTERFACE(Interface)= 6
> DEBUG
ENABLE(Enable)= Off
DISABLE(Disable)= On
> SIMULATION
ENABLE(Enable)= Off
DISABLE(Disable)= On
> CONFIG_PROCESS
CONFIG_LOAD(Load)= Off
CONFIG_SAVE(Save)= Off
CONFIG_DEFAULT(Default)= Off
> Available Cams
ZWO ASI120MC(ZWO ASI120MC)= On
Disconnecting
INDI server localhost/7624 disconnected.
2015-03-31 19:34:00,249 Server disconnected (exit code = 0,localhost:7624)
pi@raspberrypi ~/swig-indi-python $
Last edit: 9 years 3 weeks ago by Magnar G. Johnsen.
9 years 3 weeks ago #3814

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

  • Posts: 49
  • Thank you received: 20
Ok and the whole output of singleframe.py?
9 years 3 weeks ago #3816

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

  • Posts: 15
  • Thank you received: 0
pi@raspberrypi ~ $ python singleframe.py
2015-03-31 19:56:42,497 creating an instance of PyQtIndi.IndiClient
Connecting and waiting 2secs
Server connected (localhost:7624)
2015-03-31 19:56:42,516 Set new device ASI CCD!
2015-03-31 19:56:42,526 new property CONNECTION for device ASI CCD
2015-03-31 19:56:42,547 Got property CONNECTION for ASI CCD!
2015-03-31 19:56:42,556 new property DRIVER_INFO for device ASI CCD
2015-03-31 19:56:42,561 new property DEBUG for device ASI CCD
2015-03-31 19:56:42,567 new property SIMULATION for device ASI CCD
2015-03-31 19:56:42,577 new property CONFIG_PROCESS for device ASI CCD
2015-03-31 19:56:42,581 new property Available Cams for device ASI CCD
9 years 3 weeks ago #3817

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

  • Posts: 49
  • Thank you received: 20
Do you habe the latest drivers and does the camera work with KStars/Ekos? (maybe this problem: indilib.org/forum/ccds-dslrs/548-zwo-asi...on.html?limitstart=0)

I'm not really well versed in INDI but maybe you have to choose an avaiable camera after connecting to ASI CCD device.
Last edit: 9 years 3 weeks ago by fehlfarbe.
9 years 3 weeks ago #3818

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

  • Posts: 15
  • Thank you received: 0
I followed the tutorial on the indi web page for installing the driver, so I assume it is the newest one. I just installed Kstars, and did not get it to work there either, but that might have something to do with my lack of experience with astronomy software... I will investigate this further.

Thanks so far :-)
9 years 3 weeks ago #3819

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

magnargj, I think you're using INDI packages for Raspberry PI which are using older ASI CCD driver. Try to compile INDI on your PI from SVN to use the latest driver which is known to work OK on the Raspberry PI.
9 years 3 weeks ago #3822

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

  • Posts: 15
  • Thank you received: 0
9 years 3 weeks ago #3824

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

  • Posts: 45
  • Thank you received: 6

Replied by gus on topic Take image with python script

I found this topic very interesting and went along the tutorial.
Compiling swig-indi-python showed many warnings, but I thought it wasn't important.
But as soon as I first ran:
python test-indiclient.py
I got:
pi@raspberrypi ~/swig-indi-python $ python test-indiclient.py
2015-04-21 14:24:52,125 creating an instance of PyQtIndi.IndiClient
Connecting and waiting 2secs
Server connected (localhost:7624)
2015-04-21 14:24:52,135 new device CCD Simulator
2015-04-21 14:24:52,136 new property CONNECTION for device CCD Simulator
2015-04-21 14:24:52,137 new property DRIVER_INFO for device CCD Simulator
2015-04-21 14:24:52,138 new property DEBUG for device CCD Simulator
2015-04-21 14:24:52,139 new property CONFIG_PROCESS for device CCD Simulator
2015-04-21 14:24:52,140 new property SIMULATOR_SETTINGS for device CCD Simulator
2015-04-21 14:24:52,141 new property ON_TIME_FACTOR for device CCD Simulator
List of devices
CCD Simulator
List of Device Properties
-- CCD Simulator
   > CONNECTION
swig/python detected a memory leak of type 'INDI_PROPERTY_TYPE *', no destructor found.
Traceback (most recent call last):
  File "test-indiclient.py", line 111, in <module>
    if p.getType()==PyIndi.INDI_TEXT:
AttributeError: 'module' object has no attribute 'INDI_TEXT'

Any advise?
Last edit: 9 years 5 days ago by gus.
9 years 5 days ago #4028

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

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

that's weird. I had to recompile the Python wrappers and now I get the same errors. Maybe something changed in new Indi version?
9 years 4 days ago #4039

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

Time to create page: 0.817 seconds