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.

Modbus RS-485 on CR6


_DK_ Feb 26, 2025 07:56 AM

can i code modbus as slave on cr6?

'2023-05-18 By JR 35 VWP, CELL215 on at noon for 1 hour
Public PTemp, Batt_volt

Const nVW = 35
Const A=1.40503E-03' log poly coefficients 3K therm
Const B=2.36939E-04
Const C=1.01266E-07

Public Bunits(nVW),VW_Temp(nVW)
Public VW(nVW,6)
Public Htz(nVW),Amp(nVW),S2N(nVW),NF(nVW),DR(nVW)
Public kPa(nVW)
Public i

Units Bunits() = B
Units Htz = Hz
Units kPa() = kPa
Units VW_Temp() = °C
Units NF = Hz

Public OutString As String * 1000

'CELL2XX Series Variables
Public ModemSTATUS As String * 16 'Tells User when CellModem is ON / OFF
'Cell Modem Diagnostic CR300/CR310/CR1000X/CR6 setup
Public cell_rsrp As Long
Public cell_rssi
Public cell_rsrq
Public cell_ecio
Public cell_status As String * 300
Public cell_state As String * 100
Public cell_info As String * 400
Public cell_ip_address As String * 40
Public cell_todays_usage
Public cell_yesterdays_usage
Public cell_this_months_usage
Public cell_last_months_usage
Public _4G_Signal_Status As String * 32
Public _3G_Signal_Status As String * 32
Public cell_Technology As String * 32
Public Cell_Diversity
Units cell_rssi = dB
Units cell_ecio = dB
Units cell_rsrq = dB
Units cell_rsrp = dBm
Units cell_todays_usage = KB
Units cell_yesterdays_usage = KB
Units cell_this_months_usage = KB
Units cell_last_months_usage = KB

Alias cell_rsrp = rsrp_LTE
Alias cell_rsrq = rsrq_4G
Alias cell_ecio = ecio_3G

' ! ! CH201 ! !
'CR6: U7 CH201: TX
'CR6: G CH201: G
'Global Constants
Const SlowScan = 1 '1 min
'Public variables
Public ChargeState_Status As String * 70 'Displays Charge Status
Public ChargeSource_Status As String * 70 'Displays Charge Status
Public CheckBattery_Status As String * 70 'Displays Charge Status
'Array to hold all the data coming from the CH201
Public Charge_Remaining
Public CH201_M0(9)
'Alias names for array elements.
Alias CH201_M0(1) = VBatt 'Battery voltage (Vdc)
Alias CH201_M0(2) = IBatt 'Current (Amps) going into, or out of, the battery
Alias CH201_M0(3) = ILoad 'Current (Amps) going to the load
Alias CH201_M0(4) = V_in_1 'Voltage (Vdc) coming into the charger on DC IN 1
Alias CH201_M0(5) = V_in_2 'Voltage (Vdc) coming into the charger on DC IN 2
Alias CH201_M0(6) = Chg_TmpC 'Charger temperature (Celsius)
Alias CH201_M0(7) = Chg_State 'Charging state:
' -1 = Regulator Fault
' 0 = No Charge
' 1 = Current Limited
' 2 = Cycle Charging
' 3 = Float Charging
Alias CH201_M0(8)=Chg_Source 'Charging source:
' 0 = None
' 1 = DC In 1
' 2 = DC IN 2
Alias CH201_M0(9)=Ck_Batt 'Check battery error:
' 0 = Normal
' 1 = Check Battery
Public CH201_MX(4) 'Array to hold extended data from the CH201
'Alias names for array elements
Alias CH201_MX(1) = BattTargV 'Battery charging target voltage
Alias CH201_MX(2) = InputVoltControl 'Input voltage control setting
Alias CH201_MX(3) = BattCap 'Present battery capacity
Alias CH201_MX(4) = Qloss 'Battery charge deficit
Public Amp_Hour(3)
'Net Amp-hours used by the entire system
Alias Amp_Hour(1) = Sys_Amp_hr
'Amp-hours used by the datalogger, sensors and communication options
Alias Amp_Hour(2) = Load_Amp_hr
'Amp-hours into the battery. Current out of the battery is
'part of the Load_amp_hr value.
Alias Amp_Hour(3) = Batt_Amp_hr
Units VBatt = Vdc
Units IBatt = A
Units ILoad = A
Units V_in_1 = Vdc
Units V_in_2 = Vdc
Units Chg_TmpC = °C
Units Sys_Amp_hr = A/Hr
Units Load_Amp_hr = A/Hr
Units Batt_Amp_hr = A/Hr
Units Qloss = A/Hr
Units Charge_Remaining = %

