LAN_rhk_hwi_spm.C

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 1999,2000,2001 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Farid El Gabaly <farid.elgabaly@uam.es>, Juan de la Figuera <juan.delafiguera@uam.es>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 /* irnore this module for docuscan
00029 % PlugInModuleIgnore
00030  */
00031 
00032 
00033 // "C++" headers
00034 #include <iostream>
00035 
00036 // system headers
00037 #include <fcntl.h>
00038 #include <sys/ioctl.h>
00039 
00040 #include <locale.h>
00041 #include <libintl.h>
00042 
00043 
00044 // Gxsm headers
00045 #include "glbvars.h"
00046 #include "dsp-pci32/xsm/xsmcmd.h"
00047 #include "LAN_rhk_hwi.h"
00048 
00049 
00050 // use "gxsm2 --debug-level=5" (5 or higher) to enable debug!
00051 #define RHK_DEBUG(S) XSM_DEBUG (DBG_L4, S)
00052 
00053 /*
00054  * Init things
00055  */
00056 
00057 LAN_rhk_hwi_spm::LAN_rhk_hwi_spm():LAN_rhk_hwi_dev(){
00058         RHK_DEBUG("Init LAN-RHK SPM");
00059         ScanningFlg=0;
00060 }
00061 
00062 /*
00063  * Clean up
00064  */
00065 
00066 LAN_rhk_hwi_spm::~LAN_rhk_hwi_spm(){
00067         RHK_DEBUG("Finish LAN-RHK SPM");
00068 }
00069 
00070 void LAN_rhk_hwi_spm::ExecCmd(int Cmd){
00071 
00072         char txtcmd[80];
00073         // Exec "DSP" command (additional stuff)
00074         RHK_DEBUG("Exec Cmd 0x" << std::hex << Cmd);
00075         if (Cmd==DSP_CMD_APPROCH)
00076                 {
00077                         sprintf(txtcmd, "check %6.0d\n",ScanData.hardpars.TIP_DUz);
00078                         SendCommand(txtcmd);
00079                 }
00080         if (Cmd==DSP_CMD_APPROCH_MOV_XP)
00081                 {
00082                         sprintf(txtcmd, "approach %6.0f on %6.0f %6.0f\n",ScanData.hardpars.MOV_Steps,
00083                                 3276.8*ScanData.hardpars.MOV_Ampl, ScanData.hardpars.MOV_Speed);
00084                         SendCommand(txtcmd);
00085                 }
00086         else if (Cmd==DSP_CMD_CLR_PA)
00087                 {
00088                         SendCommand("stop\n");
00089                 }
00090         else if (Cmd==DSP_CMD_AFM_MOV_YP)
00091                 {
00092                         sprintf(txtcmd, "approach %6.0f off %6.0f %6.0f\n",ScanData.hardpars.MOV_Steps,
00093                                 3276.8*ScanData.hardpars.MOV_Ampl, ScanData.hardpars.MOV_Speed);
00094                         SendCommand(txtcmd);
00095                 }
00096         else if (Cmd==DSP_CMD_AFM_MOV_YM)
00097                 {
00098                         sprintf(txtcmd, "retract %6.0f  %6.0f %6.0f\n",ScanData.hardpars.MOV_Steps, 3276.8*ScanData.hardpars.MOV_Ampl, ScanData.hardpars.MOV_Speed);
00099                         SendCommand(txtcmd);
00100                 }
00101         else if (Cmd==DSP_CMD_MOVETO_X)
00102                 {
00103                         SendCommand("xy on\n");
00104                 }
00105         else if (Cmd==DSP_CMD_MOVETO_Y)
00106                 {
00107                         SendCommand("xy off\n");
00108                 }
00109 
00110         // Put CMD to DSP for execution.
00111         // Wait until done and
00112         // call whenever you are waiting longer for sth.:
00113         // gapp->check_events(); // inbetween!
00114 }
00115 
00116 
00117 void LAN_rhk_hwi_spm::PutParameter(void *par, int grp)
00118 {
00119         /* Read both scan parameters and spm settings (RHK STM 100 has its own scan generator, so we
00120            only need to READ the settings, we cannot set them. To be used with new RHKControl plugin... */
00121 
00122         /* Use PutParameter(dsp) to transfer dsp parameter to this plugin (for DSPmover control) */
00123         /* Use PutParameter(scandata,1) to synchronize the settings as read from the RHK */
00124 
00125         char buffer[18], d0,d1;
00126         short *reading;
00127         int ad_gain, mult;
00128         float line_rate;
00129         int temp, count;
00130 
00131                 if (ScanningFlg) {RHK_DEBUG("Tried to get params while scanning!");
00132                 return;
00133                 }
00134         if (grp!=1) {
00135                 if (par)
00136                 memcpy(&(ScanData.hardpars),par, sizeof(ScanData.hardpars));
00137                 RHK_DEBUG("Settings " << ScanData.hardpars.AFM_Steps << ScanData.hardpars.MOV_Steps);
00138                 return;
00139         }
00140         if (par)
00141                 memcpy(&ScanData,par, sizeof(ScanData));
00142         RHK_DEBUG("Settings " << ScanData.hardpars.AFM_Steps << ScanData.hardpars.MOV_Steps);
00143         SendCommand("read_settings\n");
00144         ReadData(buffer,sizeof(buffer));
00145         reading=(short *)buffer;
00146         d0=buffer[16];
00147         d1=buffer[17];
00148         ScanData.hardpars.UTunnel=reading[2];
00149         ScanData.hardpars.ITunnelSoll=reading[1];
00150 
00151         ScanData.s.rx=reading[6];
00152         ScanData.s.ry=reading[4];
00153         //scanPar.rz=reading[4];
00154         ScanData.s.tStart;
00155         ScanData.s.tEnd;
00156         ScanData.s.x0=reading[7];
00157         ScanData.s.y0=reading[5];
00158 
00159         line_rate = d0 & 0x0f;
00160         temp = 2 << (((d0 & 0x70) >> 4) - 1);
00161         ad_gain = (temp == 0) ? 1 : temp;
00162         temp = d1 & 3;
00163         mult = (int)pow (10.0, temp);
00164         ScanData.s.ny= 128 << ((d1 & 12) >> 2);
00165         ScanData.s.nx= ScanData.s.ny;
00166         line_rate *= mult;
00167         ScanData.s.rz=32768/ad_gain;
00168         RHK_DEBUG("Updating parameters xUT=" );
00169 
00170         if (par)
00171                 memcpy(par,&ScanData,sizeof(ScanData));
00172 
00173 
00174 }
00175 
00176 // just note that we are scanning next...
00177 void LAN_rhk_hwi_spm::StartScan2D(){
00178         ScanningFlg=1;
00179         KillFlg=FALSE; // if this gets TRUE while scanning, you should stopp it!!
00180         //      SendCommand("start\n");
00181         RHK_DEBUG("Start Scan 2D");
00182 }
00183 
00184 // and its done now!
00185 void LAN_rhk_hwi_spm::EndScan2D(){
00186         ScanningFlg=0;
00187         SendCommand("reset\n");
00188         RHK_DEBUG("End Scan 2D");
00189 }
00190 
00191 // we are paused
00192 void LAN_rhk_hwi_spm::PauseScan2D(){
00193         ScanningFlg=0;
00194         SendCommand("stop\n");
00195         RHK_DEBUG("Pause Scan 2D");
00196 }
00197 
00198 // and its going againg
00199 void LAN_rhk_hwi_spm::ResumeScan2D(){
00200         SendCommand("start\n");
00201         RHK_DEBUG("Resume Scan 2D");
00202         ScanningFlg=1;
00203 }
00204 
00205 // X position tip, relative to Offset,
00206 // but in rotated cooerd sys!
00207 // Note: X is always the fast scanning direction!!
00208 void LAN_rhk_hwi_spm::MovetoX(long x){
00209         // this is how I pass params to the DSP
00210         // you could do sth. else here!
00211         // use the rot matrix (rotmxx/xy/yx/yy/rotoffx/rotoffy) !!
00212         /*
00213           PARAMETER_SET hardpar;
00214           rx=x;
00215           hardpar.N   = DSP_MOVETOX+1;
00216           hardpar.Cmd = DSP_CMD_MOVETO_X;
00217           hardpar.hp[DSP_MOVETOX ].value = x;
00218           SetParameter(hardpar);
00219         */
00220         //RHK_DEBUG("MovetoX: " << x); rx=x;
00221 }
00222 
00223 // Y position tip, relative to Offset,
00224 // but in rotated cooerd sys!
00225 void LAN_rhk_hwi_spm::MovetoY(long y){
00226         // use the rot matrix (rotmxx/xy/yx/yy/rotoffx/rotoffy) !!
00227         /*
00228           PARAMETER_SET hardpar;
00229           ry=y;
00230           hardpar.N   = DSP_MOVETOY+1;
00231           hardpar.Cmd = DSP_CMD_MOVETO_Y;
00232           hardpar.hp[DSP_MOVETOY ].value = y;
00233           SetParameter(hardpar);
00234         */
00235         //RHK_DEBUG("MovetoY: " << y); ry=y;
00236 }
00237 
00238 // this does almost the same as the XSM_Hardware base class would do, 
00239 // but you may want to do sth. yourself here
00240 void LAN_rhk_hwi_spm::SetDxDy(int dx, int dy){
00241         Dx = dx; 
00242         Dy = dy;
00243         //dspPar.LS_dnx = dx;
00244         RHK_DEBUG("SetDxSy: " << dx << ", " << dy);
00245 }
00246 
00247 // this does almost the same as the XSM_Hardware base class would do, 
00248 // but you may want to do sth. yourself here
00249 void LAN_rhk_hwi_spm::SetOffset(long x, long y){
00250         rotoffx = x; rotoffy = y;
00251         RHK_DEBUG("SetOffset: " << x << ", " << y);
00252 }
00253 
00254 // this does almost the same as the XSM_Hardware base class would do, 
00255 // but you may want to do sth. yourself here
00256 void LAN_rhk_hwi_spm::SetAlpha(double alpha){ 
00257         // calculate rot matrix
00258         Alpha=M_PI*alpha/180.;
00259         rotmyy = rotmxx = cos(Alpha);
00260         rotmyx = -(rotmxy = sin(Alpha));
00261         RHK_DEBUG("SetAlpha: " << alpha);
00262 }
00263 
00264 // this does almost the same as the XSM_Hardware base class would do, 
00265 // but you may want to do sth. yourself here
00266 void LAN_rhk_hwi_spm::SetNx(long nx){ 
00267         Nx=nx; 
00268         //dspPar.LS_nx2scan = nx;
00269         RHK_DEBUG("Setnx: " << nx);
00270 }
00271 
00272 
00273 /*
00274  * Do ScanLine in multiple Channels Mode
00275  *
00276  * yindex:  Index of Line
00277  * xdir:    Scanning Direction (1:+X / -1:-X) eg. for/back scan
00278  * lsscrs:  LineScan Sources, MUX/Channel Configuration
00279  * PC31 has can handle 2 Channels of 16bit data simultan, using 4-fold Mux each
00280  *      additional the PID-Outputvalue can be used and the PID Src is set by MUXA
00281  *      it may be possible to switch MUXB while scanning -- test it !!!
00282  * bit     0 1 2 3  4 5 6 7  8 9 10 11  12 13 14 15 ...
00283  * PC31:   ==PID==  =MUX-A=  ==MUX-B==  
00284  * PCI32:  ==PID==  A======  B========  C==== D====
00285  *    eg.  Z-Value  Fz/I     Fric...
00286  * example:
00287  * value   1 0 0 0  1 0 0 0  1 0  0  0  0...
00288  * buffers B0       B1       B2
00289  * 3 buffers used for transfer (B0:Z, B1:Force, B2:Friction)
00290  *
00291  * Mob:     List of MemObjs. to store Data
00292  *
00293  * with maximized DPRAM usage: [DPRAM] [DSPMEM1] [DSPMEM2] ... (Blocks of same size)
00294  *                              B0,B1,  B2, B3,   B4,..
00295  * nach DSP_CMD_SWAPDPRAM:      B2,B3,  -------   B4,..
00296  * nach DSP_CMD_SWAPDPRAM:      B4,..   -------   -------
00297  * ...
00298  * 
00299  */
00300 
00301 void LAN_rhk_hwi_spm::ScanLineM(int yindex, int xdir, int lssrcs, Mem2d *Mob[MAX_SRCS_CHANNELS], int ix0 ){
00302         char txt[80];
00303         int count;
00304         int channel; // Only one for now...
00305 
00306         // this is how I pass parameters to the DSP
00307         // you may use thoes otherwise
00308         /*
00309           PARAMETER_SET hardpar;
00310 
00311           hardpar.N   = DSP_LSYINDEX+1;
00312           hardpar.Cmd = DSP_CMD_LINESCAN;
00313           hardpar.hp[DSP_LSNX       ].value = dspPar.LS_nx2scan;
00314           if(xdir<0) // Rück - Scan (-)
00315           hardpar.hp[DSP_LSDNX      ].value = -dspPar.LS_dnx;
00316           else    // Hin  - Scan (+)
00317           hardpar.hp[DSP_LSDNX      ].value = dspPar.LS_dnx;
00318           hardpar.hp[DSP_LSSTEPSZ   ].value = dspPar.LS_stepsize;
00319           hardpar.hp[DSP_LSNREGEL   ].value = dspPar.LS_nRegel;
00320           hardpar.hp[DSP_LSNAVE     ].value = dspPar.LS_nAve;
00321           hardpar.hp[DSP_LSINTAVE   ].value = dspPar.LS_IntAve;
00322           hardpar.hp[DSP_LSNXPRE    ].value = dspPar.LS_nx_pre;
00323           hardpar.hp[DSP_LSSRCS     ].value = lssrcs; // Codierte MUX/Srcs Configuration
00324           hardpar.hp[DSP_LSYINDEX   ].value = yindex; // for verify only
00325 
00326           // waits until done!!! But calls the check event func for non blocking!
00327           SetParameter(hardpar, TRUE);
00328         */
00329         if (yindex<1) {
00330                 if (lssrcs & 0x01)  channel=0;
00331                 else if (lssrcs & 0x02) channel=1;
00332                 else if (lssrcs & 0x04) channel=2;
00333                 else if (lssrcs & 0x08) channel=3;
00334                 else if (lssrcs & 0x08) channel=3;
00335                 else if (lssrcs & 0x10) channel=4;
00336                 else if (lssrcs & 0x20) channel=5;
00337                 else if (lssrcs & 0x40) channel=6;
00338                 else if (lssrcs & 0x80) channel=7;
00339 
00340                 RHK_DEBUG("Selecting " << lssrcs <<  " and so, channel " << channel );
00341                 count=sprintf(txt, "channel %d\n\0",channel);
00342                 SendCommand(txt);
00343                 SendCommand("start\n");
00344         }
00345         // call this while waiting for background data updates on screen...
00346         CallIdleFunc ();
00347 
00348         // calc # of srcs
00349         int num_srcs = 0;
00350         int bi = 0;
00351         do{
00352                 if(lssrcs & (1<<bi++))
00353                         ++num_srcs;
00354         }while(bi<16);
00355 
00356         ReadScanData (yindex, num_srcs, Mob); 
00357 }

Generated on Sat Apr 1 09:04:16 2006 for GXSM by  doxygen 1.4.6