Lean MES Open Source Manufacturing Execution System
Flexible Manufacturing Solutions through Open Standards and Free Software....

AB SLC/Micrologix DF-1 Communication Driver for OPTO22 PAC


DF-1 RS-232 38.4K over Ethernet encapsulation, Requires LantronixUDS1100 device server and RS-232 cable/adapter.
Compatible with AB 1747-L53* , 1747-L54* , 1747-L55* , and Micrologix series products.
Stable, confirmed on: SNAP-PAC-R2, S1 (Rev.8.4a); LCE, ADS, M64 (Rev.7.2h).


Deployment/Test Instructions:
1. Lantronix and PAC IPs are configured ,preferably, on the same subnet. Both devices connected to the same physical network. (Removes unnecessary routing and reduce risk of communication failure).
2. Use the following manual to configure LantronixUDS1100.
3. Lantronix uses connecting socket(client) while PAC uses listening socket(server).
4. This is one to one configuration, one connecting socket per one listening socket.
5. Self recovery, Lantronix attempts to reconnect automatically if connection dropped.
4. Download the  ctEth_rs232_rwDF1_SLCxx.zip and extract files.
5. Copy and include files from extracted .\subroutines folder to strategy's subroutines folder
6. Import the extracted ctEth_rs232_rwDF1_SLCxx.cxf into strategy
   (Note! all tags are going to maintain their generic template names,
    for replication and reuse technique in PAC Control click here coming soon...).
7. Update chsSLCxx_DF1 tag in PAC Control Communication Handles to desired port number.
    It is recommended to use 22001-22254 ports, where the last 3 digits represent last octet in IP address of the connecting
    Lantronix. It makes it easy to get the client IP right from the strategy.
8. Compile strategy, load to PAC and click the Run Strategy button.
9. Run the driver flow(chart). Verify nSLCxx_error=5698; //client connected.
10. View training manual for examples of communication command tested and sequences.



//DF-1 SLC/Micrologix Communication Driver for OPTO22 PACs
//Driver Chart
//Copyright (C) 2010  Peter Tiagunov peter.tiagunov@leanmes.net

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.




// OPTO22 PAC-Allen-Bradley SLC/Micrologix CH0/CH1 communication
// using the DF1 protocol.Opto 22 controllers acts as a master device
// Stable, confirmed on: SNAP-PAC-R2, S1 (Rev.8.4a); LCE, ADS, M64 (Rev.7.2h).

// SLC/Micrologix CH0/CH1 Configuration
//-----------------------------------------
//Driver:                   DF1 Full Duplex
//Baud:                     38.4K
//Parity:                   NONE
//Source ID:                1
//Control Line:             No Handshaking
//Error Detection:          BCC
//Embedded Responses:       Auto Detect
//Duplicate Packet Detect:  check
//ACK Timeout:              50
//NACK Retries:             3
//ENQ Retries:              3

ntSLCxx_Parameters[0]=1;   // CH0/CH1 DF1 Half Duplex Slave Source ID
ntSLCxx_Parameters[1]=7; //*7 Accessed Data File Number. SLC Example of default files: 0 -output, 1 -input, 7 -integer(N7), 8 -float(F8)
ntSLCxx_Parameters[2]=0;   // Element Number.  Write to this Element Number within the File Number in Index 1 on the SLC5/0x.
ntSLCxx_Parameters[3]=0; //*50 The index number to start at on the Table contained in the ioControl strategy.
ntSLCxx_Parameters[4]=0; //*1 Number of Elements.  How many elements to access.
ntSLCxx_Parameters[5]=1;   // How long it will wait for a Reply (in seconds) from the slave SLC5/0x.
ntSLCxx_Parameters[6]=0;   // Communications Mode.  0 = Full-Duplex, -1 = Half-Duplex.
ntSLCxx_Parameters[7]=31;  // STS or Station Number of the Allen-Bradley 1770-KF2 DH or DH+ Asynchronous Interface Module.  Half-Duplex Only.
ntSLCxx_Parameters[8]=1;   // ioControl File Number.  1 = Integer or SLC Output or SLC Input, 2 = Float, 3 = Unsigned Integer, 4 = ASCII, 5 = String

