There is the c++ demo running error:
INDI::BaseClient::connectServer: creating new connection...
Found camera: Nikon DSLR DSC D5100 (PTP mode)
777.
Segmentation fault
Read More...
I wrote python and c++ demo to control my camera to exposure 1 second, and the python version worked but c++ verison didn't.
Here are my codes. And the C++ running error is in below.It means the error is in "indiclient.sendNewNumber(ccd_exposure);"
import PyIndi
import time
class IndiClient(PyIndi.BaseClient):
def __init__(self):
super(IndiClient, self).__init__()
def newDevice(self, d):
pass
def newBLOB(self, bp):
pass
def newSwitch(self, svp):
pass
def newNumber(self, nvp):
pass
def newMessage(self, d, m):
pass
def serverConnected(self):
pass
def serverDisconnected(self, code):
pass
def newProperty(self,property):
baseDevice = property.getBaseDevice()
deviceName = baseDevice.getDeviceName()
if(property.getName()=="DRIVER_INFO"):
interface = baseDevice.getDriverInterface()
if(interface & PyIndi.BaseDevice.CCD_INTERFACE):
print("Found camera:" + deviceName)
# connect the server
indiclient=IndiClient()
indiclient.setServer("localhost",7624)
indiclient.connectServer()
# Let's take some pictures
ccd="Nikon DSLR DSC D5100 (PTP mode)"
device_ccd=indiclient.getDevice(ccd)
while not(device_ccd):
time.sleep(0.5)
device_ccd=indiclient.getDevice(ccd)
ccd_connect=device_ccd.getSwitch("CONNECTION")
while not(ccd_connect):
time.sleep(0.5)
ccd_connect=device_ccd.getSwitch("CONNECTION")
if not(device_ccd.isConnected()):
ccd_connect[0].s=PyIndi.ISS_ON # the "CONNECT" switch
ccd_connect[1].s=PyIndi.ISS_OFF # the "DISCONNECT" switch
indiclient.sendNewSwitch(ccd_connect)
ccd_exposure=device_ccd.getNumber("CCD_EXPOSURE")
# while not(ccd_exposure):
# time.sleep(0.5)
# ccd_exposure=device_ccd.getNumber("CCD_EXPOSURE")
# we should inform the indi server that we want to receive the
# "CCD1" blob from this device
indiclient.setBLOBMode(PyIndi.B_ALSO, ccd, "CCD1")
ccd_ccd1=device_ccd.getBLOB("CCD1")
# while not(ccd_ccd1):
# time.sleep(0.5)
# ccd_ccd1=device_ccd.getBLOB("CCD1")
ccd_exposure[0].value=1.0
indiclient.sendNewNumber(ccd_exposure)
ccd_dis_connect=device_ccd.getSwitch("DISCONNECTION")
while not(ccd_dis_connect):
time.sleep(0.5)
ccd_dis_connect=device_ccd.getSwitch("DISCONNECTION")
print("try disconnect")
print("disconnect!")
#include "nikon_client.h"
#include <basedevice.h>
#include <unistd.h> // sleep lib
#include <string>
#include <fstream>
#include <iostream>
#include <memory>
int main(int, char *[])
{
IndiClient indiclient;
indiclient.setServer("localhost", 7624);
indiclient.connectServer();
char ccd[]="Nikon DSLR DSC D5100 (PTP mode)";
INDI::BaseDevice device_ccd = indiclient.getDevice(ccd);
while(!device_ccd){
sleep(0.5);
device_ccd=indiclient.getDevice(ccd);
}
INDI::PropertySwitch ccd_connect=device_ccd.getSwitch("CONNECTION");
while(!ccd_connect){
sleep(0.5);
ccd_connect=device_ccd.getSwitch("CONNECTION");
}
if(!device_ccd.isConnected()){
ccd_connect[0].s=ISS_ON;
ccd_connect[1].s=ISS_OFF;
indiclient.sendNewSwitch(ccd_connect);
}
INDI::PropertyNumber ccd_exposure=device_ccd.getNumber("CCD_EXPOSURE");
indiclient.setBLOBMode(B_ALSO,ccd,"CCD1");
INDI::PropertyBlob ccd_ccd1=device_ccd.getBLOB("CCD1");
while(!ccd_ccd1){
sleep(0.5);
ccd_ccd1=device_ccd.getBLOB("CCD1");
}
ccd_exposure[0].value=1.0;
std::cout << "777.\n";
indiclient.sendNewNumber(ccd_exposure);
std::cout << "888.\n";
INDI::PropertySwitch ccd_dis_connect=device_ccd.getSwitch("DISCONNECTION");
while(!ccd_dis_connect){
sleep(0.5);
ccd_dis_connect=device_ccd.getSwitch("DISCONNECTION");
std::cout << "Try disconnect.\n";
}
std::cout << "Press Enter key to terminate the client.\n";
std::cin.ignore();
}
IndiClient::IndiClient():BaseClient()
{
}
void IndiClient::newDevice(INDI::BaseDevice baseDevice)
{
return;
}
void IndiClient::newBLOB(IBLOB *bp)
{
return;
}
void IndiClient::newSwitch(ISwitchVectorProperty *svp)
{
return;
}
void IndiClient::newNumber(INumberVectorProperty *nvp)
{
return;
}
void IndiClient::newMessage(INDI::BaseDevice *dp, int messageID)
{
return;
}
void IndiClient::serverConnected()
{
return;
}
void IndiClient::serverDisconnected(int exit_code)
{
return;
}
void IndiClient::newProperty(INDI::Property property)
{
auto baseDevice = property.getBaseDevice();
auto deviceName = baseDevice.getDeviceName();
// With DRIVER_INFO defined, we have access to getDriverInterface()
if (property.isNameMatch("DRIVER_INFO"))
{
auto interface = baseDevice.getDriverInterface();
if(interface & INDI::BaseDevice::CCD_INTERFACE)
{
IDLog("Found camera: %s\n", deviceName);
}
}
}
#include "baseclient.h"
#include <basedevice.h>
class IndiClient : public INDI::BaseClient
{
public:
IndiClient();
~IndiClient() = default;
public:
void newDevice(INDI::BaseDevice baseDevice);
void newBLOB(IBLOB *bp);
void newSwitch(ISwitchVectorProperty *svp);
void newNumber(INumberVectorProperty *nvp);
void newMessage(INDI::BaseDevice *dp, int messageID);
void serverConnected();
void serverDisconnected(int exit_code);
void newProperty(INDI::Property property);
};
Hello Bill, Could you mind giving me a valid demo about how to list all devices in indi client, I am also meeting these problems.
Read More...