øõTRiLOGI Ver 5.0
0,GetIPAddr
1,TestEmail
2,RemoteFS1
3,RemoteFS2
4,TCPConnect
5,Connect
6,TestNetcmd
8,MBTCPconn
9,TestRDMB
10,TestWRMB
11,CloseConnect
13,tempInput
~
~
0,CR1
1,CR2
~
0,T1 15
~
~
%LfnGetIP=getIPAddr
$This example shows how F-series PLC can use its Ethernet port to sendþan email to anyone with any content.þþYou must set the SMTP server IP address to the SMTP server provided by þyour ISP. Most ISPs only allow SMTP connection from their own subscribers.þSome ISP however require encryption or authentication even from their ownþsubscribers, and F-PLC would not be able to send email via these SMTP þservers.þ
%LfnEmail=testEmail
$This example shows how to use the Tag for the F-PLC to þcontact a remote TLServer and read the Real Time Clock data from the þTLServer, then update the F-PLC own RTC.
%LfnRFS1=RemoteFS1
$This example shows how to use the Tag for the F-PLC to þcreate a text file on a remote TLServer. Notice the filename is created fromþthe current time data. þ
%LfnRFS2=RemoteFS2
$The next example show how to use tag to open a TCPþconnection to a remote server. In this case we contact an NIST Internet Time þserver and use the result to update our RTC including correction for DayþSaving Time.þ
%LfnTCPconn1=TCPconnect
$This example opens a TCP/IP connection and login to another F-PLC (or þPLCs connected to a TLServer) at 192.168.1.105 to communicate with thatþPLC.þþ You can use NETCMD$ to exchange data with the remote PLCs þanywhere in the world, therefore achieving M2M communications.þþPlease click the "CloseConnect" input to close the connection to the þremote TLServer or another FPLC before openning connection to þþ
%LfnConnect=connect
%LfnNetCmd=(testNetcmd+CR1*Clk:0.2s)
$Since both the fnTCPConn and fnMBTCP both monopolise the connection, þyou should click on the "CloseConnect" input to close connection before þrunning other network connection functions. þ
%LcloseTCP=CloseConnect
%LfnMBTCP=(MBTCPconn+^T1)
%LfnRdMBTCP=(TestRDMB+CR2*Clk:0.1s)
%LfnWrMBTCP=TestWRMB
%Ltemp=Clk:0.1s
~END_CIRCUIT~
È
Fn#0,806
' This function instructs the Xserver to send out an email
' to the address specified in the tag
' The SMTP server must be configured correctly in the Xserver
' for this to work properly (see "Xserver Configuration mode"
' in the Xserver instruction manual)
' ==============================================================
SETLCD 0,0,CHR$(1) ' clear LCD screen
PRINT #4 "" ' replace with your destination email
PRINT #4 "SENDER: test@yahoo.com" ' should be a valid server address
PRINT #4 "SUBJECT: Email sent by your PLC"
PRINT #4 "I am a TRiLOGI PLC"
PRINT #4 "This is a Hello Message"
PRINT #4 ">" ' end the email.
CALL RdComm4
SETLCD 1,1,"Email Response Code:"
SETLCD 2,1, A$
S = status(3) ' Status(3) = 1 if successful, 0 if failed.
È
Fn#1,1076
' This function contacts a TLServer situated at the IP address
' 192.168.1.105:9080 and executes a file service on the
' TLServer to update its own RTC.
' The TLServer must be version 2.1 and above to support
' this remote File Service operation.
'===============================================================
SETLCD 0,0,CHR$(1)
SETLCD 1,1, "Contacting TLServer.."
PRINT #4 ""
PRINT #4 ""
PRINT #4 ">"
delay(200)
FOR J=1 TO 7 ' First read the 7 data into DMs
CALL RdComm4 ' RdComm4 processes the INPUT$(4).
IF LEN(A$)=0
SETLCD 3,1, "Fail to Synchronize"
PRINT #4 "" ' attempt to close REMOTEFS operation.
RETURN
ENDIF
DM[100+J] = VAL(A$)
NEXT
FOR J = 1 TO 4 ' Now copy the data from DMs to RTC.
DATE[J] = DM[100+J]
NEXT
FOR J = 1 TO 3
TIME[J] = DM[104+J]
NEXT
PRINT #4 ""
SETLCD 2,1, "RTC has been updated"
CALL RdComm4
SETLCD 3,1,"RemoteFS Result:"
SETLCD 4,1, A$
S = status(3) ' Status(3) = 1 if successful, 0 if failed.
È
Fn#2,917
' This function opens a TCP/IP connection and login to another Xserver
' or a TLServer at 192.168.1.105 to communicate with the PLC connected
' to that server. After the connection is opened, you can use NETCMD$
' to exchange data with the remote PLCs anywhere in the world.
' =====================================================================
SETLCD 0,0,CHR$(1) ' clear LCD screen
SETLCD 1,1, "Contacting Server.."
PRINT #4 ""
PRINT #4 "samples" ' username
PRINT #4 "" ' password
CALL RdComm4 ' read the message
SETLCD 2,1,A$
S = STATUS(3) ' STATUS(3) = 1 if connection is successful
' else STATUS(3) = 0
IF STRCMP(A$,"")<> 0 ' did not received "CONNECTED" message
SETLCD 3,1,"Connect Unsuccessful"
RETURN
ENDIF
S = STATUS(3) ' get the status of running
IF S=1
SETIO CR1
ELSE
CLRIO CR1
ENDIF
È
Fn#3,1023
' This function contacts a TLServer situated at the IP address
' 192.168.1.105:9080 and executes a file service on the
' TLServer to create a text file inside the FileService folder of
' that remote PC. The TLServer must be version 2.1 and above to support
' this remote File Service operation.
'===============================================================
SETLCD 0,0,CHR$(1)
PRINT #4 ""
PRINT #4 ""
PRINT #4 "This is a file created on the TLServer"
PRINT #4 "which is located at remote location"
PRINT #4 "That's all"
PRINT #4 ">"
CALL RdComm4 ' The TLServer would return if successful
SETLCD 1,1,"TLSvr Resp:"+A$
PRINT #4 ""
CALL RdComm4 ' TLServer would return "" when it closes properly
S = status(3) ' Status(3) = 1 if successful, 0 if failed.
SETLCD 2,1,"RemoteFS Result:"
SETLCD 3,1, A$
S = status(3) ' Status(3) = 1 if successful, 0 if failed.
È
Fn#4,227
SETLCD 0,0,CHR$(1) ' clear LCD screen
PRINT #4 "" ' Get IP address of this FServer as a string
Call RdComm4
SETLCD 1,1,"IP Address="
SETLCD 2,1, A$
S = status(3) ' Status(3) = 1 if successful, 0 if failed.
È
Fn#5,2236
' This example uses the tag to connect to an NIST Time server to
' obtain the most accurate atomic time and use the result to update the PLC's own
' real time clock. This could be used if the PLC has internet connectivity.
' Otherwise, pls refer to "fnRFS1" for a way to update PLC's RTC from a PC that runs TLServer.
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' NOTE: The date and time obtained below are GMT date/time, so you must add or subtract
' your time zone and take care of the day if it rolls over to the next day.
' If your PLC has battery backed RTC you probably only need to update time and not the dates.
' Alternatively, try to contact a time server that give you your local date and time.
'
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SETLCD 0,0,CHR$(1) ' clear LCD screen
DM[1000] = -8 ' This is used to store the timezone (PST = -0800 hrs)
SETLCD 1,1,"Contact NIST TimeSvr"
PRINT #4 "" ' make a connection to NIST timer server
CALL RdComm4
IF LEN(A$)<2 : CALL RdComm4 : ENDIF
S = STATUS(3)
SETLCD 2,1, "A$="+A$ ' A$ contains response from the server. Time is GMT
SETLCD 3,1, " "+MID$(A$,18,LEN(A$)-18) ' display continuation of A$
IF LEN(A$)<> 0 ' response code
TIME[1] = VAL(MID$(A$,16,2)) ' The hour is GMT time
TIME[2] = VAL(MID$(A$,19,2))
TIME[3] = VAL(MID$(A$,22,2))
' DATE[1] = VAL(MID$(A$,7,2))+2000
' DATE[2] = VAL(MID$(A$,10,2))
' DATE[3] = VAL(MID$(A$,13,2)) ' The day is GMT day.
SETLCD 4,1, "RTC Updated"
ELSE
SETLCD 4,1, "Fail to update RTC"
ENDIF
' Now correct for time zone. For simplicity we don't correct the date since we didn't update the date above
' since it can become complicated when it stranded across month and year.
' ------------------------------------
TIME[1] = TIME[1]+DM[1000]
' Next correct for US day light saving. This is indicated in the position 16 and 17 of A$
' ------------------------------------
IF VAL(MID$(A$,16,2))<> 0 ' 0 is standard time. > 0 is DST
TIME[1]=TIME[1]+1
ENDIF
IF TIME[1] < 0
TIME[1]=TIME[1]+24
ELSE
IF TIME[1] > 23
TIME[1]=TIME[1]-24
ENDIF
ENDIF
È
Fn#6,385
SETLCD 0,0,CHR$(1) ' clear screen
SETLCD 1,1,"Contact ModbusTCP Sv"
PRINT #4 ""
CALL RdComm4
SETLCD 2,1,A$
IF STRCMP(A$,"")<> 0 ' did not received "CONNECTED" message
SETLCD 3,1,"Connect Unsuccessful"
RETURN
ENDIF
S = STATUS(3) ' get the status of running
IF S=1
SETIO CR2
ELSE
CLRIO CR2
ENDIF
È
Fn#7,562
A$ = NETCMD$(4,"@01XA") ' communicate with the remote PLC.
B$ = NETCMD$(4,"@01RVS0101") ' communicate with remote PLC ID = 01
S = STATUS(3) ' STATUS(3)=0 if Network connection error
IF S = 0 ' network connection is bad
SETLCD 2,1,B$
RETURN
ENDIF
T = STATUS(2) ' STATUS(2)=1 if NETCMD$ successful
IF T <>0 ' if T is not zero
OUTPUT[1] = HEXVAL(MID$(B$,7,4)) ' copy remote output1-16 to local output1-16
SETLCD 2,1,"NetCMD$ successful"
ENDIF
È
Fn#9,22
È
Fn#10,286
' This function read a CR-terminated string received from COMM1 and
' the returned string is stored in A$.
'===================================================================
FOR I = 1 to 10000
A$ = INPUT$(4)
IF LEN(A$) <> 0 RETURN: ENDIF
NEXT
È
Fn#11,204
' This is used to force a previous opened or half-opened connection to close
PRINT #4 ">"
S = STATUS(3)
SETLCD 0,0,chr$(1) ' clear screen
SETLCD 1,1,"Connection Closed"
CLRIO CR1
CLRIO CR2
È
Fn#12,466
B = READMODBUS(4,1,0)
READMB2 4,1,0,DM[1],10
T = STATUS(2) ' check READMB2 status. 0 = failure, 1 = success
S = STATUS(3)
IF T=0
S = STATUS(3)
IF S=0
Z = Z+1 ' count the number of times connection is re-established.
CLRIO CR2 ' clear the relay that run this function periodically
CALL closeTCP
TimerPV[1] = 50 ' start timer T1 to reconnect 5 seconds later.
CLRIO T1 ' clear its contact first.
ENDIF
ENDIF
È
Fn#13,210
FOR I=1 to 10
DM[I] = I*11 ' some test data to be written to the MBTCP slave.
NEXT
WRITEMODBUS 4,1,16,55
WRITEMB2 4,1,1,DM[1],10
T = STATUS(2) ' check WRITEMB2 status. 0 = failure, 1 = success
È
Fn#19,150
' Link output 1 to 16 to Rly129 to 144
' so that green button pressed on XHMI1.HTM
' will trigger the output 1-8.
OUTPUT[1] = RELAY[9]
È
Fn#20,235
T = STATUS(2) ' check READMB2 status. 0 = failure, 1 = success
S = STATUS(3) ' testing to see if after 1 minute connection closed automatically what
'is the status(3) result. This section to be removed later.
~END_CUSTFN~
0,fnEmail
1,fnRFS1
2,fnConnect
3,fnRFS2
4,fnGetIP
5,fnTCPconn1
6,fnMBTCP
7,fnNetCmd
9,SendNSReq
10,RdComm4
11,closeTCP
12,fnRdMBTCP
13,fnWrMBTCP
19,F20
20,temp
21,temp1
~END_CUSTFNLABEL~
0,0,
1,0,
2,0,
3,0,
4,0,
~END_QUICKTAGS~