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  <20212022  2023  2024  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  <20212022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Re: Re: A problem with modbus reading floating point numbers
From: Mark L Rivers via Tech-talk <tech-talk at aps.anl.gov>
To: 高振华 <gaozh at ihep.ac.cn>
Cc: "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
Date: Fri, 19 Nov 2021 13:21:02 +0000
> 1. Does the modbus enumeration type start at 0 or 1?  Rval is also incorrect when we try to set modbus data type to 0x8.  

It starts at 0.  However, if you use R3-2 of the modbus module then you can replace 0x7 with the string INT32_BE.  This is much easier to understand.  I recommend that you use that version.

But I am still confused about what you are saying.  You said:

> note: I used the AI_scaledValue command to read moxa E1242 instead of the raw AI_rawValue command.  
> Instead of reading the original 2-byte integer, the 4-byte float value converted to the scaled value is read .

If this is really true then you should not be using INT32_BE you should be using FLOAT32_BE (or one of the other FLOAT32 variants).

>  AsynFloat32 type not found,  Only asynFloat32Array was found,Can I use it to read 4-byte float values?

No.  You should use asynFloat64, not asynFloat32.  The driver will convert the value from Float32 to Float64.  That is explained in the documentation here:

Mark





From: 高振华 <gaozh at ihep.ac.cn>
Sent: Friday, November 19, 2021 2:43 AM
To: Mark L Rivers <rivers at cars.uchicago.edu>
Cc: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: Re: Re: Re: A problem with modbus reading floating point numbers
 
Thank you very much,mark.
But I have some questions about modbus datatypes and ASyn interface types:  
1. Does the modbus enumeration type start at 0 or 1?  Rval is also incorrect when we try to set modbus data type to 0x8.  

drvModbusAsynConfigure("MOXA_E1242_In_Word",   "moxa",    255, 4,  0x208,  0x8,    0x8,  2000,    "moxa E1242")

2. AsynFloat32 type not found,  Only asynFloat32Array was found,Can I use it to read 4-byte float values?
Rval is also incorrect when trying to set DTYP to asynFloat32Array.  

record(ai, "$(P)$(R)_AI") {
    field(DTYP,"asynFloat32Array")
    field(INP,"@asynMask($(PORT) $(OFFSET) $(BITS))MODBUS_DATA")
    field(LINR,"LINEAR")
    field(EGUL,"$(EGUL)")
    field(EGUF,"$(EGUF)")
    field(HOPR,"$(EGUF)")
    field(LOPR,"$(EGUL)")
    field(PREC,"$(PREC)")
    field(SCAN,"$(SCAN)")
}

Gao Zhenhua


-----原始邮件-----
发件人:"Mark L Rivers" <rivers at cars.uchicago.edu>
发送时间:2021-11-18 21:32:55 (星期四)
收件人: "高振华" <gaozh at ihep.ac.cn>
抄送: "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
主题: Re: Re: A problem with modbus reading floating point numbers

> note: I used the AI_scaledValue command to read moxa E1242 instead of the raw AI_rawValue command.  
> Instead of reading the original 2-byte integer, the 4-byte float value converted to the scaled value is read .

So the Moxa is returning a 4-byte float, or is it returning an integer?

The drvModbusAsynConfigure command is this:
drvModbusAsynConfigure("MOXA_E1242_In_Word",   "moxa",    255, 4,  0x208,  0x8,    0x7,  2000,    "moxa E1242")

So you are using Modbus data type 0x7 which is INT32_BE.  So the driver is reading a 32-bit integer, not a 32-bit float.

Your ai record is configured for asynInt32 device support:

    field(DTYP,"asynInt32")

If the Moxa is returning a float you need to change both the Modbus data type and the asyn interface in the ai record.

Mark



From: 高振华 <gaozh at ihep.ac.cn>
Sent: Thursday, November 18, 2021 2:29 AM
To: Mark L Rivers <rivers at cars.uchicago.edu>
Cc: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: Re: Re: A problem with modbus reading floating point numbers
 

Hi Mark,

Now rval=7 instead of 49169 for 7.5V.
note:I used the AI_scaledValue command to read moxa E1242 instead of the raw AI_rawValue command.  
Instead of reading the original 2-byte integer, the 4-byte float value converted to the scaled value is read . 


