TLServer 3.0   File and Email Services


Starting from version 2.0, the TLServer provides a number of  File and Email services to the PLCs via the serial comm port. Basically a PLC can send service requests to the TLServer using "tags" (which are ASCII characters enclosed between the '<' and '>' characters) and the TLServer will perform the service requests upon receiving valid commands. All data between the <command [parameter]> tag and the </> tag will be treated as data for the requested service .

Since the PLC is the one which initiates the service request, it does not need to be linked to the TLServer all the time unless it needs to request a service from the TLServer. This makes it possible for a remote PLC to connect to the TLServer via the telephone line using a modem and perform the required file or email services, then disconnects itself from the TLServer so that other PLCs can take turns to connect to the TLServer to request for services.

Note: All the files created or used in the write/append/read actions are located in the directory: 
<trilogi base directory> /FileService.  (hence the default path is C:\TRiLOGI\TL6\FileService). You may also read/write files that are located in  sub-directory below the "..../FileService" directory provided that the sub-directory already exists.

The currently supported files and emails services are described below:

1.  Write data to file

Format: 
  <WRITE [filename]> 
  data data data...
  data....
  </>

E.g. To save data of DM[1] to DM[10] to a file name "testWrite.txt", execute the following statement from a custom function:

PRINT #1 "<WRITE testWrite.txt>"    ' Write data request
FOR I = 1 TO 10
PRINT #1 DM[I];"   ";      REM delimited by space characters.
NEXT
PRINT #1    ' send a CR character.
PRINT #1 "</>"   ' End of Service request

The TLServer will close the file after it receives the end-of-service tag "</>" from the PLC and it will in turn send a "<OK>" string to the PLC to acknowledge that the WRITE request has been completed successfully. It is up to your PLC program to check for the "<OK>" tag to determine if it the service it requested have been completed successfully.

2.  Append data to file

Format: 
<APPEND [filename]> 
  data data data...
  data....
  </>

E.g. To append the  time of an event to a file name "testAppend.txt", execute the following statements in a custom function when the event take place:

PRINT #1 "<APPEND testAppend.txt>"   ' Append data request
PRINT #1 "Event Time = ";TIME[1];":";TIME[2];":";TIME[3]
PRINT #1 "A=";A
PRINT #1 "</>"                ' End of Service request

  • If the file does not exist a new file will be created. Otherwise, the PLC's real time clock data in the format "hh:mm:ss" and the value of A will be appended at the end of the file "testAppend.txt" every time the above statements are executed.
  • The TLServer will close the file after it receives the end-of-service tag "</>" from the PLC and it will in turn send a "<OK>" tag to the PLC to acknowledge that the APPEND request has been successfully completed. It is up to your PLC program to check for the "<OK>" tag to determine if it the service it requested have been completed successfully.

 

3.  Email data to recipient

Format: 
  <EMAIL [email address]> 
  Sender: [sender email]
  Subject: [subject text]
  data data data...
  data....
  </>

 

 

E.g. To send  data to an email address:  whoever@yahoo.com with the subject "PLC Email Test", execute the following statements:

PRINT #1 "<EMAIL whoever@yahoo.com>" ' change it to your own email.
PRINT #1 "Sender: triuser@hotmail.com" ' it can be anything.
PRINT #1 "Subject: PLC Email Test"
PRINT #1 "Hello, this email is sent by your friendly TRiLOGI PLC"
PRINT #1 "Don't worry, everyting is working out great today!"
PRINT #1 </>

Note:

  • "Sender:" field should be in email format e.g. xxx@yyy.zzz, but it does not need be an actual valid email address.
  • "Subject:"  field is optional and may be omitted totally
  • The TLServer will first save all the data it received into a temporary file named "Email.txt" in the default directory. After the TLServer receives the end-of-service tag "</>" from the PLC and it will then send out the email to the recipient email address. This email service will make use of the SMTP server defined  in the "Setup Emails" portion of the TLServer configuration, so make sure that you have defined a correct SMTP server before testing the email service function.
  • When the email has been successfully sent via the SMTP server, the TLServer will send an "<OK>" tag to the PLC to acknowledge that the EMAIL request has been successfully completed. It is up to your PLC program to check for the "<OK>" tag to determine if it the service it requested has been processed.

 

4. Read Data from File

Format: 
  <READ [filename]> 
  </>

This service allows the PLC to request the TLServer to open a text file and upload  its content to the PLC. This may be useful for loading some previously saved parameters.

Upon receiving this command and if the specified [filename] is successfully opened, the TLServer will begin sending all the ASCII characters contained in the text file to the PLC. Note that line breaks in a text file are sent to the PLC as CR character only and not as a CR+LF pair. As such, your PLC program can easily use the INPUT$(1) command to read in all the CR-terminated text string one string at a time and then interpret or convert the data as necessary. After sending out the last byte in the data file to the PLC, the TLServer will send a CR-terminated acknowledgement string "<OK>" to the PLC to signal that the READ command have been properly completed.

5. Read Real Tim Clock From TLServer

Format: 

  <READ RTC[]> 
  </>
  <READ Date[1]> 
  </>
  <READ Date[2]> 
  </>
  <READ Date[3]> 
  </>
  <READ Date[4]> 
  </>
  <READ Time[1]> 
  </>
  <READ Time[2]> 
  </>
  <READ Time[3]> 
  </>

This service allows the PLC to get the Real Time Clock data of the TLServer (i.e. the PC in which the TLServer runs on).  

The type of data is indicated in the Date[n] and Time[n]  parameter which correspond to the DATE[n] and TIME[n] system variables in TBASIC:

i.e.   Date[1] = year;  Date[2]=month;   Date[3]=day;  Date[4]=dayofWeek;
        Time[1]=hour;  Time[2]=minute; Time[3]=second.

For full synchronization, use the <READ RTC[]> tag which returns the values of the Date[1], Date[2], Date[3], Date[4], Time[1], Time[2], Time[3] in 7 CR-terminated ASCII strings.

Upon receiving this command the TLServer will immediately send the relevant clock/calendar data as CR-terminated ASCII string(s) to the PLC. Your PLC program can easily use the INPUT$(1) command to read in the data and convert them into  integers using the VAL command. Note that unlike the "READ file" service, the TLServer does not send "<OK>" string after performing the "READ RTC" service.