Public ModIn(9)
Public Counter
'Public Modbus(2)
Public ModbusCoil(9) As Boolean
Public Xvar As Boolean

Sub CH201_Charger
'Get CH201 values
SDI12Recorder(CH201_M0(),U7,0,"MC!",1.0,0,0)
'Get extended status values
SDI12Recorder(CH201_MX(),U7,0,"M2!",1.0,0)
'Current values coming from the CH201 are in amps. Have to convert that to
'amp-hours based on the scan rate.
Batt_Amp_hr = IBatt * SlowScan/60
Load_Amp_hr = ILoad * SlowScan/60
Sys_Amp_hr = Load_Amp_hr + Batt_Amp_hr
Charge_Remaining = ((BattCap - Qloss)/BattCap)*100

If Chg_State = -1 Then
ChargeState_Status = "WARNING: REGULATOR FAULT"
ElseIf Chg_State = 0 Then
ChargeState_Status = "WARNING: NO CHARGE"
ElseIf Chg_State = 1 Then
ChargeState_Status = "CURRENT LIMITED"
ElseIf Chg_State = 2 Then
ChargeState_Status = "CYCLE CHARGING"
ElseIf Chg_State = 3 Then
ChargeState_Status = "FLOAT CHARGING"
EndIf

If Chg_Source = 0 Then
ChargeSource_Status = "WARNING: NO CHARGE SOURCE"
ElseIf Chg_Source = 1 Then
ChargeSource_Status = "DC In 1"
ElseIf Chg_Source = 2 Then
ChargeSource_Status = "DC In 2"
EndIf

If Ck_Batt = 0 Then
CheckBattery_Status = "NORMAL OPERATION"
ElseIf Ck_Batt = 1 Then
CheckBattery_Status = "CHECK BAT - <10.5V or Open Circuit"
EndIf
EndSub

DataTable (VWire,1,-1)
Sample (1,Batt_volt,FP2)
Sample (1,PTemp,FP2)
Sample (nVW,kPa(),IEEE4)
Sample (nVW,Bunits(),IEEE4)
Sample (nVW,VW_Temp(),IEEE4)
EndTable

'Define CELL2XX Data Tables
DataTable(CellModem_diagnostic, True,-1)'Limiting '****CELL2XX Diagnostic Variables***
'**** END CELL2XXthe size of diagnostic to 50 - rewrites over old data
Sample (1, cell_rssi,IEEE4)
FieldNames("Signal_Strength_rssi")
Sample (1,_3G_Signal_Status,String)
Sample (1,cell_ip_address,String)
FieldNames("IPv4_Address")
Sample (1, cell_rsrp,IEEE4)
FieldNames("LTE_rsrp")
Sample (1,_4G_Signal_Status,String)
Sample (1, cell_rsrq,FP2)
FieldNames("4G_rsrq")
Sample (1, cell_ecio,FP2)
FieldNames("3G_ecio")
Sample(1,cell_info,String)
FieldNames("Cell_Info")
Sample (1,cell_status,String)
FieldNames("Current_Status")
Sample (1,cell_state,String)
FieldNames("Current_State") '"Power off.", "Powering up.", "Powered up.", "SIM authorized.", "Setting baud rate.", "Waiting for baud rate.", "Baud rate set.", "Baud rate failure.",
'"Power off. Waiting for retry.", "Powered up. SIM authfailure.", "Querying modem.", "Waiting for network registration.", "Configuring modem.",
'"Dialing.", "Dialing (retry).", "Dialed.", "PPP negotiation.", "Network ready.", "PPP closing.", "PPPpaused.", "PPP dropped.", "Terminal AT command mode.",
'"Firmware update mode.", “Shutting down.” (BUT NOT LIMITED)
Sample(1,cell_todays_usage,FP2)
Sample(1,cell_yesterdays_usage,FP2)
Sample(1,cell_this_months_usage,FP2)
Sample(1,cell_last_months_usage,FP2)
Sample (1,Cell_Diversity,String)
EndTable

