Sign in to follow this  
Followers 0
saucekorn69

Micrologix 1500 DF1 Protocol Newbie

14 posts in this topic

Hi Everyone, First of all I'm new on this forum and glad to become one of yours, there is a lot of informations there and I'm pretty sure this forum will be really usefull for me. As you can see, I'm a newbie in PLC programmation, and I have to write a driver using DF1 protocol for a Micrologix 1500 under VB.Net. I already went on tomantron.com, but according to Jiri, his driver doesn't seem to work with a Micrologix 1500. So, I read the DF1 manual, and I'm currently trying to communicate with the PLC and I'm having a hard time. I'm trying to send an echo command, and It doesn't work at all... Dim s_Tx1As string s_Tx1 = Chr(16) + Chr(2) + Chr(0) + Chr(0) s_Tx1 = s_Tx1 + Chr(1) + Chr(0) + Chr(0) + Chr(0) s_Tx1 = s_Tx1 + Chr(0) + Chr(0) + Chr(50) s_Tx1 = s_Tx1 + Chr(16) + Chr(3) s_Tx1 = s_Tx1 + Chr(90 Mod 256) s_Tx1 = s_Tx1 + Chr(CInt(90 / 256)) moRS232.Write(s_Tx1) moRS232.Write(s_Tx1) it returns me DLE NAK Thanks in advance. Regards. Nicolas Chaillou. Edited by saucekorn69

Share this post


Link to post
Share on other sites
The first thing that jumps out at me is that your TNS is only one byte long and should be 2.

Share this post


Link to post
Share on other sites
Never mind, you edited the post. I would expect to see a 6 in the CMD byte if you are doing an echo command.

Share this post


Link to post
Share on other sites
check this code would get you stater Private Function GetEcoFromPlc() As Boolean    Dim EcoToSend         As String    Dim EcoRespond            As String    Dim TransactionNumber     As Integer    Dim lngCounter            As Integer    Dim NAKCount              As Integer    Dim ENQCounter            As Integer    EcofromPLC = ""    'clear buffer    Container.MSComm.InputLen = 0    EcoToSend = Container.MSComm.Input    'Create Random transaction Number every read    'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)    TransactionNumber = Int((200 - 1 + 1) * Rnd + 1)    EcoToSend = Chr(16) + Chr(2)    'destination and source    EcoToSend = EcoToSend + Chr(RemoteNodeAddress) + Chr(DHNodeAddress)    'command type    EcoToSend = EcoToSend + Chr(6)    'status of the message    EcoToSend = EcoToSend + Chr(MessageStatus)    'transaction value 2 bytes long    EcoToSend = EcoToSend + Chr(TransactionNumber) + Chr(0)    'function    EcoToSend = EcoToSend + Chr(0)    EcoToSend = EcoToSend + Chr(54) + Chr(72) + Chr(53) + Chr(54)    'termination of the message    EcoToSend = EcoToSend + Chr(16) + Chr(3)    'send command    Select Case mvarCalcCheckSum        Case 1            CalcCRC EcoToSend        Case 0            CalcBCC EcoToSend    End Select    Container.MSComm.Output = EcoToSend    'wait for acknowledgment    Do        lngCounter = lngCounter + 1        Sleep 10        DoEvents    Loop While 3 > lngCounter And Container.MSComm.InBufferCount < 2    Container.MSComm.InputLen = 2    EcoRespond = Container.MSComm.Input    Timeout1 = GetTickCount&    Do        'check for good acknowledgement        If EcoRespond <> Chr$(16) + Chr$(6) Then            If EcoRespond = Chr$(16) + Chr$(21) Then                NAKCount = NAKCount + 1                If NAKCount > 3 Then                    comunicating = False                    Exit Function                Else                    Container.MSComm.Output = EcoRespond                    'wait for acknowledgment                    Do                        lngCounter = lngCounter + 1                        Sleep 10                        DoEvents                    Loop While 3 > lngCounter Or Container.MSComm.InBufferCount < 2                    'remove acknowledgment from buffer                    Container.MSComm.InputLen = 2                    EcoRespond = Container.MSComm.Input                    Timeout1 = GetTickCount&                End If            Else                Timeout2 = GetTickCount&                If (Timeout2 - Timeout1) > 20 Then                    ENQCounter = ENQCounter + 1                    If ENQCounter > 3 Then                        comunicating = False                        Exit Function                    Else                        Container.MSComm.Output = Chr$(16) + Chr$(5)                    End If                End If            End If        Else            Exit Do        End If    Loop    'send acknowledgment    With Container        .MSComm.Output = Chr(16) & Chr(6)        'get response        .MSComm.InputLen = 0        Sleep 40 '40 best results for me'play with this number        DoEvents        EcoRespond = .MSComm.Input        If Len(EcoRespond) = 0 Then            comunicating = False        End If    End With 'container    'check EcoRespond status    If Asc(Mid$(EcoRespond, 6, 1)) = 240 Then        comunicating = False        Exit Function    End If    'remove surplus 'DLE's    lngCounter = 3    Do        If Mid$(EcoRespond, lngCounter, 1) = Chr$(16) Then            EcoRespond = Left$(EcoRespond, lngCounter) & Right$(EcoRespond, Len(EcoRespond) - 1 - lngCounter)        End If        lngCounter = lngCounter + 1    Loop While lngCounter < Len(EcoRespond) - 4    Dim i    For i = 7 To 4 Step -1        EcofromPLC = EcofromPLC & "|" & _           Asc(Mid$(EcoRespond, Len(EcoRespond) - i, 1))    Next    If EcofromPLC = "|54|72|53|54" Then        GetEcoFromPlc = True    Else        GetEcoFromPlc = False    End If    GetStatusFromPlc End Function if you need the hole project go here MrPLC Best Regards Hidroilio Perez

