Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

How To Read SR30 Pyranometer Data Into CR1000X Via Modbus


kgrindstaff Feb 4, 2018 02:43 AM

I am trying to read a signed 32bit value from a Hukseflux SR30 pyranometer over RS485 using ModBus RTU into a CR1000X.  The program I have developed is below.  I am not sure if I actually need to combine the two 16-bit values into one to get the signed 32-bit word and if so is the way I have done it correct?  Has anyone used these pyranometers with the CR1000X before that has some examples?

'CR1000

'Declare Variables and Units
Public IRR_GHI_w_M2                ' Irradiance in Watts per square Meter for sensor on Fixed bracket (GHI)
Public GHI_RESP                    ' Modbus Response Code For Read Of GHI Sensor
Public IRR_GHI(2) As Long        ' Raw Modbus Data in 16-Bit Format For GHI Sensor (1)= LSW  (2)=MSW

Alias IRR_GHI(1)=GHI_LSW        ' Least Significant Word For GHI Sensor Modbus Data
Alias IRR_GHI(2)=GHI_MSW        ' Most Significant Word For GHI Sensor Modbus Data

'Declare Constants
ConstTable
    Const BAUD_RATE = 19200        ' Modbus Serial Port Baud Rate
    Const COM_FRMT = 2            ' COM Port Data Format
    Const COM_BUFF = 1000        ' COM Port Buffer Size
    Const IRR_ADDR = 1            ' Irradiance Sensor Modbus Address
    Const IRR_REG = 2            ' SR30 Irradiance Modbus Register
EndConstTable

Units IRR_POA_w_M2=W/m^2
Units IRR_GHI_w_M2=W/m^2


DataTable(DataValues,True,86400)
    DataInterval(0,30,Sec,10)
    TableFile("CRD:MetStn_",8,-1,0,0,Min,OutStat,0)
    Sample(1,IRR_GHI_w_M2,FP2)
EndTable


BeginProg   'Main Program

    'Open COM Port For Pyranometer Communications
    SerialOpen(COM3,BAUD_RATE,COM_FRMT,0,COM_BUFF)            'Open COM Port For GHI Sensor


    'Main Scan
    Scan(30,Sec,1,0)
        ' Read GHI Pyranometer Irradiance From Sensor Using Modbus Via RS485
        'ModbusMaster(ResultCode, ComPort, BaudRate, ModbusAddr, Function, Variable, Start, Length, Tries, TimeOut, VariableFormat)
        ModbusMaster(GHI_RESP, COM3, BAUD_RATE, IRR_ADDR, 3, IRR_GHI(), IRR_REG, 2, 3, 100,2)
        
        ' Combine The Two 16-Bit Registers Into One 32-Bit Signed Word
        If GHI_RESP = 0 Then    ' A Non Zero Response Indicates An Error Reading Modbus Data
            MoveBytes(IRR_GHI_w_M2,2, GHI_LSW,2,2)
            MoveBytes(IRR_GHI_w_M2,0, GHI_MSW,2,2)
            If (IRR_GHI_w_M2<0) Or (IRR_GHI_w_M2=NAN) Then
                IRR_GHI_w_M2=0
            EndIf
        Else
            IRR_GHI_w_M2=0
        EndIf
        
        'Flush GHI Serial Port Buffer
        SerialFlush(COM3)
        
        ' Call Data Tables and Store Data
        CallTable(DataValues)
    
    NextScan

EndProg

Log in or register to post/reply in the forum.