/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/pcipywrap.c

  • Committer: Vasilii Chernov
  • Date: 2016-02-09 16:32:11 UTC
  • mto: This revision was merged to the branch mainline in revision 353.
  • Revision ID: vchernov@inr.ru-20160209163211-j56vrnez4sbt9r1o
Add write_register python wrap. Add no_set_check attribute to pcilib_view_t type

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
/*!
27
27
 * \brief Sets python exeption text. Function interface same as printf.
28
28
 */
29
 
void setPyExeptionText(const char* msg, ...)
 
29
void __setPyExeptionText(const char* msg, ...)
30
30
{
31
31
        char *buf;
32
32
        size_t sz;
55
55
/*!
56
56
 * \brief Sets pcilib context to wraper.
57
57
 * \param[in] addr Pointer to pcilib_t, serialized to bytearray
58
 
 * \return true, serialized to PyObject, NULL with exeption text, if failed.
 
58
 * \return 1, serialized to PyObject or NULL with exeption text, if failed.
59
59
 */
60
60
PyObject* __setPcilib(PyObject* addr)
61
61
{
62
62
        if(!PyByteArray_Check(addr))
63
63
        {
64
 
                setPyExeptionText(PyExc_Exception, "Incorrect addr type. Only bytearray is allowed");
 
64
        __setPyExeptionText(PyExc_Exception, "Incorrect addr type. Only bytearray is allowed");
65
65
                return;
66
66
        }
67
67
        
150
150
 
151
151
 
152
152
/*!
153
 
 * \brief Reads register value.
 
153
 * \brief Reads register value. Wrap for pcilib_read_register function.
154
154
 * \param[in] regname the name of the register
155
155
 * \param[in] bank should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
156
 
 * \return register value, can be integer or float type
 
156
 * \return register value, can be integer or float type; NULL with exeption text, if failed.
157
157
 */
158
158
PyObject* read_register(const char *regname, const char *bank)
159
159
{
160
160
        if(!__ctx)
161
161
        {
162
 
                setPyExeptionText("pcilib_t handler not initialized");
 
162
        __setPyExeptionText("pcilib_t handler not initialized");
163
163
                return NULL;
164
164
        }
165
 
    
166
 
    pcilib_get_dma_description(__ctx);
167
165
 
168
166
        pcilib_value_t val = {0};
169
167
    pcilib_register_value_t reg_value;
173
171
        err = pcilib_read_register(__ctx, bank, regname, &reg_value);
174
172
        if(err)
175
173
        {
176
 
                setPyExeptionText("Failed: read_register (%i)", err);
 
174
        __setPyExeptionText("Failed: pcilib_read_register (%i)", err);
177
175
                return NULL;
178
176
        }
179
177
        
180
178
        err = pcilib_set_value_from_register_value(__ctx, &val, reg_value);
181
179
        if(err)
182
180
        {
183
 
                setPyExeptionText("Failed: pcilib_set_value_from_register_value (%i)", err);
184
 
                return NULL;
185
 
        }
186
 
 
187
 
    return pcilib_convert_val_to_pyobject(__ctx, &val, setPyExeptionText);
188
 
}
189
 
 
190
 
 
 
181
        __setPyExeptionText("Failed: pcilib_set_value_from_register_value (%i)", err);
 
182
                return NULL;
 
183
        }
 
184
 
 
185
    return pcilib_convert_val_to_pyobject(__ctx, &val, __setPyExeptionText);
 
186
}
 
187
 
 
188
/*!
 
189
 * \brief Writes value to register. Wrap for pcilib_write_register function.
 
190
 * \param[in] val Register value, that needs to be set. Can be int, float or string.
 
191
 * \param[in] regname the name of the register
 
192
 * \param[in] bank should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
 
193
 * \return 1, serialized to PyObject or NULL with exeption text, if failed.
 
194
 */
 