dbpr as follows:
epics> dbpr MOXA:ADC1_AI 2
ACKS: NO_ALARM      ACKT: YES           ADEL: 0             AFTC: 0             
AOFF: 0             ASG :               ASLO: 1             BKPT: 00            
DESC:               DISA: 0             DISP: 0             DISS: NO_ALARM      
DISV: 1             DTYP: asynInt32     EGU :               EGUF: 65535         
EGUL: 0             EOFF: 0             ESLO: 1             EVNT:               
FLNK: CONSTANT      HHSV: NO_ALARM      HIGH: 0             HIHI: 0             
HOPR: 65535         HSV : NO_ALARM      HYST: 0             
INP : INST_IO @asynMask(MOXA_E1242_In_Word 0 16)MODBUS_DATA LCNT: 0             
LINR: LINEAR        LLSV: NO_ALARM      LOLO: 0             LOPR: 0             
LOW : 0             LSV : NO_ALARM      MDEL: 0             NAME: MOXA:ADC1_AI  
NSEV: NO_ALARM      NSTA: NO_ALARM      PACT: 0             PHAS: 0             
PINI: NO            PREC: 3             PRIO: LOW           PUTF: 0             
ROFF: 0             RPRO: 0             RVAL: 7             SCAN: I/O Intr      
SDIS: CONSTANT      SDLY: -1            SEVR: NO_ALARM      SIML: CONSTANT      
SIMM: NO            SIMS: NO_ALARM      SIOL: CONSTANT      SMOO: 0             
SSCN: <nil>         STAT: NO_ALARM      SVAL: 0             
TIME: 2021-11-18 15:14:56.279766515     TPRO: 0             TSE : 0             
TSEL: CONSTANT      UDF : 0             UDFS: INVALID       VAL : 7             
epics>

#traceIO
2021/11/18 15:50:06.322 192.168.127.254:502 write 12

00 99 00 00 00 06 ff 04 02 00 00 04 
2021/11/18 15:50:06.339 192.168.127.254:502 read 17

00 99 00 00 00 0b ff 04 08 c0 11 00 00 00 0f 00 26 
2021/11/18 15:50:06.340 192.168.127.254:502 write 12

00 9a 00 00 00 06 ff 04 02 08 00 08 
2021/11/18 15:50:06.355 192.168.127.254:502 read 25

00 9a 00 00 00 13 ff 04 10 16 30 40 f0 00 00 00 00 00 96 3b 
16 00 be 3b be 

Best Regards, Gao Zhenhua

-----原始邮件-----
发件人:"Mark L Rivers" <rivers at cars.uchicago.edu>
发送时间:2021-11-17 22:22:52 (星期三)
收件人: "高振华" <gaozh at ihep.ac.cn>
抄送: "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
主题: Re: A problem with modbus reading floating point numbers

Hi Gao,

I think I see the problem:

file "../../db/ai.template" { pattern
{P,         R,      PORT,               OFFSET, BITS,  EGUL,  EGUF,   PREC,   SCAN}
{MOXA:,    ADC1,   MOXA_E1242_In_Word,   0,      16,   0.,    65535.,    3,      "I/O Intr"}
{MOXA:,    ADC2,   MOXA_E1242_In_Word,   1,      16,   0.,    65535.,    3,      "I/O Intr"}
}

You have set EGUF to 65535.  If you do that then the ai record will do a linear conversion, but the output values in EGU units will be the same as the input values in RAW units.  You should set the EGUF to be the maximum value of the ADC in the engineering units you want to use.  For example, if it is a 0 to 10V ADC then you can set EGUF=10 and then the ai record will be in the units of volts.  If it is -10V to 10V ADC you should set EGUL=-10.

Mark



From: 高振华 <gaozh at ihep.ac.cn>
Sent: Wednesday, November 17, 2021 2:36 AM
To: Mark L Rivers <rivers at cars.uchicago.edu>
Cc: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: A problem with modbus reading floating point numbers
 
Hi Mark,

I am reading the ai value of moxa E1242 multifunctional IO module and I have a problem,

Cannot display floating point numbers, only integer numbers, 

cannot display decimal places.

What's the reason? thanks.