DataTable(CH201_DATA,1,-1)
DataInterval(0,1,Hr,10)
Sample(6,CH201_M0(),FP2)
Sample(1,Batt_Amp_hr,FP2)
Sample(1,Load_Amp_hr,FP2)
Sample(1,Sys_Amp_hr,FP2)
Sample(1,ChargeSource_Status,String)
Sample(1,CH201_M0(7),FP2)
Sample(1,ChargeState_Status,String)
Sample(1,CheckBattery_Status,String)
Sample(1,CH201_M0(9),FP2)
Sample(1,BattTargV,FP2)
Sample(1,InputVoltControl,FP2)
Sample(1,BattCap,FP2)
Sample(1,Charge_Remaining,FP2)
EndTable

'Main Program
BeginProg
Call CH201_Charger
SerialOpen(ComC3,9600,0,0,1000)
' ModbusSlave(ComC3,9600,1,ModIn(),ModbusCoil(),2)
ModbusServer(ComC3, 9600,1,ModIn(),0)
Scan (1,Min,0,0)
' SerialOpen (ComC3,9600,16,0,1000)
Delay (0,50,mSec)
PanelTemp (PTemp,50)
Battery (Batt_volt)
Call CH201_Charger
CallTable CH201_DATA

If TimeIsBetween (12,13,24,Hr)Then 'Modem On at Noon for 1HR
IPNetPower (5,-1) 'Enable Cell Modem on all the time.
ModemSTATUS = "Modem_ON"
'Cell Modem status
cell_ip_address = IPInfo(1,0)
cell_rssi = Settings.CellRSSI
cell_info = Settings.CellInfo
'Cell Info. Same information that shows in the
'DevConfig Cellular Network Status field
cell_status = Settings.Cellstatus
cell_state = Settings.Cellstate ' State that the modem is in. "Network Ready" lets me know my modem is good to go.
cell_rsrp = Settings.CellRSRP
'Reference signal received power for LTE in dbm.
'Very similar to RSSI
cell_ecio = Settings.CellECIO 'Reference signal received quality for 3G.
cell_rsrq = Settings.CellRSRQ 'Reference signal received quality for 4G.
cell_todays_usage = Settings.CellUsageToday 'usage reported KB
cell_yesterdays_usage = Settings.CellUsageYesterday 'usage reported in KB
cell_this_months_usage = Settings.CellUsageMonth ' usage reported in KB
cell_last_months_usage = Settings.CellUsageLastMonth ' usage reported in KB

SplitStr (cell_Technology,cell_info,"LTE",1,2)
If cell_Technology = "LTE" Then
cell_Technology = "LTE"
Else
cell_Technology = "3G"
EndIf
If cell_Technology = "LTE" Then
_3G_Signal_Status = "Not in USE"
If cell_rsrp >= -80 Then
_4G_Signal_Status = "Excellent"
ElseIf cell_rsrp < -80 AND cell_rsrp >= -90 Then
_4G_Signal_Status = "Good"
ElseIf cell_rsrp > -100 AND cell_rsrp < -90 Then
_4G_Signal_Status = "Fair to Poor"
ElseIf cell_rsrp <= -100 Then
_4G_Signal_Status = "No Signal"
Else
_4G_Signal_Status = "Not in USE"
EndIf
Else
_4G_Signal_Status = "Not in USE"
If cell_rssi >= -70 Then
_3G_Signal_Status = "Excellent"
ElseIf cell_rssi < -70 AND cell_rssi >= -85 Then
_3G_Signal_Status = "Good"
ElseIf cell_rssi > -100 AND cell_rssi < -85 Then
_3G_Signal_Status = "Fair"
ElseIf cell_rssi <= -100 Then
_3G_Signal_Status = "Poor"
ElseIf cell_rssi <= -110 Then
_3G_Signal_Status = "No Signal"
Else
_3G_Signal_Status = "Not in USE"
EndIf
EndIf

CallTable CellModem_diagnostic 'Get Diagnostics data to a table

Else
ModemSTATUS = "Modem_OFF"
IPNetPower (5,0) 'Disable Cell Modem
EndIf

If TimeIntoInterval (0,6,Hr) Then ' *** CHECK INTERVAL - 2020-06-11

PortSet (U2,1) 'Reset
Delay(0,100,mSec)
For i=1 To nVW
PulsePort (U1,5000) 'Clock
Delay(0,100,mSec)
VibratingWire (VW(i,1),1,U3,1500,3500,1,0.05,"",60,A,B,C)
Htz(i)=VW(i,1)'frequency
Amp(i)=VW(i,2)'amplitude
S2N(i)=VW(i,3)'signal to noise ratio
NF(i)=VW(i,4)'noise frquency
DR(i)=VW(i,5)'decay ratio
Bunits(i) = (VW(i,1)^2)/1000 'Convert to B Units
VW_Temp(i)= VW(i,6) 'Temperature
Next i
PortSet (U2,0)