195
PyObject* write_register(PyObject* val, const char *regname, const char *bank)
 
196
{
 
197
        if(!__ctx)
 
198
        {
 
199
        __setPyExeptionText("pcilib_t handler not initialized");
 
200
                return NULL;
 
201
        }
 
202
        
 
203
        pcilib_value_t val_internal = {0};
 
204
    pcilib_register_value_t reg_value;
 
205
        
 
206
        int err; 
 
207
        err = pcilib_convert_pyobject_to_val(__ctx, val, &val_internal);
 
208
        if(err)
 
209
        {
 
210
        __setPyExeptionText("Failed pcilib_convert_pyobject_to_val (%i)", err);
 
211
                return NULL;
 
212
        }
 
213
        
 
214
        reg_value = pcilib_get_value_as_register_value(__ctx, &val_internal, &err);
 
215
        if(err)
 
216
        {
 
217
        __setPyExeptionText("Failed: pcilib_get_value_as_register_value (%i)", err);
 
218
                return NULL;
 
219
        }
 
220
        
 
221
        err = pcilib_write_register(__ctx, bank, regname, reg_value);
 
222
        if(err)
 
223
        {
 
224
        __setPyExeptionText("Failed: pcilib_write_register (%i)", err);
 
225
                return NULL;
 
226
        }
 
227
    return PyInt_FromLong((long)1);
 
228
}
 
229
 
 
230
/*!
 
231
 * \brief Reads propety value. Wrap for pcilib_get_property function.
 
232
 * \param[in] prop property name (full name including path)
 
233
 * \return property value, can be integer or float type; NULL with exeption text, if failed.
 
234
 */
191
235
PyObject* get_property(const char *prop)
192
236
{
193
237
        if(!__ctx)
194
238
        {
195
 
                setPyExeptionText("pcilib_t handler not initialized");
 
239
        __setPyExeptionText("pcilib_t handler not initialized");
196
240
                return NULL;
197
241
        }
198
242
        
203
247
        
204
248
        if(err)
205
249
        {
206
 
                        setPyExeptionText("Failed pcilib_get_property (%i)", err);
 
250
            __setPyExeptionText("Failed pcilib_get_property (%i)", err);
207
251
                        return NULL;
208
252
        }
209
253
        
210
 
    return pcilib_convert_val_to_pyobject(__ctx, &val, setPyExeptionText);
 
254
    return pcilib_convert_val_to_pyobject(__ctx, &val, __setPyExeptionText);
211
255
}
212
256
 
 
257
/*!
 
258
 * \brief Writes value to property. Wrap for pcilib_set_property function.
 
259
 * \param[in] prop property name (full name including path)
 
260
 * \param[in] val Property value, that needs to be set. Can be int, float or string.
 
261
 * \return 1, serialized to PyObject or NULL with exeption text, if failed.
 
262
 */
213
263
PyObject* set_property(const char *prop, PyObject* val)
214
264
{
215
265
        int err;
216
266
        
217
267
        if(!__ctx)
218
268
        {
219
 
                setPyExeptionText("pcilib_t handler not initialized");
 
269
        __setPyExeptionText("pcilib_t handler not initialized");
220
270
                return NULL;
221
271
        }
222
272
        
224
274
        err = pcilib_convert_pyobject_to_val(__ctx, val, &val_internal);
225
275
        if(err)
226
276
        {
227
 
                setPyExeptionText("pcilib_convert_pyobject_to_val (%i)", err);
 
277
        __setPyExeptionText("Failed pcilib_convert_pyobject_to_val (%i)", err);
228
278
                return NULL;
229
279
        }
230
280
        
232
282
        
233
283
        if(err)
234
284
        {
235
 
                setPyExeptionText("Failed pcilib_get_property (%i)", err);
 
285
        __setPyExeptionText("Failed pcilib_get_property (%i)", err);
236
286
                return NULL;
237
287
        }
238
288