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.

Troubleshooting CR6 as Modbus Slave


SteveA Oct 9, 2018 03:01 PM

I tried posting this before, but I don't think it posted, so here goes again...

I've got a CR6 which I've programmed to be a modbus slave. I feel like it seems like it should be fairly simple and I feel fairly confident in the program; however, when I run Modbus Poll to check that the holding registers are populating correctly all I get is a timeout error. The datalogger is definitely getting the requests for data (monitored through dev config terminal window), but no data seems to be getting through. The terminal window says:
17:26:39.597 R 01 32 .2
17:26:39.607 R C4 1F ..
17:26:40.668 R 01 32 .2
17:26:40.678 R C4 1F ..
17:26:41.738 R 01 32 C4 .2.
17:26:41.748 R 1F .
17:26:42.809 R 01 32 C4 .2.
17:26:42.819 R 1F .
17:26:43.879 R 01 32 C4 1F .2..
17:26:44.950 R 01 32 C4 1F .2..
I'm fairly new to modbus, but if I understand it right, each of the lines with an "R" above is a response from the datalogger, which is odd since I thought it would also show the message from the master with a "T" by it. In any case, does anyone have an idea what might be going on? Thanks in advance.


My code is reproduced below. I don't have the two multiplexers wired, but I figured I could just check that the batt and temp values were being recorded in registers 1,2 and 3,4, respectively.

 

'Declare Variables and Units
Dim Count
Dim Count_2
Public BattV
Public FCLoaded
Public PTemp_C
Public VW(6)
Public ZMode
Public CIndex
Public CAvg
Public Freq(15)
Public Amp(15)
Public SNRat(15)
Public NFreq(15)
Public DRat(15)
Public TT(15)
Public TT0(15)
Public Digits(15)
Public Digits0(15)
Public Strain(15)
Public VW_2(6)
Public ZMode_2
Public CIndex_2
Public CAvg_2
Public Freq_2(15)
Public Amp_2(15)
Public SNRat_2(15)
Public NFreq_2(15)
Public DRat_2(15)
Public TT_2(15)
Public TT0_2(15)
Public Digits_2(15)
Public Digits0_2(15)
Public Strain_2(15)

Public ModbusRegisters(62)
Public ModbusCoil As Boolean

Units BattV=Volts
Units PTemp_C=Deg C
Units Freq=Hz
Units Amp=mV RMS
Units NFreq=Hz
Units TT=deg C
Units TT0=deg C
Units Digits=digits
Units Digits0=digits
Units Strain=microstrain
Units Freq_2=Hz
Units Amp_2=mV RMS
Units NFreq_2=Hz
Units TT_2=deg C
Units TT0_2=deg C
Units Digits_2=digits
Units Digits0_2=digits
Units Strain_2=microstrain

'Define Data Tables
DataTable(StrainTab,True,-1)
	DataInterval(0,60,Min,10)
	Sample(1,Freq(),FP2)
	Sample(1,Amp(),FP2)
	Sample(1,SNRat(),FP2)
	Sample(1,NFreq(),FP2)
	Sample(1,DRat(),FP2)
	Sample(1,TT(),FP2)
	Sample(1,Digits(),IEEE4)
	Sample(1,Strain(),IEEE4)

	Sample(1,Freq_2(),FP2)
	Sample(1,Amp_2(),FP2)
	Sample(1,SNRat_2(),FP2)
	Sample(1,NFreq_2(),FP2)
	Sample(1,DRat_2(),FP2)
	Sample(1,TT_2(),FP2)
	Sample(1,Digits_2(),IEEE4)
	Sample(1,Strain_2(),IEEE4)
EndTable

DataTable(VitalsTab,True,-1)
	DataInterval(0,1440,Min,10)
	Minimum(1,BattV,FP2,False,False)
	Sample(1,PTemp_C,FP2)
EndTable

'Calibration history table
DataTable(CalHist,NewFieldCal,10)
	SampleFieldCal
EndTable

