EPICS Controls 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  2018  2019  2020  2021  2022  2023  <20242025  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  2018  2019  2020  2021  2022  2023  <20242025 
<== Date ==> <== Thread ==>

Subject: An error occurred while using aSub to process Modbus data
From: LONG FENG via Tech-talk <tech-talk at aps.anl.gov>
To: tech-talk at aps.anl.gov
Date: Mon, 4 Nov 2024 16:55:06 +0800
Hi all,

I want to process Modbus format data, but it's not going very smoothly.
My record file content is as follows:  
record(waveform, "Sensor:waveform")
{
    field(DESC, "read data")
    field(DTYP, "stream")
    field(NELM, "40")
    field(FTVL, "UCHAR")
    field(INP, "@RS485Test.proto getData SI")
    field(SCAN, "5 second")
    field(FLNK, "ProcessSensorData")
}

record(aSub, "ProcessSensorData")
{
    field(INAM, "init_dose")
    field(SNAM, "dose")
    field(INPA, "Sensor:waveform NPP NMS")
    field(FTVE, "DOUBLE")
    field(OUTA, "Sensor:ai NPP NMS")
    field(NOVA, "1")
}

record(ai, "Sensor:ai")
{
    field(DESC, "Dose Measurement")
    field(INP, "ProcessSensorData.VALA NPP NMS")
    field(PREC, "3")
    field(EGU, "µSv/h")
    field(SCAN, "Passive")
}



dose.c:
#include <epicsExport.h>
#include <aSubRecord.h>
#include <registryFunction.h>

int init_dose(struct aSubRecord *psub) {
    double *p1 = (double *)psub->vala; 
    *p1 = 0; 
    return 0;
}

int dose(struct aSubRecord *psub) {
    char *inData;
    double *pout1, doseRate;
    unsigned char readData[4] = {0};

    inData = (char *)psub->a;

    pout1 = (double *)psub->vala;
    //
For example, the returned data is: 01 04 0c 14 7b 3e 2e 00 03 00 00 00 00 00 00 ad c9. '14 7b' represents the low byte, and '3e 2e' represents the high byte.  
    readData[0] = inData[4];
    readData[1] = inData[3];
    readData[2] = inData[6];
    readData[3] = inData[5];

    doseRate = *((float*)readData);

    *pout1 = doseRate;

    return 0;
}

epicsRegisterFunction(init_dose); 
epicsRegisterFunction(dose); 
 
 I used caget to observe Sensor:ai, and the result is always:  
Sensor:ai                      2.20405e-38

I think I made a mistake in my processing function, so I wrote a simple test program as follows:
#include <epicsExport.h>
#include <aSubRecord.h>
#include <registryFunction.h>

int init_dose(struct aSubRecord *psub) {
    double *p1 = (double *)psub->vala; 
    *p1 = 0; 
    return 0;
}

int dose(struct aSubRecord *psub) {
    char *inData;
    double *pout1, doseRate;

    inData = (char *)psub->a;

    pout1 = (double *)psub->vala;
    doseRate = inData[3]*0.1;
    *pout1 = doseRate;

    return 0;
}

epicsRegisterFunction(init_dose); 
epicsRegisterFunction(dose); 

However, the result is always:  
Sensor:ai                      0
 
What should I modify? Please help me.  

Feng

Replies:
Re: An error occurred while using aSub to process Modbus data Érico Nogueira Rolim via Tech-talk
RE: An error occurred while using aSub to process Modbus data Mark Rivers via Tech-talk

Navigate by Date:
Prev: Re: a compilation error in the aSub processing function. Ralph Lange via Tech-talk
Next: Re: An error occurred while using aSub to process Modbus data Érico Nogueira Rolim via Tech-talk
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  2018  2019  2020  2021  2022  2023  <20242025 
Navigate by Thread:
Prev: Re: a compilation error in the aSub processing function. Ralph Lange via Tech-talk
Next: Re: An error occurred while using aSub to process Modbus data Érico Nogueira Rolim via Tech-talk
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  2018  2019  2020  2021  2022  2023  <20242025 
ANJ, 05 Nov 2024 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions ·
· Download · Search · IRMIS · Talk · Documents · Links · Licensing ·