Sign in to follow this  
Followers 0
saucekorn69

DF1 protocol problems

4 posts in this topic

Hi everyone, I'm currently writting a driver in order to communicate with a AB Micrologix 1500 following DF1 Protocol under vb.net. I succesfully implemented read and write with 3 adress fields, but It seems not working properly when I send unlimited number of commands. After a couple of commands, PLC only reponds NAK signal, like if the sink message is full. I tried to increase inteval time between command transfer, but it still doesn't work. Here is a part of my code: Do Try m_oRS232.Write(m_OutputBuffer) ' Send Command m_oRS232.Read(2) ' Read Response Catch ex As Exception Throw New CDF1Exception("Error 1 SEND COMMAND Function : ", ex) SendCommandV4 = False Exit Function End Try If m_InputBuffer(0) = DLE And m_InputBuffer(1) = ACK Then ' Message received correctly ' Read entire packet Exit Do ElseIf m_InputBuffer(0) = DLE And m_InputBuffer(1) = NAK Then ' Message not received correctly m_NAKCounter += 1 PurgeInputBuffer() ElseIf m_InputBuffer(0) = DLE And m_InputBuffer(1) = ENQ Then ' Message not received correctly m_ENQCounter += 1 PurgeInputBuffer() If m_ENQCounter = 0 Then Try m_oRS232.Write(Chr(DLE) + Chr(ACK)) PurgeInputBuffer() Catch ex As Exception Throw New CDF1Exception("Error 4 SEND COMMAND Function : ", ex) SendCommandV4 = False Exit Function End Try End If End If If m_NAKCounter >= 3 Or m_ENQCounter >= 3 Then Throw New CDF1Exception("Error 5, NAK counter: " + m_NAKCounter + " ENQ counter: " + m_ENQCounter) m_NAKCounter = 0 m_ENQCounter = 0 SendCommandV4 = False Exit Function End If Loop Try m_oRS232.Read(m_ReponseLength) Catch ex As Exception Throw New CDF1Exception("Error 2 SEND COMMAND Function : ", ex) SendCommandV4 = False Exit Function End Try If Buffer.ValidateNextMessage(m_oRS232.InputStream) Then Try m_oRS232.Read(2) m_InputBuffer = m_oRS232.InputStream Catch ex As Exception Throw New CDF1Exception("Error 3 SEND COMMAND Function : ", ex) SendCommandV4 = False Exit Function End Try If m_InputBuffer(0) = DLE And m_InputBuffer(1) = ENQ Then ' Validation correct m_InputBuffer(0) = DLE m_InputBuffer(1) = ACK SendCommandV4 = True Else m_NAKCounter += 1 End If Else ' Validation incorrect, re-send entire message m_InputBuffer(0) = DLE m_InputBuffer(1) = ENQ End If Try m_oRS232.Write(m_InputBuffer) PurgeInputBuffer() Catch ex As Exception Throw New CDF1Exception("Error 4 SEND COMMAND Function : ", ex) SendCommandV4 = False Exit Function End Try Does anyone have a advice or suggestions ?? Best regards. Nicolas Chaillou. Edited by saucekorn69

Share this post


Link to post
Share on other sites
Ok, I'm replying to myself, maybe someone will be able to give me an advice. My problem is that ReadPollRate value is not enough big, but according to Jiri Toman, I have to calculate it using baud rate value and numbers of integers I'm about to read. Fact is that i know my baudrate (19200) but I want to read an undetermined number of integers, so I'm kind of stuck... Can anyone help me ? Nicolas Chaillou.

Share this post


Link to post
Share on other sites
This may be of some help. It is a very good read if nothing else. chas183 click here

Share this post


Link to post
Share on other sites
Thanks, but I already read this topic which as you said, really helped me. My driver perform all this kind of command described there, but I'm still stuck on timeouts problems...

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