'************************************************************************************
'Convert Piezometer B Units to MPa & KPa - serial number must match channel

' ******* 'ENTER CORRECT CALIBRATION CONSTANTS FROM CAL SHEETS BELOW!!! ************
'MAKE SURE SENSOR NUMBER MATCHES MUX CHANNEL NUMBER!!!
'*** Engineering Units ***

'Example: kpa(1) = <Calibration Factor> * ( <Initial Reading> - Bunits(1)) - <Temperature Correction Factor> * ( <Initial Reading> - VW_Temp(1)) + ( <Initial Reading> - pressure_kpa)
kPa(1) = 0.000 * ( 0.000 - Bunits(1)) - 0.000 * ( 0.000 - VW_Temp(1)) '# VW Sensor s/n VW49870 MUX 1, CH.1
kPa(2) = 0.000 * ( 0.000 - Bunits(2)) - 0.000 * ( 0.000 - VW_Temp(2)) '# VW Sensor s/n VWXXXXX MUX 1, CH.2
kPa(3) = 0.000 * ( 0.000 - Bunits(3)) - 0.000 * ( 0.000 - VW_Temp(3)) '# VW Sensor s/n VWXXXXX MUX 1, CH.3
kPa(4) = 0.000 * ( 0.000 - Bunits(4)) - 0.000 * ( 0.000 - VW_Temp(4)) '# VW Sensor s/n VWXXXXX MUX 1, CH.2
kPa(5) = 0.000 * ( 0.000 - Bunits(5)) - 0.000 * ( 0.000 - VW_Temp(5)) '# VW Sensor s/n VWXXXXX MUX 1, CH.3

kPa(6) = 0.000 * ( 0.000 - Bunits(6)) - 0.000 * ( 0.000 - VW_Temp(6)) '# VW Sensor s/n VWXXXXX MUX 2, CH.1
kPa(7) = 0.000 * ( 0.000 - Bunits(7)) - 0.000 * ( 0.000 - VW_Temp(7)) '# VW Sensor s/n VWXXXXX MUX 2, CH.2
kPa(8) = 0.000 * ( 0.000 - Bunits(8)) - 0.000 * ( 0.000 - VW_Temp(8)) '# VW Sensor s/n VWXXXXX MUX 2, CH.3
kPa(9) = 0.000 * ( 0.000 - Bunits(9)) - 0.000 * ( 0.000 - VW_Temp(9)) '# VW Sensor s/n VWXXXXX MUX 2, CH.4
kPa(10) = 0.000 * ( 0.000 - Bunits(10)) - 0.000 * ( 0.000 - VW_Temp(10)) '# VW Sensor s/n VWXXXXX MUX 2, CH.5

kPa(11) = 0.000 * ( 0.000 - Bunits(11)) - 0.000 * ( 0.000 - VW_Temp(11)) '# VW Sensor s/n VWXXXXX MUX 3, CH.1
kPa(12) = 0.000 * ( 0.000 - Bunits(12)) - 0.000 * ( 0.000 - VW_Temp(12)) '# VW Sensor s/n VWXXXXX MUX 3, CH.2
kPa(13) = 0.000 * ( 0.000 - Bunits(13)) - 0.000 * ( 0.000 - VW_Temp(13)) '# VW Sensor s/n VWXXXXX MUX 3, CH.3
kPa(14) = 0.000 * ( 0.000 - Bunits(14)) - 0.000 * ( 0.000 - VW_Temp(14)) '# VW Sensor s/n VWXXXXX MUX 3, CH.4
kPa(15) = 0.000 * ( 0.000 - Bunits(15)) - 0.000 * ( 0.000 - VW_Temp(15)) '# VW Sensor s/n VWXXXXX MUX 3, CH.5

kPa(16) = 0.000 * ( 0.000 - Bunits(16)) - 0.000 * ( 0.000 - VW_Temp(16)) '# VW Sensor s/n VWXXXXX MUX 4, CH.1
kPa(17) = 0.000 * ( 0.000 - Bunits(17)) - 0.000 * ( 0.000 - VW_Temp(17)) '# VW Sensor s/n VWXXXXX MUX 4, CH.2
kPa(18) = 0.000 * ( 0.000 - Bunits(18)) - 0.000 * ( 0.000 - VW_Temp(18)) '# VW Sensor s/n VWXXXXX MUX 4, CH.3
kPa(19) = 0.000 * ( 0.000 - Bunits(19)) - 0.000 * ( 0.000 - VW_Temp(19)) '# VW Sensor s/n VWXXXXX MUX 4, CH.4
kPa(20) = 0.000 * ( 0.000 - Bunits(20)) - 0.000 * ( 0.000 - VW_Temp(20)) '# VW Sensor s/n VWXXXXX MUX 4, CH.5

