programming Communications is one of the
most challenging tasks especially when
starting from scratch is that the cable
is that the wiring is it the connector
do I need a resistor is it the
configuration of the network addresses
baud rates parity stop bits to the
device to support all the codes how many
nodes can I have in the network is the
network overloaded how does the
communication block work we can't tackle
all this in a 10 minute video but we can
program a simple read bar and right bar
in a PLC we're going to demonstrate how
to configure my bus cereal in unity Pro
and program the rebar and right bar
function blocks the native Modbus port
on the m3 40 capote supports either
rs-232 or two wire rs45 we have our PLC
programmed the serial port on the PLC
programmed as a master one second
timeout RS 45 to wire 19 2k baud 8-bit
rtu one-stop bit even parity the Modbus
device that we're using is set to
address three and all of the
configuration parameters are set
identically 19 2k bot or two you two yr
45 even parity one-stop bit so let's
look at the read bar function block
first
as we look at the reed bar function
block we have a dr which stands for the
address this is the address of the
device we're talking to the object type
this is whether it's a4x register 3 X 0
X or 1x register the first object that
we're going to read in the Modbus device
so this would be a dress 4003 let's say
the objects we want to read so let's say
we want to read 10 objects it'll be four
thousand three through four thousand
twelve and we have the receiving array
where are we going to put the values of
those registers were reading from the
device in our plc right VAR is very
similar to read VAR only we're writing
so the basic difference is an input into
the right VAR function block with the
values of the data that we want to write
both the rebar and write VAR have the
input output pin Zhi EST which is the
communication exchange management table
g EST is a 4 element array of words the
exchange management table when we open
it the first element of the exchange
management is read only the plc assigns
an exchange number and sets the activity
bit the activity bit is set to 0 set to
1 while the function block is executing
and resets to zero when the execution is
complete the second element of the
exchange management table is critical
when you're debugging during the
commissioning of a project the
communication report is basically a list
of the error codes that you can get so
if you're not using the second element
of this array it's difficult to
troubleshoot and you won't see any data
the third element is the timeout you
will forget to program this time out it
will be 0 you should not forget to
program this time out you will have
trouble when you forget to program this
time out and this time out must be set
greater then we set the timeout in on
the serial port itself so in this case
our answer delay timeout is one second
in our example we're going to set a two
second timeout now you will forget to
program this time out and that is bad do
not forget to program this time out I
would make recommend programming this
time out a value of zero will wait
forever and none of us have the patience
of jobe so the fourth word of this array
is the length this is written again by
the PLC it is the length
bites of the communication exchange so
if we're writing or reading 10 words
this length will be 20 so let's program
the read VAR i'll create by
right-clicking new section a new project
called read underscore right underscore
section it's a function block section so
i will say ok I will go to my function
block input existent will click it and I
am just going to type read VAR because I
know that's what the command is or the
function block is and I will slap it
right in my logic now the when the rebar
execute I'm going to show the enable
enable out each time the enable comes on
and i'm going to one shot to it it will
execute this function block once so
first we'll put the address in the
address command is a DDM it's a string
so i put an open quote rec 0 slot 0
channel 0 modbus device 3 i will close
the quote that will end my parentheses
the type of object we're going to read
from this from this Modbus device it's
going to be a 3x register which is an
input word this is also a string so it's
open quote % IW close quote
% I w is the IC standard for 3x register
now where are we going to start reading
from will start from address 3003 and
the number let's read five registers and
will create an array and we'll call it
input from device and this is an array
we're going to read five registers but
I'm going to make this where array eight
because i know i'll have to read three
more eventually and i will hit the check
mark and then i'm going to set the
exchange management table i've already
created a variable to do this so i'm
going to call this the Modbus read
parameters and I am going to put a
one-shot which is our underscore trig
and I'll put him up here and i will
create a variable called read the
variable i will check
I have a space in there though space is
allowed check and create i will create
the link from the output of the one shot
to the enable and then i will go to the
variables i will look at my modbus read
parameters and I will not forget the
time out so i will go to the value and i
will select the 20 because if i forget
that that would be bad we'll go back to
my section of logic and we will test
this section of logic so i will build
I'll rebuild the entire project yes I am
built I will say plc connect the plc is
different plc transfer project to plc
stop the current project
and I am up and running so we'll grab my
modbus parameters and my input I will
right click I will create a new
animation table and i will look at the
devices and then I will also add my read
the variables I've got my 20 second
timeout I did not forget that which is
very good i will set the read the
variables one shot right here and you
see i get values now let's look at the
first table in hex so 39 is the exchange
number that we received from the plc no
errors because I'm 0 here but in case
there is an error I'm going to set this
to hexadecimal as well for the
communication error in the operation
report and then I get 22nd and I've read
10 bytes so let's issue the command
again and you should see some of these
five registers change and there they go
no errors disconnect the cable from the
device we will see the activity bit come
on and then we will see an error after
two seconds there's your error error one
if I go back to the help and I look at
the communication report I can see the
error is exchanged stop on timeout
because I pulled the cable let's put the
cable back together let's go back to my
plc and let's reset the exchange resets
and you see the value change now watch
the values here and that is the read far
I think we'll create another video to
show you how the right bar is written
and then we'll create a sequencer to
sequence between the two