PilatusCamera.h 5.59 KB
Newer Older
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
22
23
#ifndef PILATUSCAMERA_H
#define PILATUSCAMERA_H
24

25
#include "lima/Debug.h"
26

27
28


29
30
namespace lima
{
31
namespace Pilatus
32
{
33
class Interface;
34
class Camera
35
{
36
    friend class Interface;
37
    DEB_CLASS_NAMESPC(DebModCameraCom,"Camera","Pilatus");
38
39

public:
Arafat Noureddine's avatar
Arafat Noureddine committed
40
41
42
43
    enum Status
    {
        ERROR,
        DISCONNECTED,
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
44
        STANDBY,
45
        SETTING_ENERGY,
Arafat Noureddine's avatar
Arafat Noureddine committed
46
47
48
49
50
51
        SETTING_THRESHOLD,
        SETTING_EXPOSURE,
        SETTING_NB_IMAGE_IN_SEQUENCE,
        SETTING_EXPOSURE_PERIOD,
        SETTING_HARDWARE_TRIGGER_DELAY,
        SETTING_EXPOSURE_PER_FRAME,
52
	SETTING_ROI,
Arafat Noureddine's avatar
Arafat Noureddine committed
53
        KILL_ACQUISITION,
54
        RUNNING,
55
	RESET_HIGH_VOLTAGE,
56
	ANYCMD
Arafat Noureddine's avatar
Arafat Noureddine committed
57
58
59
60
61
62
63
64
65
66
67
68
69
    };

    enum Gain
    {
        DEFAULT_GAIN,
        LOW,
        MID,
        HIGH,
        UHIGH
    };

    enum TriggerMode
    {
Arafat Noureddine's avatar
Arafat Noureddine committed
70
71
72
73
        INTERNAL_SINGLE,
        INTERNAL_MULTI,
        EXTERNAL_SINGLE,
        EXTERNAL_MULTI,
Arafat Noureddine's avatar
Arafat Noureddine committed
74
75
76
        EXTERNAL_GATE
    };

77
    Camera(const char *host = "localhost",int port = 41234);
78
    ~Camera();
Arafat Noureddine's avatar
Arafat Noureddine committed
79
80
81
    
    void connect(const char* host,int port);
    
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
82
    const char* serverIP() const;
Arafat Noureddine's avatar
Arafat Noureddine committed
83
    int serverPort() const;
84

Arafat Noureddine's avatar
Arafat Noureddine committed
85
    void setImgpath(const std::string& path);
86
    const std::string& imgpath() const;
Arafat Noureddine's avatar
Arafat Noureddine committed
87
88
    
    void setFileName(const std::string& name);
89
    const std::string& fileName() const;
Arafat Noureddine's avatar
Arafat Noureddine committed
90
91
92
    
    Status status() const;

93
94
95
    double energy() const;
    void setEnergy(double val);

Arafat Noureddine's avatar
Arafat Noureddine committed
96
97
    int threshold() const;
    Gain gain() const;
98
99
100
    void setThresholdGain(int threshold,Gain gain = DEFAULT_GAIN); // backward compatibility
    void setThreshold(int threshold,int energy = -1);
  
Arafat Noureddine's avatar
Arafat Noureddine committed
101
102
103
104
105
106
    double exposure() const;
    void setExposure(double expo);

    double exposurePeriod() const;
    void setExposurePeriod(double expo_period);

107
    int nbImagesInSequence() const;
Arafat Noureddine's avatar
Arafat Noureddine committed
108
109
110
111
112
113
114
115
116
117
118
119
120
    void setNbImagesInSequence(int nb);

    double hardwareTriggerDelay() const;
    void setHardwareTriggerDelay(double);

    int nbExposurePerFrame() const;
    void setNbExposurePerFrame(int);

    TriggerMode triggerMode() const;
    void setTriggerMode(TriggerMode);

    void startAcquisition(int image_number = 0);
    void stopAcquisition();
121
    void errorStopAcquisition();
Arafat Noureddine's avatar
Arafat Noureddine committed
122
123
124
125
126
127
128

    bool gapfill() const;
    void setGapfill(bool onOff);
    
    void send(const std::string& message);
    
    void sendAnyCommand(const std::string& message);    
129
    std::string sendAnyCommandAndGetErrorMsg(const std::string& message);
Arafat Noureddine's avatar
Arafat Noureddine committed
130

131
    int nbAcquiredImages() const;
132
    void version(int& major,int& minor,int& patch) const;
133
134
135

    bool hasRoiCapability() const;
    void setRoi(const std::string&);
136
137
138

    bool hasHighVoltageReset();
    void resetHighVoltage(double sleeptime = -1.);
139
private:
140
    static const double             TIME_OUT = 10.;
141
142
    enum HIGH_VOLTAGE { NOT_INITIALIZED,
			HAS_HIGH_VOLTAGE,DONT_HAVE_HIGH_VOLTAGE };
143

Arafat Noureddine's avatar
Arafat Noureddine committed
144
145
146
147
    const        std::string& errorMessage() const;
    void         softReset();
    void         hardReset();
    void         quit();    
148
    void	 _connect(const char* host,int port);
Arafat Noureddine's avatar
Arafat Noureddine committed
149
150
151
152
153
154
    
    static void* _runFunc(void*);
    void         _run();    
    void         _initVariable();
    void         _resync();
    void         _reinit();
Jordi's avatar
Jordi committed
155
    void	 _pilatus2model();
156
    void	 _pilatus3model(); ///< set pilatus3 threshold extention
157
    void         _work_around_threshold_bug();
158

Arafat Noureddine's avatar
Arafat Noureddine committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
    std::map<std::string,Gain>    GAIN_SERVER_RESPONSE;
    std::map<Gain,std::string>    GAIN_VALUE2SERVER;


    //socket/synchronization with pilatus variables
    std::string             m_server_ip;
    int                     m_server_port; 
    int                     m_socket;
    bool                    m_stop;
    pthread_t               m_thread_id;
    int                     m_pipes[2];
    Status                  m_state;
    mutable Cond            m_cond;

    //Cache variables
    std::string             m_error_message;
175
    int			    m_energy;
Arafat Noureddine's avatar
Arafat Noureddine committed
176
177
178
179
180
181
182
183
184
185
186
187
    double                  m_exposure;
    int                     m_exposure_per_frame;
    double                  m_exposure_period;
    Gain                    m_gain;
    bool                    m_gap_fill;
    double                  m_hardware_trigger_delay;
    int                     m_nimages;
    int                     m_threshold;
    TriggerMode             m_trigger_mode;
    std::string             m_imgpath;
    std::string             m_file_name;
    std::string             m_file_pattern;    
188
189
    int			    m_nb_acquired_images;
    bool		    m_has_cmd_setenergy;
Jordi's avatar
Jordi committed
190
    bool                    m_pilatus2_model;
191
    bool                    m_pilatus3_threshold_mode;
192
    bool		    m_has_cmd_roi;
193
194
195
    int			    m_major_version;
    int                     m_minor_version;
    int                     m_patch_version;
196
    HIGH_VOLTAGE            m_cmd_high_voltage_reset;
197
198
199
};
}
}
200
#endif//PILATUSCAMERA_H