Appendix B. Example Programs
B-6
B.3 Modbus® Example Programs
B.3.1 CR1000 Modbus® Control Program
During testing, it was helpful to include an
Autoru
n parameter as
a Boolean variable. It allows the user to set the
Autorun
variable
to false in the
Public
table before opening up the sampler for
servicing without having to cut power to either the datalogger or
the sampler. Also the list of
Responses
includes a string message
for numeric response code (TABLE
). This will allow a text
message to be returned to the user in the data table. The following
program is available for download from the PVS5120 webpages.
'PVS5120/VSC100 program communicating via ModBus
'hardware includes MD485
'Important to remember to first configure the MD485
'then configure the sampler via devconfig
'then service the sampler so the arm is in the correct location and bottles are empty
'then load the program to the datalogger.
'this program also contains a Autorun variable that has to be true for the sampler to sample.
'If it is set to false it will disable the sampler until (for servicing...) it is set true again
'date: 2015-05-04
PreserveVariables
'Declare Public Variables
Public batt_volt 'storing datalogger battery voltage for quality control
Public MBAddress 'Modbus Address of the sampler as set in devconfig.
'The following two variables are used to convert the numeric response code value from the sampler
'to a text message.
Dim Response_List(9) As String
Public response_code_message As String
Public AutoRun As Boolean 'allows the user to prevent the sampler from running on schedule
'via the connect screen without removing power to the sampler or the logger
Public GetStatus As Boolean
Public Run_sampler As Boolean
Public Start_sample As Boolean 'control variable
Public Sampler_status(4)
'*** Status Values returned by the sampler once a sample is collected ****
Alias Sampler_status(1) = CurrentBottle 'Discrete distributor arm position
Alias Sampler_status(2) = SampleCount 'How many samples are currently in bottle
Alias Sampler_status(3) = ResponseCode 'Numeric response code
Alias Sampler_status(4) = SamplerBatt 'Sampler battery voltage (V)
Public MbResult(3)'need a result variable for every modbus instruction
'does not need to be an array
'will increment greater than zero to let you know if a communication does not occur
'in this program MbResult1 error code occurs when communication is lost during any scan interval
'in this program it will increment every 10 secs that communcation is lost.
'MbResult2 error code occurs when the initiate sample command can not be sent to the sampler because
'communications are down. It will increment every 15 minutes.
'Define tables
DataTable (SamplerStat,True,-1) 'stores sampler status values
Sample (1,CurrentBottle,FP2)
Sample (1,SampleCount,FP2)
Sample (1,ResponseCode,FP2)
Sample (1,response_code_message,String)
Sample (1,SamplerBatt,FP2)
EndTable
DataTable (ModbusErrors,true,-1) 'stores the modbus errors
Sample (3,MbResult(),FP2)
EndTable
NOTE
Summary of Contents for PVS5120 Series
Page 2: ......
Page 4: ......
Page 6: ......
Page 8: ......
Page 70: ...Appendix A Sample Transport Velocity A 2...
Page 78: ...Appendix B Example Programs B 8...
Page 86: ...Appendix C Monitoring Sampler Status via RS 485 C 8...
Page 96: ...Appendix G Generic Modbus Control G 4...
Page 100: ...Appendix H ISO5667 Conformity H 4...
Page 101: ......