经过加里·罗伯茨|Updated: 05/31/2017 | Comments: 2
在跳过扫描方面,也许您就像我一样。我一直不喜欢看到我的数据记录仪中的跳过扫描。我已经受过训练来提防他们,并尽力编写我的CRBASIC程序,以使它们不出现。坎贝尔科学支持和实施工程师(正式称为应用程序工程师或AES)告诉我,跳过扫描是我系统中麻烦的标志。当我看到它们时,有些不对劲,我需要在失去太多数据之前对我的车站进行一些维护。
Skipped scans, when used this way, are a good thing, right? They let us know that something is wrong.
跳过扫描有时会告诉我们,我们有一个SDI-12传感器,该传感器不再正确响应或在我们期望的时间内响应。跳过扫描还可以告诉我们,某些TCP/IP功能(例如EmailSend()或ftpClient()的功能太长或无法正常工作。这是我们使用的绝佳诊断信息。(阅读“技巧和窍门:跳过跳过hooray [不]”文章了解更多信息。)
主扫描和每个慢速序列(CRBASIC程序中最多四个)在状态表中有一个记录,显示了数据记录器无法完成扫描的次数。命名的行SkippedScan在状态表中,告诉我们主要扫描尚未完全完成的次数。这Skippedslowscan(x)rows tells us the same thing for each slow scan (“x” being the number of the slow scan it is associated with).
SkippedScan | 0 |
SkippingSystemScan | 0 |
Skippedslowscan(1) | 0 |
Skippedslowscan(2) | 0 |
Skippedslowscan(3) | 0 |
因此,作为电台或系统操作员,跟踪跳过的扫描可能非常有益。
我们可以通过编程方式保持这些重要的统计数据清洁,同时仍然让数据记录仪执行它需要做的事情,而无需进行虚假的跳过扫描。
What do I mean by that? Let me give you an example.
Recently, Campbell Scientific added a new function called EMailRelay(). (You can learn more about it in the“从数据记录器中发送电子邮件变得更加容易”博客文章。)它使您能够向用户发送电子邮件或短信,而无需经历所有设置电子邮件帐户或与IT员工合作的所有头痛以访问Office电子邮件系统。这是一个很棒的小功能,可帮助您快速发送警报。
坎贝尔科学支持和实施工程师建议CRBASIC程序员将此功能添加到其程序中的缓慢序列之一中。为什么?因为有时间(取决于网络速度,服务器负载等),EmailRelay()函数可能需要比最初预期的时间更长的时间。可能比慢序的扫描间隔更长。当它确实运行更长的时间时,它可能会挂起来足够长的时间,以至于它插入下一个扫描间隔,从而导致数据记录仪记录跳过的扫描。
这是我们需要打扰的东西吗?在这种情况下,如果emailRelay()是慢速序列中运行的唯一功能,则没有。什么都没弄乱。数据记录器可以发送所需的警报。它只花了比预期的要长。
We will still get a skipped scan. In LoggerNet, it will show up in red in the Station Status of theConnect屏幕。(看着“连接窗口教程”了解更多信息。)It is going to annoy us and want us to do something about it. In this case, there is nothing neither we nor the data logger can fix that we have control over.
So how do we get around this? We don’t want to be presented with skipped scans when there isn’t an error that we need to deal with. How do we only see skipped scans in the Status table when there really is something going wrong with our system?
在这里,以缓慢的序列中的DO/LOOP指令而不是扫描/NextScan非常有帮助。
例如,我们可能使用EmailRelay()有一个简单的CRBASIC程序,看起来像这样:
'主要程序变量公共电池_Voltage public panel_temperature公共温度'emailRelay()常数const const _email_attachment =“” const _email_subject =“ email message”) 'EmailRelay() variables Public email_message As String * 300 Public email_relay_server_response As String * 100 Public email_trigger As Boolean Public email_tx_success BeginProg Scan (1,Sec,3,0) Battery (battery_voltage) PanelTemp (panel_temperature,250) TCDiff (temperature,1,mV2_5C,1,TypeT,panel_temperature,True ,0,250,1.0,0) If temperature > 30 Then email_trigger = True EndIf NextScan SlowSequence Scan(1,sec,1,0) If email_trigger = True Then email_trigger = False 'reset my trigger email_message = "Warning!" & _CR_LF & _CR_LF email_message = email_message & "This is a automatic email message from the datalogger station " & Status.StationName & ". " email_message = email_message & "An alarm condition has been identified." & _CR_LF email_message = email_message & "The temperature is " & temperature & " degrees C." & _CR_LF email_message = email_message & "Datalogger time is " & Status.Timestamp email_tx_success = EmailRelay (_EMAIL_TO_ADDRESS,_EMAIL_SUBJECT,email_message,email_relay_server_response,_EMAIL_ATTACHMENT) EndIf NextScan EndProg
当该程序运行并且温度高于30摄氏度时,数据记录器通过设置email_triggervariable toTrue。In the slow sequence, which is running a scan of every second, the EmailRelay() instruction runs. EmailRelay() definitely will take longer than one second to send the email message. In fact, it could take up to 70 seconds if the data logger cannot talk to the EmailRelay server. In either case, the data logger will record skipped scans for the first slow sequence regardless of whether EmailRelay() is successful or not.
So let’s put EmailRelay() into a Do/Loop instead and use CRBasic to tell us when EmailRelay() did not work:
'主要程序变量公共电池_Voltage public panel_temperature公共温度'emailRelay()常数const const _email_attachment =“” const _email_subject =“ email message”) 'EmailRelay() variables Public email_message As String * 300 Public email_relay_server_response As String * 100 Public email_relay_results_human_readable As String * 100 Public email_trigger As Boolean Public email_tx_success BeginProg Scan (1,Sec,3,0) Battery (battery_voltage) PanelTemp (panel_temperature,250)TCDIFF(温度,1,MV200C,U1,Typet,Panel_temperature,true,0,250,1.0,0)如果温度> 30> 30,则email_trigger = true Endif NextScan slow slow slow slow slow do email_trigger = true如果true true,则email_trigger = email_trigger = false my trigger my trigger my trigger emage_message =”警告!”&_CR_LF&_CR_LF email_message = email_message&“这是来自datalogger站的自动电子邮件”&status.stationname&'。&_cr_lf email_message = email_message&“温度为”&温度&“学位C”。& _CR_LF email_message = email_message & "Datalogger time is " & Status.Timestamp '1st attempt email_tx_success = EmailRelay (_EMAILTO_ADDRESS,_EMAIL_SUBJECT,email_message,email_relay_server_response,_EMAIL_ATTACHMENT) 'If EmailRelay was not successful, let us try one more time.If email_tx_success <> -1 Then '2nd attempt email_tx_success = EmailRelay (_EMAIL_TO_ADDRESS,_EMAIL_SUBJECT,email_message,email_relay_server_response,_EMAIL_ATTACHMENT) EndIf 'tell my human what happened with EmailRelay in human speak instead of loggerspeak ' my user got this information from the CRBasic help foremailRelay选择案例email_tx_success案例-1 email_relay_relay_results_human_readable =“ emailReLay Server成功地收到了数据词架的消息!”情况0 email_relay_results_human_readable =“与EmailRelay服务器的连接失败”。案例-2 email_relay_results_human_readable =“ emailRelay函数的执行没有由于缺乏记录或没有足够的时间而发生。”案例-3 email_relay_results_human_readable =“与EmailReLay服务器的连接进行了连接,但通信存在错误。” EndSelect EndIf Loop EndProg
通过将emailRelay()放入do/loop而不是扫描/nextscan中,do/loop持续运行直到email_trigger设置为True。当这样做时,IF当时和Endif语句之间的CRBASIC代码将被执行。
如果EmailRelay()需要10秒钟的时间来完成工作或70秒才能完成,则数据记录器不会记录跳过的扫描。因此,现在我们避免在Loggernet中看到红色Connect屏幕!
我们如何知道数据记录器是否使用EmailRelay()发送电子邮件遇到困难?我们可以查看EmailRelay()返回数据记录器的值,以及功能本身中的故障排除变量。
In our example program, we can create a variable calledemail_tx_successthat we and the data logger can use to determine success and failure.
email_tx_success = emailRelay(…
When EmailRelay() is executed, it returns a value toemail_tx_success取决于发生的事情。这些详细信息可以在CRBASIC的帮助中找到,也可以在此示例中添加到CRBASIC程序中的情况下。
We can also look at the variableemail_relay_server_response如果需要,请获取更多详细信息。该变量包含通过emailRelay()服务器返回到数据记录器的信息。成功与服务器通信后,email_relay_server_responsemay contain something like this:
{“ MessageType”:“确认”,“消息”:“电子邮件sent”}
This response is in JSON format and could easily be parsed by the data logger if we needed to do something with it and have the data logger act upon it.
In our example, here’s how the data logger could retry sending a failed message depending on the response it received with its first attempt:
'If EmailRelay was not successful, let us try one more time. If (email_tx_success <> -1) Then '2nd attempt email_tx_success = EmailRelay (_EMAIL_TO_ADDRESS,_EMAIL_SUBJECT,email_message,email_relay_server_response,_EMAIL_ATTACHMENT) EndIf
这是一个简单的示例,如果需要,可以扩展。
慢速序列的DO/LOOP是避免在数据记录器中看到跳过的扫描的好方法。希望您发现这些示例很有用。您可以下载original EmailRelay() example,以及做/循环电子邮件Relay() example。
您是否还有其他方法对数据记录仪进行编程以避免不必要的跳过扫描?如果是这样,请在下面分享。
评论
Minida28|04/18/2020,上午01:33
嗨,加里,
感谢您的这篇文章,我是坎贝尔系统的新手,因此这篇博客文章对我了解如何在CRBASIC编程中执行代码块真的很有帮助。
但是我有疑问,如果DO/LOOP像上面的代码一样无限地运行,并且代码在扫描部分之外执行,那么Datalogger是否会进入Quiescent模式?
谢谢,
miq
GaryTRoberts|04/20/2020,上午10:57
miq,
接得好。你是对的。Datalogger不会使用DO Loop作为wittin进入静态模式。为了允许Datalogger进入静态模式,需要将延迟添加到DO/循环中。用户都可以使用Waittriggersequence/TriggerSequence来控制DO/loop的使用。
请登录或注册评论。