Sign in to follow this  
Followers 0
Guest Hidroilio

Does any body please can help me out with this

10 posts in this topic

I am trying to create a df1 RS232 drive to communicate with AB PLC 5 using Visual basic 6 after weeks of searching the only thing that I found to get me and starter is this code from this forum control.com I have made some modification but I am not able to make it work I know that the ConvertFileType function is missing I contact the author of the code but did not received and answer yet What really got me lost is the creation of the command to send (QueryBuffer) I was reading the AB DF1 Protocol but I can not figure it out If some body has some code to get me started please email it to hidroela@msn.com Any help would be appreciated Best regard Hidroilio Perez Dim DestinationNode As Integer Dim SourceNode As Integer Dim TransactionNo As Integer Dim Size As Integer Dim FileNumber As Integer Dim FileType As Integer Dim ElementNumber As Integer Dim SubElementNumber As Integer Dim TimeOut As Integer Public Function MsgCRC(Message As String) As String    'Calculate CRC checksum for message then add    'to end of message. Check for 10h byte 'DLE'    'within message and change to 'DLE DLE'.    'Function to calculate message CRC    Dim xByte As Integer    Dim xResult As Long    xByte = 3    Do        xResult = xResult Xor Asc(Mid(Message, xByte, 1))        RotateResult xResult        'test for 'DLE' and double up to DLE DLE        If Asc(Mid(Message, xByte, 1)) = 16 Then            'add extra DLE            Message = Left$(Message, xByte) + Chr(16) + Right$(Message, Len(Message) - xByte)            xByte = xByte + 1 'don't include in CRC        End If        xByte = xByte + 1    Loop While (xByte <= Len(Message) - 2)    xResult = xResult Xor 3 'ETX byte    RotateResult xResult    'add CRC checksum to message    MsgCRC = Chr(xResult Mod 256) + Chr(Int(xResult / 256)) End Function Public Sub RotateResult(res&)    Dim bitout%, shift%    'Rotate result 8 times and combine with const.    For shift% = 1 To 8        bitout% = res& Mod 2 'test if bit will be shifted out        res& = Int(res& / 2) 'shift right        If bitout% Then            res& = res& Xor &H1000A001 'xor with constant            res& = res& - &H10000000 'clear top word        End If    Next shift% End Sub Private Sub Form_Load()    RS232PLC.CommPort = 1    ' 9600 baud, no parity, 8 data, and 1 stop bit.    RS232PLC.Settings = "19200,N,8,1"    ' Tell the control to read entire buffer when Input    ' is used.    RS232PLC.InputLen = 0    ' Open the port.    RS232PLC.PortOpen = True    DestinationNode = 0    SourceNode = 0    TransactionNo = 5    Size = 4    FileNumber = 0    FileType = 7    ElementNumber = 31    SubElementNumber = 14 End Sub Private Sub Timer1_Timer()    Dim TmpTime As Date    Dim QueryBuffer As String        '2:Clear MsComms Buffer    RS232PLC.InputLen = 0    QueryBuffer = RS232PLC.Input    ''3:Create Query (Build the string)    QueryBuffer = Chr$(16) & Chr$(2) & Chr$(DestinationNode) & _       Chr$(SourceNode) & Chr$(15) & Chr$(0) & _       Chr$(TransactionNo) & Chr$(0) & Chr$(162) & _       Chr$(Size * 2) & Chr$(FileNumber) & _       Chr$(FileType + 132) & _       Chr$(ElementNumber) & Chr$(SubElementNumber) & _       Chr$(16) & Chr$(3)    '4:Calculate Crc Check Sum and add to Query    QueryBuffer = QueryBuffer & MsgCRC(QueryBuffer)    '5: Send Message    RS232PLC.Output = QueryBuffer    '5:Wait for acknowledgment Or Time Out        TmpTime = Now    Do        DoEvents                If DateDiff("s", TmpTime, Now) >= 3 And _           RS232PLC.InBufferCount < 2 Then            Exit Do        End If    Loop    '6:Remove acknowledgment from buffer        RS232PLC.InputLen = 2    QueryBuffer = RS232PLC.Input    '7:Check for good acknowledgement    If QueryBuffer <> Chr(16) + Chr(6) Then        MsgBox "Bad Ack"        Exit Sub    End If    '8: Wait for response    TmpTime = Now    Do        DoEvents                If DateDiff("s", TmpTime, Now) >= 3 And _           RS232PLC.InBufferCount < 12 + (Size * 2) Then            Exit Do        End If    Loop    '9:If timeout then exit    If RS232PLC.InBufferCount < 12 + (Size * 2) Then        MsgBox "Timed Out"        Exit Sub    End If    '10: Send acknowledgment    RS232PLC.Output = Chr(16) + Chr(6)    '11:Get response    RS232PLC.InputLen = 0    QueryBuffer = RS232PLC.Input    '12:     Remove surplus 'DLE's    TmpTime = 3    Do        If Mid(QueryBuffer, TmpTime, 1) = Chr(16) Then            QueryBuffer = Left(QueryBuffer, TmpTime) + Right(QueryBuffer, Len(QueryBuffer) - 1 - TmpTime)        End If        TmpTime = TmpTime + 1    Loop While TmpTime < Len(QueryBuffer) - 4 End Sub Public Sub ConvertFileType(FileType As Integer) End Sub  

