![]() |
![]() ![]()
Experimental Physics and
| ||||||||||||||
|
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
| ||||||||||||||
ANJ, 05 Nov 2024 |
![]() · Download · Search · IRMIS · Talk · Documents · Links · Licensing · |