- Refactored site specific stuff into a site module - PSI specific stuff is now in the PSI directory. - The old version has been tagged with pre-ansto SKIPPED: psi/A1931.c psi/A1931.h psi/amor2t.c psi/amor2t.h psi/amor2t.i psi/amor2t.tex psi/amor2t.w psi/amorscan.c psi/amorscan.h psi/amorscan.w psi/amorstat.c psi/amorstat.h psi/amorstat.i psi/amorstat.tex psi/amorstat.w psi/bruker.c psi/bruker.h psi/bruker.w psi/buffer.c psi/buffer.h psi/dilludriv.c psi/dilludriv.h psi/dmc.c psi/dmc.h psi/dmc.w psi/docho.c psi/ecb.c psi/ecb.h psi/ecb.i psi/ecb.w psi/ecbdriv.c psi/ecbdriv.h psi/el734dc.c psi/el734driv.c psi/el755driv.c psi/el755driv.h psi/faverage.c psi/faverage.h psi/faverage.tex psi/faverage.w psi/fowrite.c psi/fowrite.h psi/itc4.c psi/itc4.h psi/itc4.w psi/itc4driv.c psi/ltc11.c psi/ltc11.h psi/nextrics.c psi/nextrics.h psi/nxamor.c psi/nxamor.h psi/nxamor.tex psi/nxamor.w psi/pimotor.c psi/pimotor.h psi/pimotor.tex psi/pimotor.w psi/pipiezo.c psi/polterwrite.c psi/polterwrite.h psi/psi.c psi/ruli.c psi/ruli.h psi/sanscook.c psi/sanswave.c psi/sanswave.h psi/sanswave.tex psi/sanswave.w psi/serial.c psi/serial.h psi/serial.w psi/sinqhmdriv.c psi/sinqhmdriv.i psi/sinqhmdriv.w psi/slsmagnet.c psi/sps.c psi/sps.h psi/sps.i psi/sps.tex psi/sps.w psi/swmotor.c psi/swmotor.h psi/swmotor.i psi/tas.c psi/tas.h psi/tas.tex psi/tas.w psi/tasdrive.c psi/tasinit.c psi/tasscan.c psi/tasu.h psi/tasutil.c psi/tdchm.c psi/tdchm.h psi/tecsdriv.c psi/tecsdriv.h psi/velodorn.c psi/velodorn.h psi/velodorn.w psi/velodornier.c psi/hardsup/README psi/hardsup/StrMatch.c psi/hardsup/asynsrv_def.h psi/hardsup/asynsrv_errcodes.h psi/hardsup/asynsrv_mark.c psi/hardsup/asynsrv_utility.c psi/hardsup/c_interfaces.c psi/hardsup/dillutil.c psi/hardsup/dillutil.h psi/hardsup/el734_def.h psi/hardsup/el734_errcodes.h psi/hardsup/el734_utility.c psi/hardsup/el734fix.h psi/hardsup/el734tcl.c psi/hardsup/el737_def.h psi/hardsup/el737_errcodes.h psi/hardsup/el737_utility.c psi/hardsup/el737fix.h psi/hardsup/el737tcl.c psi/hardsup/el755_def.h psi/hardsup/el755_errcodes.h psi/hardsup/el755_errorlog.c psi/hardsup/el755_utility.c psi/hardsup/err.c psi/hardsup/failinet.c psi/hardsup/geterrno.c psi/hardsup/itc4util.c psi/hardsup/itc4util.h psi/hardsup/make_gen psi/hardsup/makefile_alpha psi/hardsup/makefile_linux psi/hardsup/makeprint.c psi/hardsup/rs232c_def.h psi/hardsup/serialsinq.c psi/hardsup/serialsinq.h psi/hardsup/sinq_defs.h psi/hardsup/sinq_prototypes.h psi/hardsup/sinqhm.c psi/hardsup/sinqhm.h psi/hardsup/sinqhm_def.h psi/hardsup/stredit.c psi/hardsup/strjoin.c psi/hardsup/table.c psi/hardsup/table.h psi/hardsup/velsel_def.h psi/hardsup/velsel_utility.c psi/motor/Makefile psi/motor/el734_test psi/motor/el734_test.c psi/motor/makeprint.c psi/sinqhm/FOCUS_gbl.h psi/sinqhm/FOCUS_srv_main.c psi/sinqhm/Makefile psi/sinqhm/SinqHM_bootParamsConfig.c psi/sinqhm/SinqHM_bootUtil.c psi/sinqhm/SinqHM_def.h psi/sinqhm/SinqHM_gbl.h psi/sinqhm/SinqHM_srv_filler.c psi/sinqhm/SinqHM_srv_main.c psi/sinqhm/SinqHM_srv_routines.c psi/sinqhm/SinqHM_srv_server.c psi/sinqhm/bld psi/sinqhm/bld2 psi/sinqhm/bldmen psi/sinqhm/hist_mem_notes.tex psi/sinqhm/hist_mem_spec.tex psi/sinqhm/hist_mem_spec_fig1.ps psi/sinqhm/hist_mem_spec_fig2.ps psi/sinqhm/hist_mem_spec_fig3.ps psi/sinqhm/hist_mem_spec_fig4.ps psi/sinqhm/lwl_client.c psi/sinqhm/lwl_server.c psi/sinqhm/make_sinqhm.com psi/sinqhm/monitor.c psi/sinqhm/psi_logo.ps psi/sinqhm/sinq_logo.ps psi/sinqhm/sinqhm_bootutil_client.c psi/sinqhm/sinqhm_client.c psi/sinqhm/sinqhm_ctrl.c psi/sinqhm/usrConfig.c psi/sinqhm/usrConfig.c_diffs psi/sinqhm/usrConfig2604.c psi/sinqhm/vmio10_def.h psi/sinqhm/vmio_utility.c psi/tecs/coc_client.c psi/tecs/coc_client.h psi/tecs/coc_logfile.c psi/tecs/coc_logfile.h psi/tecs/coc_server.c psi/tecs/coc_server.h psi/tecs/coc_util.c psi/tecs/coc_util.h psi/tecs/fortify1.c psi/tecs/instr_hosts.c psi/tecs/instr_hosts.h psi/tecs/keep_running.c psi/tecs/make_gen psi/tecs/make_opt psi/tecs/make_opt_alpha psi/tecs/make_opt_llc psi/tecs/makefile psi/tecs/makefile_alpha psi/tecs/makefile_linux psi/tecs/myc_buf.c psi/tecs/myc_buf.h psi/tecs/myc_err.c psi/tecs/myc_err.h psi/tecs/myc_fortran.h psi/tecs/myc_mem.h psi/tecs/myc_str.c psi/tecs/myc_str.h psi/tecs/myc_time.c psi/tecs/myc_time.h psi/tecs/myc_tmp.c psi/tecs/myc_tmp.h psi/tecs/rstart.c psi/tecs/six.c psi/tecs/str.f psi/tecs/sys_cmdpar.f psi/tecs/sys_date.f psi/tecs/sys_env.c psi/tecs/sys_get_key.f psi/tecs/sys_getenv.f psi/tecs/sys_lun.f psi/tecs/sys_open.f psi/tecs/sys_open_alpha.f psi/tecs/sys_rdline.c psi/tecs/sys_select.c psi/tecs/sys_select.h psi/tecs/sys_unix.c psi/tecs/sys_wait.f psi/tecs/tecs.bld psi/tecs/tecs.c psi/tecs/tecs.tcl psi/tecs/tecs_c.c psi/tecs/tecs_c.h psi/tecs/tecs_cli.c psi/tecs/tecs_cli.h psi/tecs/tecs_client.f psi/tecs/tecs_data.c psi/tecs/tecs_data.h psi/tecs/tecs_dlog.inc psi/tecs/tecs_for.f psi/tecs/tecs_lsc.c psi/tecs/tecs_lsc.h psi/tecs/tecs_plot.f psi/tecs/tecs_serial.c psi/tecs/tecs_serial.h psi/tecs/term.c psi/tecs/term.h psi/utils/Makefile psi/utils/SerPortServer.c psi/utils/asynsrv_test.c psi/utils/ecb-load.c psi/utils/el734.c psi/utils/el734_test.c psi/utils/el737.c psi/utils/make.ecb psi/utils/check/amorcheck psi/utils/check/dmccheck psi/utils/check/focuscheck psi/utils/check/focusstatus.tcl psi/utils/check/hrptcheck psi/utils/check/sanscheck psi/utils/check/sicssyntax.tex psi/utils/check/sicssyntaxlib.tcl psi/utils/check/test.tcl psi/utils/check/topsicheck psi/utils/check/tricscheck psi/utils/check/tst
283 lines
8.1 KiB
C
283 lines
8.1 KiB
C
/*--------------------------------------------------------------------------
|
|
|
|
Some code to connect to a serial port through the SINQ system.
|
|
|
|
Just a wrapper around serialsinq derived from David Maden's
|
|
EL734 routines.
|
|
|
|
You are free to use and modify this software for noncommercial
|
|
usage.
|
|
|
|
No warranties or liabilities of any kind taken by me or my employer
|
|
|
|
Very primitive device to send commands to a motor from Tcl
|
|
|
|
Modified version for use within SICS.
|
|
----------------------------------------------------------------------------*/
|
|
#include "sinq_prototypes.h"
|
|
/* #include <timers.h>*/
|
|
#include <tcl.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "rs232c_def.h"
|
|
#include "el734_def.h"
|
|
#include "psi/hardsup/serialsinq.h"
|
|
#include "sics.h"
|
|
|
|
#define False 0
|
|
#define True 1
|
|
|
|
/*---------------------------------------------------------------------------
|
|
Tcl has a high niceness level. It deletes a command properly when
|
|
exiting, reinitializing etc. I use this facility to kill off the
|
|
motor initialised in Controller.
|
|
---------------------------------------------------------------------------*/
|
|
EXTERN void SerialMurder(ClientData pData)
|
|
{
|
|
/*
|
|
NetReadRemoveUserSocket(pServ->pReader, SerialGetSocket(&(pData)));
|
|
*/
|
|
SerialClose(&(pData));
|
|
free(pData);
|
|
}
|
|
/*------------------ a forward declaration -----------------------------*/
|
|
EXTERN int SurielSend(ClientData clientData, Tcl_Interp *interp,
|
|
int argc, char *argv[]);
|
|
|
|
/*----------------------------------------------------------------------------
|
|
Controller is the main entry point for this stuff. It connects to a motor
|
|
and, on success, creates a new command with the name of the motor.
|
|
Syntax:
|
|
Controller name host port channel
|
|
---------------------------------------------------------------------------*/
|
|
|
|
int Controller(ClientData clientData, Tcl_Interp *interp,
|
|
int argc, char *argv[])
|
|
{
|
|
int iRet;
|
|
int iPort, iChannel, iMotor;
|
|
char *pErr = NULL;
|
|
char pBueffel[80];
|
|
void **pData = NULL;
|
|
|
|
/* check arguments */
|
|
if(argc < 5)
|
|
{
|
|
Tcl_AppendResult(interp,
|
|
" Insufficient arguments: Controller name host port channel index"
|
|
, (char *) NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
/* convert arguments */
|
|
iRet = Tcl_GetInt(interp,argv[3],&iPort);
|
|
if(iRet == TCL_ERROR)
|
|
{
|
|
Tcl_AppendResult(interp,"Need integer value for port",
|
|
(char *)NULL);
|
|
return iRet;
|
|
}
|
|
|
|
iRet = Tcl_GetInt(interp,argv[4],&iChannel);
|
|
if(iRet == TCL_ERROR)
|
|
{
|
|
Tcl_AppendResult(interp,"Need integer value for channel",
|
|
(char *)NULL);
|
|
return iRet;
|
|
}
|
|
|
|
iMotor = 1;
|
|
|
|
|
|
/* make a new pointer, initialise EL734st */
|
|
pData = malloc(sizeof(void *));
|
|
if(pData ==NULL)
|
|
{
|
|
Tcl_AppendResult(interp,"No memory in SerialSinq",NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
/* check for optional force flag */
|
|
if(argc > 5)
|
|
{
|
|
iRet = SerialForceOpen(pData, argv[2],iPort,iChannel);
|
|
}
|
|
|
|
/* open the motor, finally */
|
|
iRet = SerialOpen(pData, argv[2],iPort,iChannel);
|
|
if(iRet == 1) /* success */
|
|
{
|
|
/* handle TCL, create new command: the serial line */
|
|
Tcl_CreateCommand(interp,strdup(argv[1]),SurielSend,
|
|
*pData,SerialMurder);
|
|
strcpy(pBueffel,argv[1]);
|
|
Tcl_AppendResult(interp,strdup(argv[1]),(char *)NULL);
|
|
if(pServ->pReader != NULL)
|
|
{
|
|
NetReadRegisterUserSocket(pServ->pReader,
|
|
SerialGetSocket(pData));
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
else
|
|
{
|
|
SerialError(iRet,pBueffel,79);
|
|
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
|
|
SerialClose(pData);
|
|
free(pData);
|
|
return TCL_ERROR;
|
|
}
|
|
}
|
|
/*--------------------------------------------------------------------------
|
|
Now, this interprets some commands:
|
|
-tmo val
|
|
will set a timeout value for the connection. Everything
|
|
else will be concatenated and sent to the device.
|
|
-sendterm text
|
|
defines the terminator which will be appended automatically
|
|
to each command.
|
|
-replyterm text
|
|
sets the expected reply terminator from the Macintosh
|
|
Serial Port server.
|
|
|
|
----------------------------------------------------------------------------*/
|
|
EXTERN int SurielSend(ClientData clientData, Tcl_Interp *interp,
|
|
int argc, char *argv[])
|
|
{
|
|
char pBueffel[256];
|
|
char pAnswer[256];
|
|
char *pErr = NULL;
|
|
int iRet, iMSR;
|
|
int i;
|
|
void *pData;
|
|
|
|
pData = clientData;
|
|
|
|
if(argc >= 2)
|
|
{
|
|
if(strcmp(argv[1],"-tmo") == 0)
|
|
{
|
|
if(argc >= 3)
|
|
{
|
|
iRet = Tcl_GetInt(interp,argv[2],&iMSR);
|
|
if(iRet != TCL_OK)
|
|
{
|
|
sprintf(pBueffel,"%s is not a valid number",argv[2]);
|
|
Tcl_AppendResult(interp,pBueffel,NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
SerialConfig(&(pData),iMSR);
|
|
return TCL_OK;
|
|
}
|
|
else
|
|
{
|
|
Tcl_AppendResult(interp, "Expected parameter after -tmo",NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
}
|
|
else if(strcmp(argv[1],"-sendterm") == 0)
|
|
{
|
|
if(argc < 3)
|
|
{
|
|
Tcl_AppendResult(interp, "Expected parameter after -tmo",NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
iRet = SerialSendTerm(&(pData),argv[2]);
|
|
if(iRet != 1)
|
|
{
|
|
Tcl_AppendResult(interp,"To many characters for terminator",NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
else if(strcmp(argv[1],"-replyterm") == 0)
|
|
{
|
|
if(argc < 3)
|
|
{
|
|
Tcl_AppendResult(interp, "Expected parameter after -tmo",NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
iRet = SerialATerm(&(pData),argv[2]);
|
|
if(!iRet)
|
|
{
|
|
Tcl_AppendResult(interp,"To many characters for terminator",NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
else if(strcmp(argv[1],"-put") == 0)
|
|
{
|
|
NetReadResetUser(pServ->pReader,SerialGetSocket(&(pData)));
|
|
if(argc > 2)
|
|
{
|
|
strcpy(pBueffel,argv[2]);
|
|
}
|
|
for(i = 3; i < argc; i++)
|
|
{
|
|
strcat(pBueffel," ");
|
|
strcat(pBueffel,argv[i]);
|
|
}
|
|
iRet = SerialSend(&(pData),pBueffel);
|
|
if(iRet != 1)
|
|
{
|
|
Tcl_AppendResult(interp,pAnswer,NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
else if(strcmp(argv[1],"-readable") == 0)
|
|
{
|
|
iRet = NetReadReadable(pServ->pReader,SerialGetSocket(&(pData)));
|
|
if(iRet)
|
|
{
|
|
Tcl_AppendResult(interp,"1",NULL);
|
|
return TCL_OK;
|
|
}
|
|
else
|
|
{
|
|
Tcl_AppendResult(interp,"0",NULL);
|
|
return TCL_OK;
|
|
}
|
|
}
|
|
else if(strcmp(argv[1],"-get") == 0)
|
|
{
|
|
if(NetReadReadable(pServ->pReader,SerialGetSocket(&(pData))))
|
|
{
|
|
iRet = SerialReceive(&(pData),pAnswer, 255);
|
|
Tcl_AppendResult(interp,pAnswer,NULL);
|
|
if(iRet == 1)
|
|
{
|
|
return TCL_OK;
|
|
}
|
|
else
|
|
{
|
|
return TCL_ERROR;
|
|
}
|
|
}
|
|
Tcl_AppendResult(interp,"Not Readable",NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
}
|
|
|
|
|
|
if(argc >= 2)
|
|
{
|
|
strcpy(pBueffel,argv[1]);
|
|
}
|
|
for(i = 2; i < argc; i++)
|
|
{
|
|
strcat(pBueffel," ");
|
|
strcat(pBueffel,argv[i]);
|
|
}
|
|
i = strlen(pBueffel);
|
|
iRet = SerialWriteRead(&(pData),pBueffel,pAnswer,254);
|
|
if(iRet != 1)
|
|
{
|
|
Tcl_AppendResult(interp,pAnswer,NULL);
|
|
return TCL_ERROR;
|
|
}
|
|
Tcl_AppendResult(interp,pAnswer,NULL);
|
|
return TCL_OK;
|
|
}
|