Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  12 Apr 2021, Isaac Labrie Boulay, Forum, Client gets immediately removed when using a script button. logicCtrl.cppstart_daq.PNG
    Reply  12 Apr 2021, Ben Smith, Forum, Client gets immediately removed when using a script button. 
       Reply  12 Apr 2021, Isaac Labrie Boulay, Forum, Client gets immediately removed when using a script button. debug_logic_controller.txt
          Reply  12 Apr 2021, Ben Smith, Forum, Client gets immediately removed when using a script button. 
             Reply  13 Apr 2021, Isaac Labrie Boulay, Forum, Client gets immediately removed when using a script button. 
                Reply  13 Apr 2021, Stefan Ritt, Forum, Client gets immediately removed when using a script button. 
Message ID: 2145     Entry time: 12 Apr 2021     Reply to this: 2146
Author: Isaac Labrie Boulay 
Topic: Forum 
Subject: Client gets immediately removed when using a script button. 
Hi all,

I'm running into a curious problem when I try to run a program using my custom 
script button. I have been using a script button to start my DAQ, this button 
has always worked. It starts by exporting an absolute path to scripts and then 
runs scripts, my frontend, my analyzer, and mlogger relative to this path.

I recently added a line of code to run a new script "logic_controller". If I run 
the script_daq from my terminal (./start_daq), mhttpd accepts the client and the 
program works as intended. But, if I use the script button, the logic_controller 
program is immediately deleted by MIDAS. It can be seen appearing in the status 
page clients list and then immediately gets deleted. This is a client that runs 
on the local experiment host.

What might be the issue? What is the difference between running the script 
through the terminal as opposed to running it through the mhttpd button?

I have added a picture of my simple script and the logic_controller code.

Any help would be greatly appreciated.

Cheers.

Isaac
Attachment 1: logicCtrl.cpp  3 kB  Uploaded 12 Apr 2021  | Hide | Hide all | Show all
//
// Isaac Labrie-Boulay
//
// Program that enables the modification of gate and delay values 
// in the logic unit
//
// Last Edit: 2021-030-29
//

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <iostream>

using namespace std;

#include "CAEN_PLULib.h"
#include "midas.h"
#include "assert.h"
#include "mfe.h"
#include "mvmestd.h"
#include "odbxx.h"
//#include "CAEN_PLULib_TEST.h"

#ifdef WIN32 // Windows
#include <windows.h>
#include <conio.h>
#else // Linux
#define _popen popen
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>

char _getch() {
        char buf = 0;
        struct termios old = { 0 };
        fflush(stdout);
        if (tcgetattr(0, &old)<0)
                perror("tcsetattr()");
        old.c_lflag &= ~ICANON;
        old.c_lflag &= ~ECHO;
        old.c_cc[VMIN] = 1;
        old.c_cc[VTIME] = 0;
        if (tcsetattr(0, TCSANOW, &old)<0)
                perror("tcsetattr ICANON");
        if (read(0, &buf, 1)<0)
                perror("read()");
        old.c_lflag |= ICANON;
        old.c_lflag |= ECHO;
        if (tcsetattr(0, TCSADRAIN, &old)<0)
                perror("tcsetattr ~ICANON");
        printf("%c\n", buf);
        return buf;
}
#endif

char *base_address = "32100000";


void err_check(CAEN_PLU_ERROR_CODE err);

int main()
{

	cm_connect_experiment("", "", "logic_controller", NULL);
   	midas::odb::set_debug(true);

	//Establish a connection with the unit through the V1718
	int handle;
	CAEN_PLU_ERROR_CODE err_code;

	err_code = CAEN_PLU_OpenDevice(CAEN_PLU_CONNECT_VME_V1718, base_address, 0, 0, &handle);
	err_check(err_code);

	//Create an ODB key to hold the V2495 handle
	midas::odb hKey = {{"V2495 Handle", handle}};
	hKey.connect("/Modules/Logic");

	uint32_t firmware;
	err_code = CAEN_PLU_ReadReg(handle, 0x1000, &firmware);
	err_check(err_code);
	printf("Firmware version: %d\n", firmware);
	
	//Initialize Gate and Delay Generators
	err_code = CAEN_PLU_InitGateAndDelayGenerators(handle);
	err_check(err_code);

	//Take the Default gate values from the ODB
	midas::odb def("/Modules/Logic/Default");

	uint32_t commonGate = (uint32_t)def["width"];
        uint32_t commonDelay = (uint32_t)def["delay"];
        uint32_t commonScale = (uint32_t)def["scale"];

	//Set all gates to the same default settings
	err_code = CAEN_PLU_SetGateAndDelayGenerators(handle, commonGate, commonDelay, commonScale);
        err_check(err_code);

	//Watch the ODB subtree
	midas::odb to_watch("/Modules/Logic");
	
	//Lambda function
	//
	// if any of these keys are changed through the web server, 
	// write the new value to the logic unit
	//
	to_watch.watch([](midas::odb &logic){
      		
		//std::cout << "Value of key \"" + logic.get_full_path() + "\" changed to " << logic << std::endl;
		
		CAEN_PLU_ERROR_CODE err_code;

		//Retrieve the V2495 handle
		midas::odb temp("/Modules/Logic");
		int h = temp["V2495 Handle"];

		//Get the QDC parameters
		midas::odb qdc("/Modules/Logic/QDCGateA");
		uint32_t qdcGate = qdc["width"];
		uint32_t qdcDelay = qdc["delay"];
		uint32_t qdcScale = qdc["scale"];

		//Set the new values
		err_code = CAEN_PLU_SetGateAndDelayGenerator(h, 0, 1,  qdcGate, qdcDelay, qdcScale);
                err_check(err_code);
		
		//Get the TDC parameters
		midas::odb tdc("/Modules/Logic/TDCGate");
                uint32_t tdcGate = tdc["width"];
                uint32_t tdcDelay = tdc["delay"];
                uint32_t tdcScale = tdc["scale"];

		//Set the new values
		err_code = CAEN_PLU_SetGateAndDelayGenerator(h, 1, 1, tdcGate, tdcDelay, tdcScale);
                err_check(err_code);

   	});
	
	do {
      		int status = cm_yield(100);
      		if (status == SS_ABORT || status == RPC_SHUTDOWN)
         		break;
   	} while (!ss_kbhit());

	cm_disconnect_experiment();

	return 0;
}

void err_check(CAEN_PLU_ERROR_CODE err)
{
	if (err != CAEN_PLU_OK)
        {
                printf("Error %d\n", err);
                exit(0);
        }
}















Attachment 2: start_daq.PNG  18 kB  Uploaded 12 Apr 2021  | Show | Hide all | Show all
ELOG V3.1.4-2e1708b5