Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: poppabear on July 17, 2014, 01:12:06 PM

Title: M4 Serial and TCP Modbus tutorial using an ADC DL06 PLC
Post by: poppabear on July 17, 2014, 01:12:06 PM
     Here is a Tutorial on how to set up, Serial RTU and TCP Modbus both talking simultaneously to a Direct Logic DL06 PLC.
It also shows how to map Modbus registers to Mach4 I/O, and to a PLC, to include an interactive Screen set.

     The "How To" pdf, includes screen shots, of how to hook it all up, and includes how to embed it in the screen designer.
This is working with current build 1900 of Mach4Hobbie. So from the "ATC" page of the included screen set (and ini, and PLC project files). You can read Inputs from the PLC, and you can outputs on the PLC from that page as well. You can read/Write "Bit-Packed" words as well as full registers.

NOTE: To do the tutorial you need to have a DL06  (with ECOM module if you want to run the TCP part), the "How To" artical gives a list of what you need to have to work it. You could "Probably" port these ideas/concepts over to some "Other" Brand of PLC, the concepts should remain valid. I will leave that adventure up to you.

Read the "Read Me First"!!!

Enjoy,

Scott "Poppa Bear" Shafer
Title: Re: M4 Serial and TCP Modbus tutorial using an ADC DL06 PLC
Post by: poppabear on July 17, 2014, 03:54:08 PM
Update on the MB dialog not closing, Steve remoted in to see what I was seeing. He dropped a pearl, that the Serial MB was set to polling at 25ms, but the actual time to complete the poll was 460ms or so. He noted that the ques on the windows event where stacking up since the poll was not completed. So he set my Poll to 600ms, and since that was greater than the serial completion time, it now CLOSES like it should. I.e. via the Red X or Exit.

Further I had my Serial Speed set to 19, and I bumped it up to 38 so it now completes faster, and I set the poll to 500ms to give me some wiggle room.
It now closes as it should every time.......

So, set the Serial Port speed in the PLC and in Serial MB (modbus0) to 38,400 and that will help cut the lag time. I had it origanally low since I was going through USB-Serial converter cables, but they appear to do fine at 38,400.



Thanks Steve!!
Title: Re: M4 Serial and TCP Modbus tutorial using an ADC DL06 PLC
Post by: gjk on December 30, 2014, 03:20:19 PM
Scott,

Thank you for creating the modbus tutorial. It has been extremely helpful. I'd like to display a 32 bit accumulating timer value in a DRO. I've converted the value from BCD to binary in the PLC and am reading the two registers in Mach.  I then plan to use WriteReg("iRegs0/doubletimerval", ?); This is where I am stuck. I am not sure how to format the write register command so that it feeds timer1 and timer2 into the Mach register as a double word. Any help would be appreciated. Thanks again. 


Title: Re: M4 Serial and TCP Modbus tutorial using an ADC DL06 PLC
Post by: poppabear on December 30, 2014, 06:12:59 PM
well, If I am understanding you correctly......... 
you are reading a "High" half, and a "Low half (half being the High bytes, and low bytes respectively).

so you will need to bit shift up your High half (or down depending on if your using big or little endian),
then shift in your low byte, to re-integrate your accumulator value.

The lua version that is in these lastest Mach4's has "Bit-Banging" functions built in, look up the Lua version on the web, I THINK it is 5.2.......... but, it is listed somewhere in the forum, I just cant remember at the moment. But, in that lua version you will see how to do your bit-baning to make it all work.

Scott