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.

Emailsend on OS25


MPPMC Aug 22, 2012 11:20 AM

Hi,

I have a program that logs certain variables throughout the course of a test, usually every 5 minutes but with some additional logs thrown in depending on conditons. At the moment, I have Loggernet polling the station every minute to collect the data as it's written and store it on a local hard drive. When the test is finished (which is always a variable length) the program sends an email with a link to the file on the local hard drive - so anyone on the local network can click on the link to access the file. However, the guy who needs to access these files the most has a very slow remote connection. I'm therefore looking to include an attachment containing the data file with the email so he doesn't have to log on to our network.

I've experimented with using TableFile to create a file that can be attached. However, the problem I'm having is that the test length and number of records are variable, so the two options to specify when a file is written, either a time interval or a number of records, doesn't help. I should mention that each test's data should be all in one file - it's no use to us to split them up. What I want to do is basically write all the records of a table to a file on demand.

I've also noticed that Emailsend in OS25 now includes an option to send data from a data table without creating a file. I thought this might be the answer but how do you specify which table to send? The two additional parameters, NumRecs & FileOption, don't appear to let you specify. Also, how is the RemoteFileName parameter specified? If I get this working, would it be possible to update a variable with the number of records in the table (Records = TableLog.Record(1,1)) then use this to set NumRecs in Emailsend?

Or any other ideas to achieve this?


aps Aug 22, 2012 12:00 PM

I would advise not trying to use the new options in Emailsend as it was found to be rather limited for many applications. We will be offering more expanded features in the next OS release.

Even then I ma not sure it will cope with the flexibility you require. I think you may need to resort to may have to program this up in a more basic way. What you would need to do is write your own file knowing the final number of records you need to write (which could be variable).

So when you need to write the file you would do something along the lines of:

Open a new file (using FileOpen for writing)
Within a loop
Use the Getrecord instruction to pull one record at a time out of the required table and write it to a string. Changing the pointer to the right record back.
Write that string to the file.
End the loop when the required number of records is written.
Close the file.
Email it.


MPPMC Aug 23, 2012 01:55 PM

Thanks for the info. I think the guy is just gonna have to stick with his slow connection for now :)


Dana Aug 23, 2012 09:42 PM

If you have an SC115 or an NL115/CFM100 with card, the program below I think will do what you want. Unfortunately, this does not work with files stored to the USR drive (or CPU).

The significant part --
TableFile ("USB:TableName",9,1,0,-1,Hr,OutStat,LAstFileName)

With a fairly recent OS (24 or 25?), TableFile added new functionality for writing a file when using an SC115 or a Card. The Interval option code is set -1. The idea is that the datalogger buffers records until you connect an external device (SC115 or card). Then it writes those records out to the external device when the device is connected. Along with Interval set to -1, you set the NumRecs parameter to a defined number of records to write, or you set it to 0 to write All the Records stored in the table. For your application, you would want to write all records, so that the entire table of records is emailed at the end of each test.

You probably don't want to be connecting/disconnecting a device, but an alternative to connecting the SC115 or card to trigger writing the data to file is to use CardFlush.

So... in the program below I've set up TableFile as described above, along with a boolean called TestOver that executes CardFlush to write the data to the USB drive (SC115). If OutStat is true (i.e., the file has been written), then I set a boolean SendEmail to true, to trigger the EmailSend that is running in a SlowSequence. Note that OutStat is set true only after the file has been written & closed, and writing the file can take a "little time" as compared to running the main scan. Also, because EmailSend can take considerably more time, I've put it in a SlowSequence, and... because it is in a SlowSequence, I am using a different variable to control the email send. The reason? -- Running in PipelineMode, OutStat could possibly (likely) get set back to false even before you got to the SlowSequence, so emailsend might not be triggered. Thus, a separate variable that is only set False after EmailSend runs. (sorry if this is too much detail!!)

'Declare Public Variables
'Example:
Public PTemp, batt_volt, TestOver As Boolean, OutStat As Boolean, LAstFileName As String * 30, SendEmail As Boolean

'Email parameter strings (as constants), Message String & Result Variable
Const ServerAddr="XXXXXXXXXXXXXXXXXX"
Const ToAddr="xxxxxxx@xxxxxxxxxxxxxx"
Const FromAddr="CR1000@xxxxxxxxxxxxxx"
Const Subject="New Data File"
Const Message= "See new data file attached"
Const UserName=""
Const Password=""
Public EmailResult As String * 50

'Define Data Tables
DataTable (Test,1,1000)
DataInterval (0,15,Sec,10)
TableFile ("USB:TableName",9,1,0,-1,Hr,OutStat,LAstFileName)
Minimum (1,batt_volt,FP2,0,False)
Sample (1,PTemp,FP2)
EndTable

'Main Program
BeginProg
Scan (1,Sec,0,0)
PanelTemp (PTemp,250)
Battery (batt_volt)

'Enter other measurement instructions
CallTable Test
If TestOver Then
CardFlush
TestOver=False
EndIf
If OutStat Then SendEmail = True
NextScan
SlowSequence
Do
If SendEmail Then
EMailSend (ServerAddr,ToAddr,FromAddr,Subject,Message,LAstFileName,UserName,Password,EmailResult)
SendEmail=False
EndIf
Loop
EndProg

Note I didn't test the card, only the SC115, but it should work the same as the SC115 in this instance.

I hope the info is useful, though I suspect that the guy will still have to stick with his slow connection :)

Dana

* Last updated by: Dana on 8/23/2012 @ 3:45 PM *

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