Sign in to follow this  
Followers 0
boomer7010

DF1 Protocol For Bit Read

18 posts in this topic

Hello All!

I need some help structuring a command to read a bit in a Micrologix 1500 using DF1 Full Duplex via RS232. I have a simple program loaded on the PLC and I'd like to read the bit B3:0/0. I have been reading the "DF1 Protocal and Command Set" and the PLC's instruction manual, but with my lack of experience with serial communication and interfacing with PLC's I am not making the progress in the time I'd like. Hence a call for help.

I am using LabVIEW for the communication. My current command line I am sending (after initializing the port) is attached. Could anyone help me structure it correctly or point me in the right direction?

 

Command_0.png

Share this post


Link to post
Share on other sites

The command is OK. What is the result of issuing the command? The result could be a garbled response, error code or ...

If the result is nothing, it could be the cable is not correct/connected, the device is powered off, bad serial port, etc.. Lots of possible reasons.

We have a free DF1 slave program that might help https://www.hmisys.com/downloads/PeakHMISlaveSimulatorInstall.exe

 

 

Share this post


Link to post
Share on other sites

When I read the buffer after sending the command, it reads 2 bytes and the hex value is 1015.

im guessing this is the PLC’s response with 10 = DLE and 15 = ? Not sure, but it’s something other than DLE which means it’s not a successful read. Am I right?

Share this post


Link to post
Share on other sites

From the DF1 guide:

E Command cannot be executed

 

Share this post


Link to post
Share on other sites

For some closure to this thread. I was calculating the BCC and my PLC was expecting CRC. I implemented the correct CRC conversion and I have successful communication!! On to testing the bit write...

Share this post


Link to post
Share on other sites

Thanks for the followup !

Most A-B devices can be set for BCC or CRC, but SLC/MicroLogix default to CRC.   As you've found, it's a fairly ordinary CRC-16 checksum, so it's 2 bytes instead of 1.

Remember also that the Transaction Sequence Number should increase by one every time you send a command;  the reply for that specific command event should have a matching TSN.

The sequence numbers are one of the things that distinguishes DF1 from Modbus and allows true full duplex communication.

Some A-B devices can be configured to ignore duplicate packets, so sequences of the same command with the same TSN will ignore all but the first one.

Share this post


Link to post
Share on other sites

Ah ha. This is a great point, thanks Ken! I have not been doing this and have noticed communication issues when sending sequential commands. 
 

So I need to store the TSN number as a variable and increment each time I send a command? When can/should I reinitialize this to 0?

Share this post


Link to post
Share on other sites

I'm not a protocol driver author, but in general I'd initialize to zero when you open a connection or restart the driver, then roll over at 65535.

Share this post


Link to post
Share on other sites

One more issue I’m facing with this. I’ve progressed to using the mask write for this which is like the protected write with 3 address but with an added 16 bit mask.

So to set B3:0/0 to 1 I send the command:

AB 02 03 85 00 00 01 00 01 00

to set back to 0 I’m sending:

AB 02 03 85 00 00 01 00 00 01

Works every time.

I'm trying now to toggle the B3:0/1 with no luck. I feel I’ve tried everything that makes sense and more but I am new to the bit communication thing. Anyone know how the above command should change as I progress through the sub elements of the B3:0 element?

Share this post


Link to post
Share on other sites

Show the command you are using for bit 1.

Edited by Mark-

Share this post


Link to post
Share on other sites

All I’m changing is the sub element byte. For a requested write of 1, I’m sending:

AB 02 03 85 00 01 01 00 01 00

I’m sure the mask byte needs to change but not sure how. My trial and error hasn’t produced a success.

Share this post


Link to post
Share on other sites

10 02 01 29 0F 00 40 00 AB 02 03 85 FF 00 00 00 01 00 01 00 10 03 82 CF
10 02 01 29 0F 00 40 00 AB 02 03 85 FF 00 00 00 02 00 02 00 10 03 36 CF


The first line is bit 0 and the second is bit 1. The mask clears the other bits of the element.

 

Share this post


Link to post
Share on other sites

Thanks Mark, that solved the problem. I am now able to toggle individual bits in the B3 file.

Now for one more question. What if the file number is 32? For B32:0/0 I am sending this command:

AB 02 20 85 FF 00 00 00 01 00 01 00

The PLC doesn't like this at all, reply's 1015. Any thoughts? I'm just trying to understand the variation and how/why commands are changing.

Share this post


Link to post
Share on other sites

> I'm just trying to understand the variation and how/why commands are changing.

I assume you are reading the specifications?

Do you have a binary file 32 in the the PLC?

Share this post


Link to post
Share on other sites

Yes sir, I am reading and digesting. Between the bits, bytes, hex, its all a little overwhelming. I'm a lot more knowledgeable than I was, but the experience and perspective still lack.

Yes, I do have a B32 file in the PLC. It is downloaded to the PLC and I can toggle it through RSLogix.

Share this post


Link to post
Share on other sites

There exist a finite number of reasons a command does not work.

10 02 01 29 0F 00 40 00 AB 02 20 85 FF 00 00 00 01 00 01 00 10 03 26 4B

 

Share this post


Link to post
Share on other sites

Hey Mark, I got it to work. Thanks for your help. Quick question, why do we include the FF after the File Type?

Share this post


Link to post
Share on other sites
1 hour ago, boomer7010 said:

Hey Mark, I got it to work. Thanks for your help. Quick question, why do we include the FF after the File Type?

You are welcome.

From the DF1 manual:

For higher addresses, setting this byte to FF expands this field to three bytes total. Use the second and third
bytes for the expanded file address (low address byte first).

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