kPa(21) = 0.000 * ( 0.000 - Bunits(21)) - 0.000 * ( 0.000 - VW_Temp(21)) '# VW Sensor s/n VWXXXXX MUX 5, CH.1
kPa(22) = 0.000 * ( 0.000 - Bunits(22)) - 0.000 * ( 0.000 - VW_Temp(22)) '# VW Sensor s/n VWXXXXX MUX 5, CH.2
kPa(23) = 0.000 * ( 0.000 - Bunits(23)) - 0.000 * ( 0.000 - VW_Temp(23)) '# VW Sensor s/n VWXXXXX MUX 5, CH.3
kPa(24) = 0.000 * ( 0.000 - Bunits(24)) - 0.000 * ( 0.000 - VW_Temp(24)) '# VW Sensor s/n VWXXXXX MUX 5, CH.4
kPa(25) = 0.000 * ( 0.000 - Bunits(25)) - 0.000 * ( 0.000 - VW_Temp(25)) '# VW Sensor s/n VWXXXXX MUX 5, CH.5

kPa(26) = 0.000 * ( 0.000 - Bunits(26)) - 0.000 * ( 0.000 - VW_Temp(26)) '# VW Sensor s/n VWXXXXX MUX 6, CH.1
kPa(27) = 0.000 * ( 0.000 - Bunits(27)) - 0.000 * ( 0.000 - VW_Temp(27)) '# VW Sensor s/n VWXXXXX MUX 6, CH.2
kPa(28) = 0.000 * ( 0.000 - Bunits(28)) - 0.000 * ( 0.000 - VW_Temp(28)) '# VW Sensor s/n VWXXXXX MUX 6, CH.3
kPa(29) = 0.000 * ( 0.000 - Bunits(29)) - 0.000 * ( 0.000 - VW_Temp(29)) '# VW Sensor s/n VWXXXXX MUX 6, CH.4
kPa(30) = 0.000 * ( 0.000 - Bunits(30)) - 0.000 * ( 0.000 - VW_Temp(30)) '# VW Sensor s/n VWXXXXX MUX 6, CH.5

kPa(31) = 0.000 * ( 0.000 - Bunits(31)) - 0.000 * ( 0.000 - VW_Temp(31)) '# VW Sensor s/n VWXXXXX MUX 6, CH.1
kPa(32) = 0.000 * ( 0.000 - Bunits(32)) - 0.000 * ( 0.000 - VW_Temp(32)) '# VW Sensor s/n VWXXXXX MUX 6, CH.2
kPa(33) = 0.000 * ( 0.000 - Bunits(33)) - 0.000 * ( 0.000 - VW_Temp(33)) '# VW Sensor s/n VWXXXXX MUX 6, CH.3
kPa(34) = 0.000 * ( 0.000 - Bunits(34)) - 0.000 * ( 0.000 - VW_Temp(34)) '# VW Sensor s/n VWXXXXX MUX 6, CH.4
kPa(35) = 0.000 * ( 0.000 - Bunits(35)) - 0.000 * ( 0.000 - VW_Temp(35)) '# VW Sensor s/n VWXXXXX MUX 6, CH.5

Counter = 0
CallTable VWire
EndIf
Counter += 1
ModIn(1) = 40001 = VW_Temp(13)
ModIn(2) = 40002 = VW_Temp(14)
ModIn(3) = 40003 = VW_Temp(15)
ModIn(4) = 40004 = VW_Temp(16)
ModIn(5) = 40005 = VW_Temp(28)
ModIn(6) = 40006 = VW_Temp(32)
ModIn(7) = 40007 = Counter
ModIn(8) = 40008 = Batt_volt
ModIn(9) = 40009 = PTemp
'
' ModIn(1) = VW_Temp(13)
' ModIn(2) = VW_Temp(14)
' ModIn(3) = VW_Temp(15)
' ModIn(4) = VW_Temp(16)
' ModIn(5) = VW_Temp(28)
' ModIn(6) = VW_Temp(32)
' ModIn(7) = Counter
' ModIn(8) = Batt_volt
' ModIn(9) = PTemp

NextScan
EndProg

and this my program, the result on my modbus poll is zero (on all datas)

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