Share this post


Link to post
Share on other sites
If you using .NET you can download a free driver ( a dll.net component ) at this site: http://www.tomantron.com./

Share this post


Link to post
Share on other sites
Unfortualy I am using vb6 Thanks any ways Best regard Hidroilio Perez

Share this post


Link to post
Share on other sites
I assume you do not have a copy or do not want to use RsLinx, that would make this project much easier. What exactly are you planning to do using VB6, some more info may be helpful. JJ

Share this post


Link to post
Share on other sites
Yes we do have only a copy but we have 20 more computer to go so $$$ money talks what we are trying to do with vb6 and the AB DF1 protocol is interact with the plc Right now my problem with the above code if how to figure it out the command to send this is how should look in the code QueryBuffer = Chr$(16) & Chr$(2) & Chr$(DestinationNode) & _      Chr$(SourceNode) & Chr$(15) & Chr$(0) & _      Chr$(TransactionNo) & Chr$(0) & Chr$(162) & _      Chr$(Size * 2) & Chr$(FileNumber) & _      Chr$(ConvertFileType (FileType + 132)) & _      Chr$(ElementNumber) & Chr$(SubElementNumber) & _      Chr$(16) & Chr$(3) Thanks any ways Best regard Hidroilio Perez

Share this post


Link to post
Share on other sites
http://www.plcdriver.com/abplcactivex.htm I've used the CimQuest driver for the last 7-8 years. Bought it once and the runtime is distributed free. Easy as pie to use. Its paid for itself many times over. Edited by jstolaruk

Share this post


Link to post
Share on other sites
Jstolaruk thanks I already check INGEAR Allen-Bradley Studio ActiveX But I should be a little more specific in the last post I got the time to work around and if we buy it where is the excitement Thanks any ways Best regard Hidroilio Perez

Share this post


Link to post
Share on other sites
Here is a VB6 project that will read and write to a SLC PLC, N9:0 to N9:9. It is set up for Comm port 1 at 19200 baud. It is somewhat similar to your earlier code, give it a try see if it works for you. AB.zip Edited by TechJunki

Share this post


Link to post
Share on other sites
TechJunki thanks I will try tomorrow at work and let you know thanks again Best regard Hidroilio Perez

Share this post


Link to post
Share on other sites
TechJunki I was really busy at work today so a can not test your code but any ways a need to change the data to read because I do not have a N9:0 to N9:9 on my plc and i dont know so i am still searching Best regard Hidroilio Perez

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0