Share this post


Link to post
Share on other sites
Thanks Hidroilio, Currently, I can send 100 of echo commands, and I'm trying to read on a binary file. Thanks for help, I let you know If i need more help !! Nicolas Chaillou.

Share this post


Link to post
Share on other sites
Hi Everyone, Thanks for your example, I can send echo commands and perform protected typed logical read, but I'm having troubles reading an output status : O:0/1 I'm working with a Micrologix 1500 under vb.net following AB DF1 protocol This is what I sent : |DST|SRC|CMD|STS| TNS |FNC|bytesize|fileNo|filetype|Ele.no|S/Ele.no| | 1 | 0 | 0F | 0 | 1 | 0 | A2 | 8 | 1 | 8B | 0 | 0 | It returns me: |CMD|STS| TNS | DATA |EXT/STS| | 79 | 0 | 1 | 0 | 0 | 0 | 0 | 64 | 0 | 32 | 0 | 0 | 16 | 3 | May someone help me understanding what Data Field means ?? Thanks you all !! Regards. Nicolas.

Share this post


Link to post
Share on other sites
Use this command on pag 7-17 protected typed logical read with three address fields CommandType = 15 Functionn = 162 BiteSize = 2 CommandToSend = Chr(16) + Chr(2) + Chr(RemoteNodeAddress) + _ Chr(DHNodeAddress) + Chr(CommandType) + _ Chr(MessageStatus) + Chr(TransactionNumber) + _ Chr(0) + Chr(Functionn) + Chr(BiteSize ) + _ Chr(FileNumber(Index)) + Chr(FileType(Index)) + _ Chr(ElementNumber(Index)) + Chr$(0) + _ Chr(16) + Chr(3) Remember to attach the check sum (CRC or BCC) to the command send Your respond should end in some thing like this DLE ETX CRC CRC Your data should be on the left side of DLE two bytes I used this code to extract it from the respond DecimalValue=256 * CLng(Asc(Mid$(Respond, Len(Respond) - 4, 1))) + CLng(Asc(Mid$(Respond, Len(Respond) - 5, 1))) Your respond would be the entire word 16 bits from there you have to pick the one that you are looking for example 0000101011100000 output 0:0/5 bit is one I use this code to get it Position:Position in the word of the bit that you want to read BitValue: bit that you want to read Private Function GetData(DecimalValue As Long, Possition As Long)    On Error Resume Next    Dim counter   As Integer    Dim TempValue As Long    Dim BinValue  As Byte    Do        counter = counter + 1        TempValue = DecimalValue Mod 2        BinValue = CStr(TempValue) + BinValue        DecimalValue = DecimalValue \ 2    Loop Until counter = Possition + 1    BitValue = TempValue End Function Hope this help Best regards Hidroilio Pérez

Share this post


Link to post
Share on other sites
Thanks Hidroilio, your message really helped me. I can read using "protected typed logical read with three address fields" command, but it seems to be a little different to wrtie with three adress fields on a ML 1500, and according to Jiri Toman, ML1500 uses logical write with two adress fields instead of three, but I cannot make it work correctly... I think I'll have to do a protected typed file read and write, but I have a few questions: I read on a post that Tag value is received with the open file command, so It's no longer a problem. Filetype fields is not really documented, so I would like to know which Filetype value should I use in order to write on bit table, integer table, input or output table... Is it the same file type value than we need to use to read with three adress fields ? Is there any other usefull command I should implement ?? Thanks for helping. Regards. Nicolas Chaillou Edited by saucekorn69

Share this post


Link to post
Share on other sites
Thanks !!! I finally made it work using write with three adress fields command !! It was not supposed to work with ML1500, but it does ! I can write on binary table, float, integer and output table !! As soon as I finish it, I'll post it on the forum !! Thank you all !! My best regards. Nicolas Chaillou.

Share this post


Link to post
Share on other sites
I just figure it out than every time I restart my computer, PLC is no longer communicating with me, I have to start RSLinx which send an unknown command that enable communication. Down anyone of you guys know if I have to send a specific control word using a AB ML1500, or any activating command ??? Thanks in advance ! Nicolas Chaillou.

Share this post


Link to post
Share on other sites
Make sure your comm port is not in use rslinx start up as a server when you start up your PC so probably it is using it Hope this help Best regards Hidroilio Pérez Edited by hidroela

Share this post


Link to post
Share on other sites
By the way Nicolas Chaillou how did you manage to write to the output table to a particular bit not the entire word for example change O:0/7 from 1 to 0 Best regards Hidroilio Pérez Edited by hidroela

Share this post


Link to post
Share on other sites
Hi Hidroilio Pérez, I cannot understand why the PLC seems not to communicate with me... RsLinx is not running, and my comm Port is correctly open. Whatever the command I try to send, PLC returns me only 0. Maybe the baudrate or parity value are incorrects.. I thougth I had to send a first command to initialize Communication, but I seem to be wrong, so my problem is somewhere else... Unfortunately, I cannot change only a bit like you asked me, I have to send the hole word every time I want to change a bit value. Do you think we have another solution ?? Thanks for your time and your help. Nicolas Chaillou.

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