4
4
- Uses RAGUI - Research Assistant Graphical User Interface Library.
5
5
- Uses Qt v.5.0.2 - http://qt-project.org/
6
6
- Uses RANet - Research Assistant Net Library.
7
- Copyright(C) 2010-2014, Dmitrii Nelson, St.Petersburg, Russia.
7
- Copyright(C) 2010-2017, Dmitrii Nelson, St.Petersburg, Russia.
8
8
d.nelson@mail.ioffe.ru
9
9
*///////////////////////////////////////////////////////////////////////////////
10
10
#include "LomoCCDDriver.h"
30
26
DeviceSettings = DeviceCfg >> "Settings";
31
27
if( DeviceSettings.IsCorrect() ){
32
28
//! @todo{Instruments} Why SetAttr?
29
DeviceSettings |= attr("NumberOfPixels",3648);
33
30
DeviceSettings |= attr("CCD_SH",64);
34
31
DeviceSettings |= attr("CCD_ICG",64);
35
DeviceSettings |= attr("IntegrationTime",1);
32
DeviceSettings |= attr("MiddlePixel",1733);
33
DeviceSettings |= attr("WL_0",sPhysValue(0.02389,"nm"));
34
DeviceSettings |= attr("WL_k",sPhysValue(-7.8e-6,_Unitsless_));
36
35
DeviceSettings |= attr("CCDDeviceName","CCD Utils");
38
sDriver::Preconfigure(DeviceCfg);
37
sTunableCCDDriver::Preconfigure(DeviceCfg);
40
sLomoCCDDriver::~sLomoCCDDriver ()
41
44
sLomoCCDDriver::sLomoCCDDriver (sString DevicetId
42
45
,sNodePtr DeviceCfg)
43
:sDriver(DevicetId,DeviceCfg)
46
:sTunableCCDDriver(DevicetId,DeviceCfg)
47
,WL_0(sPhysValue(1.0,"nm"))
48
,WL_k(sPhysValue(1,_Unitsless_))
48
53
void sLomoCCDDriver::PostConstructor ()
50
sDriver::PostConstructor();
55
sTunableCCDDriver::PostConstructor();
51
56
try{ //get config parameters
52
57
get_from<sIntegerNode>(DeviceSettings >> "CCD_SH" ,CCD_SH);
53
58
get_from<sIntegerNode>(DeviceSettings >> "CCD_ICG" ,CCD_ICG);
54
get_from<sIntegerNode>(DeviceSettings >> "IntegrationTime" ,IntegrationTime);
55
59
get_from<sTextNode>(DeviceSettings >> "CCDDeviceName" ,CCDDeviceName);
60
get_from<sPhysValueNode>(DeviceSettings >> "WL_0" ,WL_0);
61
get_from<sPhysValueNode>(DeviceSettings >> "WL_k" ,WL_k);
57
63
SetInvalid(tr("Something wrong in configuration."));
59
//evolution of the inherited state machine (behaviour)
61
{ // evolution of the State_Warming
62
State_W_Connect = new sState(State_Warming());
65
->OnEnterCall( SLOT(ConnectUSBDevice()) )
66
->AddTransition(SIGNAL(Connected()),State_Warming()->Fin())
67
->AddTransition(SIGNAL(ErrorMessage()),State_Cooling());
69
// evolution of the State_Operating
71
State_O_Stopped = new sState(State_Operating());
72
State_O_Measuring = new sState(State_Operating(),1);
73
State_O_GetMeasured = new sState(State_Operating());
76
->AddTransition(cStart,SLOT(StartCCD ()) ,State_O_Measuring)
77
->AddReaction<int>(cSetIntegrationTime
78
,SLOT(SetCCD_IntegrTime(int)));
80
->AddTransition(State_O_Measuring,SIGNAL(Timeout())
82
->AddTransition(cStop,SLOT(StopCCD ()) ,State_O_Stopped);
84
->OnEnterCall( SLOT(GetCCD_Data()) )
85
->AddTransition(State_O_Measuring);
90
67
void sLomoCCDDriver::ConnectUSBDevice ()
127
void sLomoCCDDriver::CalculateWavelengths ()
129
sPhysValue dWL = WL_0 + WL_k * WLPosition;
130
sPhysValue LeftPos = WLPosition - dWL*MiddlePixel;
131
sPhysValue RightPos = WLPosition + dWL*((NumOfPixels -1) - MiddlePixel);
132
real dX_0 = ((WL_0 + WL_k * LeftPos)/(sPhysValue(1.0,"nm"))).ToReal();
133
real dX_1 = ((WL_0 + WL_k * RightPos)/(sPhysValue(1.0,"nm"))).ToReal();
134
real dX = (dWL/(sPhysValue(1.0,"nm"))).ToReal(); // in "nm/pixel"
135
real d2X = (dX_1 - dX_0)/NumOfPixels;
136
real XM = (WLPosition/(sPhysValue(1.0,"nm"))).ToReal(); // in "nm"
137
for (int i = 0; i < NumOfPixels; i++) {
138
Wavelengths.ArrBody[i] = XM + (dX + d2X *(i - MiddlePixel))*(i - MiddlePixel);
140
emit NewWavelengths (Wavelengths);
150
143
void sLomoCCDDriver::StartCCD ()
152
// for (int i = 0; i < 10000;i++ ){
153
// TestReading[i] = 0;
155
// TestReadCount = 0;
157
145
BYTE byteToSend = 0x80;
158
146
ResetTriadeBuffer();
160
ReadingError_I_No = 0;
161
ReadingError_II_No = 0;
162
ReadingError_III_No = 0;
163
ReadingError_IV_No = 0;
164
ReadingError_V_No = 0;
165
148
FT_STATUS CCDDeviceStatus;
166
149
CCDDeviceStatus = FT_Purge(CCDDeviceHandle,FT_PURGE_RX | FT_PURGE_TX);
167
150
if(CCDDeviceStatus != FT_OK){
182
166
CCDDeviceStatus = FT_Write(CCDDeviceHandle,&byteToSend,1,&bytesWritten);
183
167
if(CCDDeviceStatus != FT_OK)
184
168
emit ErrorMessage(FormCCDErrorMessage(CCDDeviceStatus));
185
qDebug() << "ReadingError_I_No " << ReadingError_I_No;
186
qDebug() << "ReadingError_II_No " << ReadingError_II_No;
187
qDebug() << "ReadingError_III_No " << ReadingError_III_No;
188
qDebug() << "ReadingError_IV_No " << ReadingError_IV_No;
189
qDebug() << "ReadingError_V_No " << ReadingError_V_No;
169
WLDriver.ReleaseExclusiveControl();
192
void sLomoCCDDriver::SetCCD_IntegrTime (int IntegrTime)
172
void sLomoCCDDriver::SetCCD_Parameters (sCCDDriver::sParameters Params)
194
if (IntegrTime > 65535) IntegrationTime = 65535;
195
else if (IntegrTime < 1) IntegrationTime = 1;
196
else IntegrationTime = IntegrTime;
197
if(SendParam(0xC0,IntegrationTime))
175
if( ! WLDriver.TakeExclusiveControl() ){
179
if (Parameters.IntegrationTime/10 > 65535) _ITime = 65535;
180
else if (Parameters.IntegrationTime/10 < 1) _ITime = 1;
181
else _ITime = Parameters.IntegrationTime/10;
182
if(SendParam(0xC0,_ITime))
201
187
QString sLomoCCDDriver::FormCCDErrorMessage(FT_STATUS CCDStatus)
280
/* -------- Этот вариант мой - работает хреново ---------
281
void sLomoCCDDriver::AddByte(BYTE DataByte)
283
TriadeBuffer[NumInTriade ++] = DataByte;
284
if((DataByte & 0x80) == 0) { //Промежуточный байт
285
if(NumInTriade == 3) { // Лишний байт
286
TriadeBuffer[0] = TriadeBuffer[1];
287
TriadeBuffer[1] = TriadeBuffer[2];
289
ReadingError_I_No++; // Счетчик ошибок +1
291
} else { //Командный байт
292
if(NumInTriade < 2) { // Не хватает байтов данных
293
TriadeBuffer[0] = 1; // Заполняем их единицами
294
TriadeBuffer[1] = 1; // Оба для определенности
295
ReadingError_II_No++; // Счетчик ошибок +1
298
BYTE CommandCode = DataByte & 0xF0;
299
if(CommandCode == FRAME_START) { // Заполняем первую точку
301
DataArray.ArrBody[PointNo ++] = ConvertTriadeBuffer();
302
} else if(CommandCode == FRAME_MIDDLE) {
303
if(PointNo == PIXELSNUM - 1) { // Сбой в числе точек -
304
PointNo = 0; // бракуем весь кадр
306
ReadingError_III_No++; // Счетчик ошибок +1
307
}else if(PointNo == 0) { // Середина вместо начала -
308
NumInTriade = 0; // бракуем весь кадр
309
ReadingError_IV_No++; // Счетчик ошибок +1
310
}else { // Все в порядке - добавляем точку
311
DataArray.ArrBody[PointNo ++] = ConvertTriadeBuffer();
314
} else if(CommandCode == FRAME_END) {
315
if(PointNo == PIXELSNUM - 1) { //Конец фрейма
316
DataArray.ArrBody[PointNo ++] = ConvertTriadeBuffer();
319
emit NewData(DataArray);
320
} else { // Сбой в числе точек -
321
PointNo = 0; // бракуем весь кадр
323
ReadingError_V_No++; // Счетчик ошибок +1
325
} else { // Пришло непонятно что -
326
PointNo = 0; // бракуем весь кадр
328
ReadingError_VI_No++; // Счетчик ошибок +1
332
-------------------------------------------------------------------*/
334
266
// ------ Это взято у ЛОМО и слегка модифицировано -----------------
336
268
void sLomoCCDDriver::AddByte(BYTE DataByte )
338
// if (TestReadCount < 10000) TestReading[TestReadCount ++] = DataByte;
340
270
TriadeBuffer[NumInTriade ++] = DataByte ;
341
271
if(( DataByte & 0x80) == 0) { //Промежуточный байт
342
272
if(NumInTriade == 3) { // Лишний байт
343
273
TriadeBuffer[0] = TriadeBuffer[1];
344
274
TriadeBuffer[1] = TriadeBuffer[2];
346
ReadingError_I_No++; // Счетчик ошибок +1
349
278
}else { //Командный байт