/***IMPORTANT!******IMPORTANT!******IMPORTANT!******IMPORTANT!******IMPORTANT!******IMPORTANT!***
Use http://www.opto22.com/site/downloads Allen-Bradley DF1 Integration Kit R1.0c
(R1.0d not tested) to add:
1. ./Master/AB Protected Typed Logical Read.isb
2. ./Master/AB Protected Typed Logical Write.isb
Master folder subroutines for the SLC family of PLCs, the commands
Protected Typed Logical Read and Protected Typed Logical Write have been implemented in both
the master and slave subroutines. All these commands have been implemented to the element
(word) level of addressing.
Perform following adjustments:
AB Protected Typed Logical Read.isb - BLOCK:END,Close Comm. comment: //intTemporary = CloseCommunication(Serial_Handle);
rename subroutine AB Protected Typed Logical Read to srABProtectedTypedLogicalRead
AB Protected Typed Logical Write.isb - BLOCK:END,Close Comm. comment: //intTemporary = CloseCommunication(Serial_Handle);
rename subroutine AB Protected Typed Logical Write to srABProtectedTypedLogicalWrite
The above adjustment is required to maintain socket open at all the time.
This due to a difference between Serial and TCP/IP communication handles in OPTO22 PAC.*/

// check if communication established
if (not(IsCommunicationOpen(chsSLCxx_DF1))) then
    /* ListenForIncomingCommunication(ch)
       0 = Success.
     -10 = Invalid port.
     -36 = Invalid command. Use this command only with a TCP communication handle; for FTP or File communication handles, use Open Outgoing Communication instead.
     -47 = Open failed. Handle has already been opened.
    -203 = Driver not found. */
    //nSLCxx_Sts=SendCommunicationHandleCommand(chsSLCxx_DF1, "set.to:1.0"); returns -53
    nSLCxx_Sts=ListenForIncomingCommunication(chsSLCxx_DF1);
    //nSLCxx_Sts=SendCommunicationHandleCommand(chsSLCxx_DF1, "set.to:1.0"); returns -53
    //if listen port just open or already been opened
    if (nSLCxx_Sts==0 or nSLCxx_Sts== -47) then
        /* AcceptIncomingCommunication(ch)
           0 = Success
         -36 = Invalid command. Use this command only with a TCP communication handle; for FTP or File communication handles, use Open Outgoing Communication instead.
         -47 = Open failed. Handle has already been opened.
        -203 = Unknown driver on communication handle.
        -441 = Could not listen on socket.
        -442 = Could not accept on socket. No devices are currenlty attempting to connect on this port. */
        //accept connecting client (Lantronix)
        nSLCxx_Sts=AcceptIncomingCommunication(chsSLCxx_DF1);
        if (nSLCxx_Sts==0 or nSLCxx_Sts== -47) then
            nSLCxx_Sts=SendCommunicationHandleCommand(chsSLCxx_DF1, "set.to:1.0");
            if(nSLCxx_Sts==0)then
                //SetEndOfMessageTerminator(chsSLCxx_DF1,13);
                ClearCommunicationReceiveBuffer(chsSLCxx_DF1);
                nSLCxx_error=5698; //client connected
                nSLCxx_commsts=1;//communication link established
            else
                nSLCxx_error=7724; //Establish Controller's Connection Error
                nSLCxx_commsts=0;//no communication link
            endif
        elseif (nSLCxx_Sts== -442) then
            nSLCxx_error=7723; //Waiting for Controller's Connection
            nSLCxx_commsts=0;//no communication link
        else
            nSLCxx_error=7724; //Establish Controller's Connection Error
            nSLCxx_commsts=0;//no communication link
        endif
    endif

else
    //write
    if(sSLCxx_Cmd=="W")then
        if(srABProtectedTypedLogicalWrite(ntSLCxx_Parameters,
                                          ntSLCxx_IntegersWrite,
                                          ftSLCxx_FloatsWrite,
                                          stSLCxx_StringsWrite,
                                          chsSLCxx_DF1,
                                          nSLCxx_Transaction,
                                          nSLCxx_error)==0) then //seccess
             if(nSLCxx_RunCounter < 2147483647)then
                nSLCxx_RunCounter=nSLCxx_RunCounter+1;
             else
                nSLCxx_RunCounter=-2147483648;
             endif
            sSLCxx_Cmd=""; //write complete
        else //subroutine srABProtectedTypedLogicalWrite execution error
            nSLCxx_error=7721;
        endif
    //read
    elseif(sSLCxx_Cmd=="R")then
        if(srABProtectedTypedLogicalRead (ntSLCxx_Parameters,
                                          ntSLCxx_IntegersRead,
                                          ftSLCxx_FloatsRead,
                                          stSLCxx_StringsRead,
                                          chsSLCxx_DF1,
                                          nSLCxx_Transaction,
                                          nSLCxx_error)==0) then //seccess
             if(nSLCxx_RunCounter < 2147483647)then
                nSLCxx_RunCounter=nSLCxx_RunCounter+1;
             else
                nSLCxx_RunCounter=-2147483648;
             endif
            sSLCxx_Cmd=""; //read complete
        else //subroutine srABProtectedTypedLogicalRead execution error
            nSLCxx_error=7722;
        endif
    endif
endif

DelayMsec(nSLCxx_Scan);