Mach3 can use the
MODBUS protocol to
talk to external units such as PLC's and I/O modules.
It's then possible to use Mach3's BRAIN capabilities to
integrate the external unit with Mach3.
are small, programmable controllers that speak
MODBUS out-of-the-box. They can be programmed in BASIC
as well as LADDER-logic as found on most PLC's. They may
not be the fastest around but they are a good choice for
use with Mach3 due the MODBUS support.
This page is a meant as a
short tutorial on how to get the CUBLOC modules to talk
to Mach3. I'm using the
CB405 module and
CuBase-40M baseboard but the configuration should be
more or less the same with other modules.
Here's a photo of the hardware:
The board has 24
opto-isolated inputs, 16 relay outputs, 4 analog inputs
and 3 16bits PWM outputs - all terminated to screw
terminals. On top of that there's additional RS232 and
RS485 ports (besides those used for programming and
MODBUS), TTL I/O's, I2C and more.
The first thing we need to
do (after installing CUBLOC studio) is to tell the
development software which module we are using, that we
want to use MODBUS and which settings to use for the
MODBUS communications. Then we need to tell it which I/O's
we want to use. All this can be done by going to
Setup/PLC Wizard in CUBLOC studio or by writing the
code manually in the BASIC-tab of CUBLOC studio:
(Click the picture to view code as text.)
In this example we'll use
P5, 6 & 7 as inputs and P32, 33, & 34 as outputs.
The Set Ladder On statement turns on the LADDER
execution (needs to be done for MODBUS to work even
though no LADDER code are actually used) and the Do
Loop statements just loops the BASIC-program
preventing it from running off to la-la land. This is
just about all that needs to be done on the CUBLOC for a
basic I/O test.
(Please note that the
Usepin command acts on the I/O-port number (P0, P1,
P28 etc) and not on the actual pin number of the
module. So when we say Usepin 32, Out we are in
reallity setting P32 as an output and not pin
In Mach3 the first thing
to do is to enable MODBUS by going to Config/Ports &
Pins and ticking the ModBus InputOutput Support
checkbox and while you're there tick the ModBus
plugin supported checkbox too to enable Mach3's
improved MODBUS support. Then go to Function Cfg's
and select Setup Serial Modbus Control. You will
see something like this:
(We'll get back to this window later)
Make sure that Port Num
is set to the COM port number that is connected to your
CUBLOC's RS232 port setup for MODBUS. Set the
Baudrate to the same as on the CUBLOC (115200 in
this case) and the protocol to 8-1-N. Now click the Test
ModBus button. You should see this window:
Again, check and make sure
that communications settings are correct and then click
the Open button. Hopefully you should see the
text No error in the status field. So far so good
- now for the real test.
The CUBLOC's inputs and
outputs (P registers, also called Coils) are
available at Modbus adress 0 to 127 so to turn ON output
P33 we simply write the logic value '1' to Slave
Adress 1, StartC(oil) 33 and NumCoils
1 (since we want to write one register only). To turn it
off again type a 0 (zero) in the data window and click
To read input P5 change
StartC to 5 and click Read. The state of
input P5 should be shown in the data window.
As have been stated before
the CUBLOC's (P) registers starts at adress 0 but you can
access any register you want, like Timers, Counters and
special Function registers. For example, to get the
value of Counter 0 you read register 24576 ($6000).
Please see the CUBLOC documentation for further details.
If the above tests work it
means that we have MODBUS communication between Mach3
and the CUBLOC. There's some really good videos on the
Machsupport web-site dealing with MODBUS and BRAINS. If
you haven't looked at them they are a good starting