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.

Writing on a variable through MODBUS


Ing. Paolo Diaz Jul 19, 2023 04:55 PM

I setting up a CR350 to a remote location where it records variables once an hour, but we expect that once or twice a year, a different team might move some parameters from the instrument and we want to update them remotely to keep cost low, how can I set up a variable so I can update it through MODBUS and having it safe guarded in case of reboots/power cycles?

Initally I had structured my code to something like this (this is not the real code)

'++Declare Public Variables

Public SetpointVar1 'Value that I wish to uptade through modbus
Public SetpointVar2 'Value that I wish to uptade through modbus
Public TableVar 'Recorded value
Public modbusData(3) As Long 'Modbus slots declaration

'++Declare Tables
DataTable (MainTable,true,-1)
	DataInterval (0,3600,Sec,1)  
	Maximum (1,TableVar,IEEE4,False,False)
EndTable

'++Main Program
BeginProg
  SerialOpen (Com2,9600,0,0,50)
  ModbusSlave (Com2,9600,1,modbusData(),0)
	Scan (1,Sec,0,0)
                SetpointVar1 = modbusData(2)
                SetpointVar2 = modbusData(3)
		CurrentSE (Flujo,1,mV2500,2,1,0,60,-1*SetpointVar1,-4*SetpointVar2)
		CallTable Principal
		'Modbustable 
   		  modbusData(1) = MainTable.TableVar_Max*100
	NextScan
EndProg

 

And it worked fine, I was able to write through an MODBUS F16 and it was updating in real time, then, because anything can happen in remote places like where this device is going despite having batteries, I powered off the device to see if the values would hold, but these MODBUS field went back to 0 (I had other variables and scans tied to constant values and those worked fine after the reboot) then I tried like this but would still go back to 0 after the power cycle.

 

'++Main Program
BeginProg
  SerialOpen (Com2,9600,0,0,50)
  ModbusSlave (Com2,9600,1,modbusData(),0)
  modbusData(2) = SetpointVar1 'New line
  modbusData(3) = SetpointVar2 'New line
	Scan (1,Sec,0,0)
                SetpointVar1 = modbusData(2)
                SetpointVar2 = modbusData(3)
		CurrentSE (Flujo,1,mV2500,2,1,0,60,-1*SetpointVar1,-4*SetpointVar2)
		CallTable Principal
		'Modbustable 
   		  modbusData(1) = MainTable.TableVar_Max*100
	NextScan
EndProg

 

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