CR1000 program simulation_Campbellsci论坛问答

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

CR1000 program simulation_Campbellsci论坛问答

新对话如下:

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

新对话如下:

Thanks!

新对话如下:

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

新对话如下:

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.

新对话如下:

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

新对话如下:

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?

新对话如下:

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.

新对话如下:

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.

新对话如下:

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

新对话如下:

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

新对话如下:

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.  

新对话如下:

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.

新对话如下:

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.  

新对话如下:

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. 

分享到:

原文链接:,转发请注明来源!
海洋仪器网 仪器使用 CR1000 program simulation_Campbellsci论坛问答
「CR1000 program simulation_Campbellsci论坛问答」评论列表

发表评论