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.

CR1000 program simulation


TomH Oct 16, 2009 02:32 PM

Does simulation software exist to run, test, debug code without loading into the datalogger?


Dana Oct 16, 2009 04:16 PM

The only thing to validate the code is the pre-compiler in CRBasic Editor, but that doesn't provide any kind of run-time feedback.

Regards, Dana


TomH Oct 16, 2009 05:04 PM

Thanks!


SeaZee Jul 30, 2010 02:11 PM

Hi, I realise this is an old thread. I found it because I was searching for the same thing.
It would probably be a good tool for CSI to develop.

Thanks!

Chris


aps Jul 30, 2010 03:35 PM

This has been discussed several times and we always get stuck on the questions of what to do with instructions that read signals or control external devices. In the case of reading signals, e.g. analog, digital or serial, the way the program runs often is determined by the measured values so some values have to be set and changed to test operation of the program fully. Without some simulation of the I/O a simulator almost becomes less useful.

I suppose we could require the user to enter and manually change values as if read by the input instructions but, as this could only happen slowly you would lose all forms of synchronicity with other signals and sequences. It is pretty difficult to emulate the timing of the program too and we could not really emulate communications to remote devices either.

Perhaps you could explain what you need it to emulate to see if something useful could be done bearing in mind the limitations mentioned above.


Sam Aug 2, 2010 05:09 PM

I know this isn't what you are looking for, but the following code could help in your debugging efforts. You still need a data logger to run the program, but with a little extra effort in coding you can create a "debug" output stream. That output can be recorded and reviewed during or after execution. The analogy would be adding "System.out.println" or "Console.Write" lines to your code, using the console to watch debug messages from your program. I encourage you to post your code back to this thread if you make enhancements or come up with a better idea.

Enjoy

---------------------------------------

Public PTemp, batt_volt
Public I

ConstTable
Const Debug = TRUE
Const DebugTo = Table ' Table, ComRS232, Com1, Com2, Com3, Com4
EndConstTable

#If Debug Then
#If DebugTo = Table Then
Dim DebugMsg As String * 31
DataTable (Debug,True,1000)
Sample (1,DebugMsg,String)
EndTable
#EndIf

Sub _Debug(Msg As String * 31)
'wrapping for future support of other options
'Future options might include: Print to serial port,
'IP port, or write to flat file
#If DebugTo = Table Then
DebugMsg = Msg
CallTable (Debug)
#ElseIf (DebugTo = ComRS232) OR (DebugTo = Com1) OR (DebugTo = Com2) OR (DebugTo = Com3) OR (DebugTo = Com4)
SerialOpen (DebugTo,-115200,0,0,100)
SerialOut (DebugTo,Msg + CHR(13) + CHR(10),"",0,0)
SerialClose (DebugTo)
#EndIf
EndSub

#EndIf

DataTable (Test,1,1000)
DataInterval (0,15,Sec,10)
Minimum (1,batt_volt,FP2,0,False)
Sample (1,PTemp,FP2)
EndTable

BeginProg
Scan (5,Sec,0,0)
PanelTemp (PTemp,250)
Battery (batt_volt)

#If Debug Then
Call (_Debug("Entering FOR loop"))
#EndIf

For I = 1 To 10
batt_volt = batt_volt + 100

#If Debug Then
Call (_Debug("I = " + I))
Call (_Debug("Battery = " + batt_volt))
#EndIf

Next I

CallTable Test
NextScan
EndProg


SMM Aug 2, 2010 08:13 PM

So if Loggernet's compiler told me that the program I'm writing did not get to a certain do loop during runtime, that might be because the do loop is activated by a sensor?


Sam Aug 2, 2010 08:30 PM

SMM,

I'm unsure what you are asking. Is this in relation to the program sample provided or an actual error you are experiencing? If it is an error you are experiencing, please post the exact error or send me a screen shot sutley *a/t campbellsci dot com.


SMM Aug 2, 2010 08:39 PM

Hi Sam!

I'm working on the datalogger program, but the instruments haven't arrived yet. I want the logger to record some weather variables every 15 minutes. At the same time, when a tipping bucket rain gauge tips I want the logger to turn on power to the RS232 port and poll a disdrometer until the rain stops.

I have the first scan set to run every 15 minutes, then an infinite do loop, containing a do loop that runs from initial rain gauge tip until measured intensity = zero. This inside do loop runs the disdrometer.

Upon compiling the program, I got 2 messages:

line 120: Warning: Do never reached at run time
line 153: Warning: Loop never reached at run time

line 120 is the Do for the outer do loop, and line 153 is the Loop until Intensity=0 for the inner do loop.

So after all that, I am wondering what those messages mean.


Sam Aug 2, 2010 08:53 PM

I don't this is the right thread for this question. Send me your program (email address above) and I will take a look.


SeaZee Aug 3, 2010 12:58 PM

Hi Sam and APS,

Thank you very much for your considered replys. For me right now(today) I am just going to have to borrow a running datalogger from the field so I can test my program.

What I am mostly testing right now is Modbus communications.

I do see how timing issues could severly limit the general usefulness of a simulator. It makes me curious how some of the PLC simulators work. I will look into it more and if I find anything interesting I will post it here.

Thanks!

Chris


crs Mar 30, 2018 04:23 PM

This has been discussed several times and we always get stuck on the questions of what to do with instructions that read signals or control external devices. 

Would it be possible to provide a means for the programmer to generate data via user-defined functions that could simulate the inputs? 

I think the usefulness of a simulator is mainly in verifying whether your program logic will respond properly to a limited set of scenarios, that are generally anticipated as the code is being developed.  A few extra lines of code (in the form of a function?) could define a time-varying value according to the programmer's interest, which could then be programmatically directed to the appropriate data logger channel in the simulation platform.  


ariklee Apr 3, 2018 08:57 PM

CRS-

You could "simulate" a sensor using the random number generator.  Comment out your analog or digital measurement and add some function or algorithm to replace it. You can write different algorithms to do different things. Here are three:

Public PTemp, Batt_volt
Public Pressure, Pressure1
Public i

BeginProg
  Scan (1,Sec,0,0)
    PanelTemp (PTemp,60)
    Battery (Batt_volt)
Randomize(Batt_volt) 'VoltSe(Pressure, 1, mV5000, 1, 0, 0, _60Hz, 1, 0) i = RND Pressure = Pressure + i ' variable slowly climbs Pressure1 = 100 + i ' random noise in data If i > 0.95 Then Pressure1 = Pressure1 + 100 * i ' random spikes in data
NextScan EndProg

Also, in a complex program that may have multiple conditional statements and branches, you can use a variable as a tracker. In each conditional branch in the program, set the tracker variable to a unique value. You can watch the tracker variable change live in the public table, or add it to a data table where you can also see the values of other variables that affect which branches the code has taken.

EDIT - For simulating controls, I've used LEDs connected to the control ports to see when they are turned off and on. Of course, you can alway save a variable to the data table to know when the control ports are switched too.


crs Apr 4, 2018 03:30 AM

I don't have ready access to a data logger for development purposes, so a separate software simulator would be very helpful.  Currently, I have to stop an ongoing data collection, upload my new program for testing, then change back when done.  In the meantime, I lose out on the data that would be collected.  


lilycollins Jan 11, 2023 01:14 AM

I don't have ready access to a data logger for development purposes, so a separate software simulator would be very helpful.  Currently, I have to stop an ongoing data collection, upload my new program for testing, then change back when done.  In the meantime snake io, I lose out on the data that would be collected. 


tuckerstephanie Jan 31, 2023 04:44 AM

This post is under review.

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