Exemple #1
0
void setCurrentPosition(int pos)
{
    char str[32];
    
	if(motorinvert)
        sprintf(str, "A %d%c", (int)((electrodeDepthOffset-pos) * motormags[motorid]),CR);
	else
        sprintf(str, "A %d%c", (int)((electrodeDepthOffset+pos) * motormags[motorid]),CR);
    write(motorPort, str, strlen(str));     delay(10);
#ifdef DEBUG
	printf("Stepper: %s\n",str);
#endif
    notifyPositionChange(electrodeDepth);
    return;
}
Exemple #2
0
void NewPosition(int pos)
{
    char buf[256];
#ifdef REVERSED_CABLEA
    int diff = pos - electrodeDepth; 
#else
    int diff = electrodeDepth - pos; 
#endif
    int old = electrodeDepth;
    int portstate;
    
    if(motorinvert){
        while((electrodeDepthOffset-pos) <= 0){
            electrodeDepthOffset += 10000;
        }
    }
    else{
        while((electrodeDepthOffset+pos) <= 0){
            electrodeDepthOffset += 10000;
        }
    }
    
#ifdef OLDCODE
    while((pos - electrodeDepthOffset) >= 0){
        electrodeDepthOffset -= 10000;
    }
#endif
    
    if(fabs(diff) > 9999){
        sprintf(buf,"Thats a big step (%d) Proceed?",diff);
        acknowledge(buf,"/bgc/bgc/c/binoc/help/bigstep.err");
    }
    if(fabs(diff) > 200){
        sprintf(buf,"Thats a big step (%d) Proceed?",diff);
        if(!confirm_yes(buf,NULL))
            return;
        
    }
    
#ifdef DEBUG
    printf("Setting new Postion to %d (%d) %d\n",pos,diff,electrodeDepthOffset);
#endif
#if !defined(WIN32)
    ioctl(motorPort,TIOCMGET,&portstate);
    if(!(portstate & TIOCM_CTS)){
        fprintf(stderr,"Stepper Not Ready\n");
        acknowledge("Stepper Not Ready!");
        if(optionflags[STEP_CLEAR_SPIKES]){
            memcpy(&cleartime,&now,sizeof(struct timeval));
            /* empirical approximation for the duration of the movement artifact */
            cleardelay = 0.2;
        }
        return;
    }
#endif
    
    sprintf(buf,"%d",pos);
    
    electrodeDepth = pos;
    
    selectMotor(motorids[motorid]);
    setCurrentPosition(old);  
    setNewPosition(electrodeDepth,diff);
	gettimeofday(&now,NULL);
    times[totalsteps] = timediff(&now,&progstarttime) + timeoffset;
    depths[totalsteps] = electrodeDepth;
    if(penlog){
        fprintf(penlog,"ed %d at %.1f\n",electrodeDepth,times[totalsteps]);
        if(diff < -200){
            fprintf(penlog,"Step Back at %s\n",binocTimeString());
        }
    }
    times[totalsteps+1] = 0;
    if(totalsteps < MAXDEPTHS-1)
        totalsteps++;
    if(optionflags[STEP_CLEAR_SPIKES]){
        memcpy(&cleartime,&now,sizeof(struct timeval));
        /* empirical approximation for the duration of the movement artifact */
        cleardelay = 0.11 + fabs(diff) * 0.027 - pow(fabs(diff),1.13) * 0.0113;
    }
    notifyPositionChange(electrodeDepth);
}
Exemple #3
0
int OpenStepSerial(char *port)
{
    char buf[256];
    char str[256];
    struct termios termios_p;
    
    TTY t;
    
    
    struct itimerval itimer;
    long speed;
    int portstate;
    void (* sigfn)();
    
    int i = 0;
    stepport = port;
    
    if(ttys[0] != 0)
        i = 1;
    /*
     * On SGI, ttyd does not use RTS/CTS, so can use this to tell the 
     * Controller to turn on RTS/CTS (which then sets CTS high)
     * Once this is done, can open with /dev/ttyf1, which uses
     * CTS. CTS then used to poll when the motor has done its move
     */
    //Ali #if defined(macosx)
    if((ttys[i] = open(port,O_RDWR|O_NONBLOCK)) < 0)
        //Ali #else
        //Ali   if((ttys[i] = open("/dev/ttyd1",O_RDWR|O_NONBLOCK)) < 0)
        //Ali #endif
    {
        sprintf(buf,"Can't open %s",port);
        perror(buf);
        return(0);
    }
    alarm(0);
    motorPort = ttys[i];
    if(tcgetattr(ttys[i], &termios_p)) {
        perror("Can't get terminal properties");
        exit(-1);
    }
    if(tcgetattr(ttys[i], &termios_p)) {
        perror("Can't get terminal properties");
        return(-1);
    }
    
    /*
     * after first opening the port, set it to ignore CTS (VTIME = 0)
     * since the controller has the busy bit set at power up.
     * then reopen the port and set it up to wait for CTS
     */
    speed = B9600;
    cfsetospeed(&termios_p, speed);
    cfsetispeed(&termios_p, speed);
    termios_p.c_cc[VMIN] = 1;
    termios_p.c_cc[VTIME] = 0;
    termios_p.c_lflag &= ~(ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL|CCTS_OFLOW);
    tcsetattr(motorPort, TCSANOW, &termios_p);
    
    /* send commands to controller to auto select BAUD rate */
    sprintf(str, "%c", CR);
    write(motorPort, str, strlen(str));
    delay(20);
    write(motorPort, str, strlen(str));
    delay(20);
    
    /* set mode to ASCII commands, enable CTS on bit 6 */
    sprintf(str, "O 0A0H%c", CR);
    i = write(motorPort, str, strlen(str)); delay(20);
    i = write(motorPort, str, strlen(str)); delay(20);
    termios_p.c_cc[VMIN] = 1;
    termios_p.c_cc[VTIME] = 0;
    termios_p.c_lflag &= ~(ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL);
    // dont need to play wiht this here - just about to close port
    //  termios_p.c_lflag |= CCTS_OFLOW;
    tcsetattr(motorPort, TCSANOW, &termios_p);
    close(motorPort);
    usleep(10000);
    
    /* Now can open a port that Respects RTS/CTS */
    sigfn = signal(SIGALRM, settimeout);
    alarm(10);
    //  itimer.it_interval.tv_sec = 10;
    //  setitimer(ITIMER_REAL, &itimer, NULL);
    
    /*
     * on macosx (with Keyspan serial adapters) this will hang
     * if there is no Controller box attached, unless O_NONBLOCK is set.
     * Alarm should deal with this, but seems not to under macosx
     * problem is that I think this may stop it from blocking when the motor
     * is moved. Need to check this.
     */
    //  if((motorPort = open(port, O_RDWR|O_NONBLOCK)) == -1) {
    if((motorPort = open(port, O_RDWR|O_NONBLOCK)) == -1) {
        
        perror("Can't open serial port");
        acknowledge("Can't open serial port",NULL);
        return(-1);
    }
  	alarm(0);
	//  itimer.it_interval.tv_sec = 0;
	//  setitimer(ITIMER_REAL, &itimer, NULL);
	signal(SIGALRM, sigfn);
    
	if(ioctl(motorPort,TCGETA,&t) < 0)
	{
		perror("iocntl 1");
		exit(-1);	
	}
	t.c_lflag &= ~(ICANON | ECHO);
	t.c_cflag &= (~(PARENB|PARODD));
	t.c_ospeed = B9600;
	t.c_ispeed = B9600;
	// This is necessary to get CTS respsected 
    t.c_cflag |= (CCTS_OFLOW);
	t.c_cc[VEOF] = 0; /* 0 buffered char */
	t.c_cc[VEOL] = 0; /* return immediately between */
	t.c_cc[VMIN] = 0; /* 0 buffered char */
	t.c_cc[VTIME] = 0; /* return if no char in 0.l sec */
	if(ioctl(motorPort,TCSETA,&t) < 0)
	{
		perror("Ioctl 2");
		exit(-2);
	}
	usleep(10000);
    
#if !defined(WIN32)
    ioctl(motorPort,TIOCMGET,&portstate);
    if(!(portstate & TIOCM_CTS)){
        acknowledge("Controller CTS is low. Restart",NULL);
    }
#endif
    
    stepsetup();
    notifyPositionChange(electrodeDepth);
    return(motorPort);
}
void GraphicsNodeSocket::
set_edge(GraphicsDirectedEdge *edge) {
	// TODO: handle edge conflict
	_edge = edge;
	notifyPositionChange();
}