'Main Program
BeginProg
  
  'Configure the datalogger as a Modbus Slave
  ModbusSlave(ComRS232,9600,1,ModbusRegisters(),ModbusCoil,2)
  
	'Initialize calibration variables for
	'Geokon 4100 Series & 4202 Vibrating Wire Strain Gage calculation 'Strain()'
	CIndex=1 : CAvg=1
	'Initialize calibration variables for
	'Geokon 4100 Series & 4202 Vibrating Wire Strain Gage calculation 'Strain_2()'
	CIndex_2=1 : CAvg_2=1
	'Load the most recent calibration values from the CalHist table
	FCLoaded=LoadFieldCal(True)
	'Main Scan
	Scan(60,Sec,1,0)
		'Default CR6 Datalogger Battery Voltage measurement 'BattV'
		Battery(BattV)
		'Default CR6 Datalogger Wiring Panel Temperature measurement 'PTemp_C'
		PanelTemp(PTemp_C,60)
		'Turn AM16/32 Multiplexer On
		PortSet(U2,1)
		Delay(0,150,mSec)
		Count=1
		
		'Populate Modbus Registers for Temp & Batt
		ModbusRegisters(1) = BattV
		ModbusRegisters(2) = PTemp_C
		
		SubScan(0,uSec,15)
			'Switch to next AM16/32 Multiplexer channel
			PulsePort(U1,10000)
			'Geokon 4100 Series & 4202 Vibrating Wire Strain Gage measurement 'Freq()'
			VibratingWire(VW(1),1,U3,1400,3500,1,0.01,"",60,1.4051E-3,2.369E-4,1.019E-7)
			Freq(Count)=VW(1)
			Amp(Count)=VW(2)
			SNRat(Count)=VW(3)
			NFreq(Count)=VW(4)
			DRat(Count)=VW(5)
			TT(Count)=VW(6)
			'Calculate digits 'Digits()'
			Digits(Count)=Freq(Count)^2/1000
			'Calculate strain 'Strain()'
			Strain(Count)=(Digits(Count)-Digits0(Count))*0.391*1
			
			'Populate Modbus Registers for Multiplexer1
			  ModbusRegisters(Count*2+2) = Strain(Count)
			  ModbusRegisters(Count*2+3) = TT(Count)
			  
			Count=Count+1
		NextSubScan
		'Zeroing calibration for
		'Geokon 4100 Series & 4202 Vibrating Wire Strain Gage calculations 'Digits()' and 'TT()'
		FieldCal(4,Digits(),15,0,Digits0(),ZMode,0,CIndex,CAvg)
		FieldCal(4,TT(),15,0,TT0(),ZMode,0,CIndex,CAvg)
		'Turn AM16/32 Multiplexer Off
		PortSet(U2,0)
		Delay(0,150,mSec)
		'Turn AM16/32 Multiplexer On
		PortSet(U7,1)
		Delay(0,150,mSec)
		Count_2=1
		SubScan(0,uSec,15)
			'Switch to next AM16/32 Multiplexer channel
			PulsePort(U1,10000)
			'Geokon 4100 Series & 4202 Vibrating Wire Strain Gage measurement 'Freq_2()'
			VibratingWire(VW_2(1),1,U9,1400,3500,1,0.01,"",60,1.4051E-3,2.369E-4,1.019E-7)
			Freq_2(Count_2)=VW_2(1)
			Amp_2(Count_2)=VW_2(2)
			SNRat_2(Count_2)=VW_2(3)
			NFreq_2(Count_2)=VW_2(4)
			DRat_2(Count_2)=VW_2(5)
			TT_2(Count_2)=VW_2(6)
			'Calculate digits 'Digits_2()'
			Digits_2(Count_2)=Freq_2(Count_2)^2/1000
			'Calculate strain 'Strain_2()'
			Strain_2(Count_2)=(Digits_2(Count_2)-Digits0_2(Count_2))*0.391*1
			'Populate Modbus Registers for Multiplexer2
			  ModbusRegisters(Count_2*2+32) = Strain(Count)
			  ModbusRegisters(Count_2*2+33) = TT(Count)
			Count_2=Count_2+1
		NextSubScan
		'Zeroing calibration for
		'Geokon 4100 Series & 4202 Vibrating Wire Strain Gage calculations 'Digits_2()' and 'TT_2()'
		FieldCal(4,Digits_2(),15,0,Digits0_2(),ZMode_2,0,CIndex_2,CAvg_2)
		FieldCal(4,TT_2(),15,0,TT0_2(),ZMode_2,0,CIndex_2,CAvg_2)
		'Turn AM16/32 Multiplexer Off
		PortSet(U7,0)
		Delay(0,150,mSec)

		'Call Data Tables and Store Data
		CallTable StrainTab
		CallTable VitalsTab
		CallTable CalHist
	NextScan
EndProg

 


Jaab Oct 9, 2018 07:35 PM

Running your program on my CR6 with OS 8 and polling with Modbus Poll I do not get an errors. Please verify your Modbus Poll software is configured for the correct serial port and 9600 8 data bits, 1 stop bit and no parity. 

To your point about T's and R's in the loggers terminal window, R's mean recieved from the Master and T's would mean transfer to the Master. In your trace it appears you getting quite a few recieved transmissions from the master. 


SteveA Oct 9, 2018 09:55 PM

Jaab,

Thanks for your reply.  Yes, I'm configured for the correct serial port with 9600 baud, 8 data bits, 1 stop bit and no parity.  Thanks for trying out my code, at least I know that the problem isn't there.  I assume then that it's due to my lack of familiarity with Modbus Poll which I am using as well (for the first time).  I'll try messing around with it in the morning to see if there is something else I'm missing.

Thanks! 


SteveA Oct 10, 2018 05:43 PM

After messing around with it for a while I realized that I'm blind and had read it incorrectly and had even parity set which was why it wouldn't connect.  Jaab, thanks for your help, it really helped knowing it wasn't something wrong with my code.  I would have spent a while messing around with that too.

Steve

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