Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017 Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
<== Date ==> <== Thread ==>

Subject: RE: Configuring multiple ports with variable port numbers for StreamDevice
From: Mark Rivers <rivers@cars.uchicago.edu>
To: Jonathan Takahashi <jtakahashi@gmail.com>, "tech-talk@aps.anl.gov" <tech-talk@aps.anl.gov>
Date: Tue, 30 May 2017 14:32:10 +0000
I would suggest writing a small C program that is called from st.cmd.  It would do the initialization on port 3000 and then call drvAsynIPPortConfigure for the other 3 ports.  It will give those new asyn ports names that you specify in the arguments to your driver, and that you then use for StreamDevice.

Your driver could look like this:

#include <asynOctetSyncIO.h>

myDriverConfigure(const char IPAddress, const char *portName, const char *portName1, const char *portName2, const char *portName3)
{
  asynUser *pasynUser;
  size_t nBytesOut, nBytesIn;
  int eomReason;
  int port1, port2, port3;
  char *initializationCommand = "your initialization command";
  char readBuffer[256];
  char tmpString[256];

  sprintf(tmpString, "%s:3000", IPAddress)
  drvAsynIPPortConfigure(portName, tmpString, 0, 0, 0);
  asynOctetSyncIO->connect(portName, 0, &pasynUser, 0);
  asynOctetSyncIO->writeRead(pasynUser, initializationCommand", strlen(initializationCommand),
                                                   readBuffer,  sizeof(readBuffer), 1.0, &nBytesOut, &nBytesIn, &eomReason);
  /* Parse the read buffer to determine the port numbers port1-port3 */
  sprintf(tmpString, "%s:%d", IPAddress, port1)
  drvAsynIPPortConfigure(portName1, tmpString, 0, 0, 0);
  sprintf(tmpString, "%s:%d", IPAddress, port2)
  drvAsynIPPortConfigure(portName2, tmpString, 0, 0, 0);
  sprintf(tmpString, "%s:%d", IPAddress, port3)
  drvAsynIPPortConfigure(portName3, tmpString, 0, 0, 0);
}

static const iocshArg myDriverInitArg0 = { "IP address", iocshArgString };
static const iocshArg myDriverInitArg1 = { "Port name", iocshArgString };
static const iocshArg myDriverInitArg2 = { "Port name 1", iocshArgString };
static const iocshArg myDriverInitArg3 = { "Port name 2", iocshArgString };
static const iocshArg myDriverInitArg4 = { "Port name 3", iocshArgString };
static const iocshArg *myDriverInitArgs[] = {
    &myDriverInitArg0,&myDriverInitArg1,&myDriverInitArg2,&myDriverInitArg4,&myDriverInitArg4};
static const iocshFuncDef myDriverInitFuncDef = {
    "myDriverInit", 5, myDriverInitArgs};
static void myDriverInitCallFunc(const iocshArgBuf *args)
{
    myDriverConfigure(args[0].sval,args[1].sval,args[2].sval,,args[3].sval,,args[4].sval);
}

static void myDriverRegister(void)
{
    static int firstTime = 1;
    if (firstTime) {
        firstTime = 0;
        iocshRegister(&myDriverInitFuncDef, myDriverInitCallFunc);
    }
}
epicsExportRegistrar(myDriverRegister);


Mark

________________________________
From: tech-talk-bounces@aps.anl.gov [tech-talk-bounces@aps.anl.gov] on behalf of Jonathan Takahashi [jtakahashi@gmail.com]
Sent: Monday, May 29, 2017 4:43 PM
To: tech-talk@aps.anl.gov
Subject: Configuring multiple ports with variable port numbers for StreamDevice

Hello, total EPICS newbie here... I have a device that communicates via IP ports and is always initialized on port 3000.  When I send an initialization message on that port it returns three new port numbers in a string and sends different types of information over each.  The returned port numbers can vary each time communication is established.  What is the best way to initialize this device?  All the examples I have looked at have only one port initialized in st.cmd using drvAsynIPPortConfigure.

I was thinking I could initialize port 3000 in st.cmd, make a record that passes the initialization command via a stream record, link the output to a scalcout record that parses the string and sends the port number to several subroutine records that initialize the new ports... however that seems complicated and I wanted to ask if there is a better way or if this method would work at all.

References:
Configuring multiple ports with variable port numbers for StreamDevice Jonathan Takahashi

Navigate by Date:
Prev: Configuring multiple ports with variable port numbers for StreamDevice Jonathan Takahashi
Next: Re: alh Rod Nussbaumer
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
Navigate by Thread:
Prev: Configuring multiple ports with variable port numbers for StreamDevice Jonathan Takahashi
Next: Use case for ao record HOPR != DRVH or LOPR != DRVL? J. Lewis Muir
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
ANJ, 30 May 2017 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·