#moxa1242.cmd
#!./../../bin/linux-x86_64/modbusApp
< envPaths
dbLoadDatabase("../../dbd/modbus.dbd")
modbus_registerRecordDeviceDriver(pdbbase)
drvAsynIPPortConfigure("moxa","192.168.127.254:502",0,0,1)
asynSetOption("moxa",0, "disconnectOnReadTimeout", "Y")
modbusInterposeConfig("moxa",0,5000,0)
#read moxa E1242 AI_scaledValue,7 is little endian,8 is big endian
drvModbusAsynConfigure("MOXA_E1242_In_Word",   "moxa",    255, 4,  0x208,  0x8,    0x7,  2000,    "moxa E1242")
# Enable ASYN_TRACEIO_HEX on octet server
asynSetTraceIOMask("moxa",0,4)
# Enable ASYN_TRACE_ERROR and ASYN_TRACEIO_DRIVER on octet server
asynSetTraceMask("moxa",0,9)
dbLoadTemplate("moxa1242.substitutions")
iocInit
asynReport 1
dbl

#moxa1242.substitutions
#asyn record for the underlying asyn octet port
file "$(ASYN)/db/asynRecord.db" { pattern
{P,           R,       PORT,      ADDR,   IMAX,    OMAX}
{MOXA:    OctetAsyn,    moxa,     0,      80,      80}
}
file "../../db/ai.template" { pattern
{P,         R,      PORT,               OFFSET, BITS,  EGUL,  EGUF,   PREC,   SCAN}
{MOXA:,    ADC1,   MOXA_E1242_In_Word,   0,      16,   0.,    65535.,    3,      "I/O Intr"}
{MOXA:,    ADC2,   MOXA_E1242_In_Word,   1,      16,   0.,    65535.,    3,      "I/O Intr"}
}

#ai.template
record(ai, "$(P)$(R)_AI") {
    field(DTYP,"asynInt32")
    field(INP,"@asynMask($(PORT) $(OFFSET) $(BITS))MODBUS_DATA")
    field(LINR,"LINEAR")
#    field(LINR,"NO CONVERSION")
    field(EGUL,"$(EGUL)")
    field(EGUF,"$(EGUF)")
    field(HOPR,"$(EGUF)")
    field(LOPR,"$(EGUL)")
    field(PREC,"$(PREC)")
    field(SCAN,"$(SCAN)")
}

#traceIO
2021/11/17 15:41:17.075 192.168.127.254:502 write 12

01 17 00 00 00 06 ff 04 02 08 00 08 
2021/11/17 15:41:17.083 192.168.127.254:502 read 25

01 17 00 00 00 13 ff 04 10 13 b0 40 f0 00 00 00 00 00 dc 3b 
5c 00 a0 3b a0 

#caget display
[gaozh@localhost db]$ caget MOXA:ADC1_AI
MOXA:ADC1_AI                   7
note:The actual input is 7.5V.

application environment:
EPICS 7.0.3
Asyn R4-33
Modbus R2-11

Thanks,
Gao Zhenhua

---
BSRF(Beijing Synchrotron Radiation Facility)
Email:gaozh at ihep.ac.cn






--
      
祝好!
高振华

电话:010-88235426
Email:gaozh at ihep.ac.cn


--
      
祝好!
高振华

电话:010-88235426
Email:gaozh at ihep.ac.cn


Replies:
Re: Re: Re: Re: A problem with modbus reading floating point numbers 高振华 via Tech-talk
References:
A problem with modbus reading floating point numbers 高振华 via Tech-talk
Re: A problem with modbus reading floating point numbers Mark L Rivers via Tech-talk
Re: Re: A problem with modbus reading floating point numbers 高振华 via Tech-talk
Re: Re: A problem with modbus reading floating point numbers Mark L Rivers via Tech-talk
Re: Re: Re: A problem with modbus reading floating point numbers 高振华 via Tech-talk

Navigate by Date:
Prev: Re: Re: Re: A problem with modbus reading floating point numbers 高振华 via Tech-talk
Next: RE: CSS (Eclipse and Phoebus) super slow on a server with multiple users Sancho Duarte Andre (F4E-Ext) 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  <20212022  2023  2024 
Navigate by Thread:
Prev: Re: Re: Re: A problem with modbus reading floating point numbers 高振华 via Tech-talk
Next: Re: Re: Re: Re: A problem with modbus reading floating point numbers 高振华 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  <20212022  2023  2024 
ANJ, 22 Nov 2021 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·