Hello Guest it is December 21, 2024, 12:02:37 PM

Author Topic: controlling bits in Mach for PLC communication  (Read 5332 times)

0 Members and 1 Guest are viewing this topic.

controlling bits in Mach for PLC communication
« on: January 01, 2012, 06:11:55 PM »
How does one turn on and off bits in memory to communicate with PLC?  I can see how to do it from the PLC side by set B1600.10 and reset B1600.10 but on the Mach side I can't find anything in the documentation that describes how to set bits.  SetOUTbit()  and resetOUTbit() seem to be the ones to use but there is nothing written about how to use it as all text is in red I think indicating this section under Mod Bus programming is under construction.

Thanks
Keith

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
Re: controlling bits in Mach for PLC communication
« Reply #1 on: January 01, 2012, 07:16:23 PM »
I use the original serial interface rather than the plugin and I can do it a few ways. First is via normal ports and pins, port 0,  pin whatever is to/from PLC via modbus. I can do it via VB, GetInput(1) or SetModOutput(1,1) etc or finally can do it via a brain.
Hood
Re: controlling bits in Mach for PLC communication
« Reply #2 on: January 01, 2012, 09:09:00 PM »
Hood,

I need to figure out how to use the base output and input register eg V1600 which has 16 bits referred to as B1600.0,  B1600.1, B1600.2 ... B1600.15   I understand how to work with bytes as you have suggested using pins and port or Setuserled, Getuserled or setuserdro etc but is there not a difference when controlling bits as opposed to bytes?

Thanks
Keith
Re: controlling bits in Mach for PLC communication
« Reply #3 on: January 01, 2012, 10:35:47 PM »
Here is a pretty good explanation handling I/O by Henrik. Although he is talking about his own modbus board, the principles should apply.

http://henriksplace.se/cnc/cnc_mach3_minimodbusboard.html

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
Re: controlling bits in Mach for PLC communication
« Reply #4 on: January 02, 2012, 12:21:54 AM »
http://www.machsupport.com/videos/

Serial Modbus Plugin video may help.

Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
Re: controlling bits in Mach for PLC communication
« Reply #5 on: January 02, 2012, 03:57:47 AM »
It will depend whether you use the old serial interface or the plugin I suspect but with the old serial interface you just set the start register you want, see screenshot of mine.
The PLC I use is octal, which I presume is normal but in Mach its decimal so for example in the screenshot the start register for the first inputs is 1025 as that is the dec for 2001 in Oct.
Hood
Re: controlling bits in Mach for PLC communication
« Reply #6 on: January 02, 2012, 07:09:59 AM »
I appreciate all the suggestions but we have not gotten to the detail that I am lacking yet. So the serial plugin is setup and the registers are defined already.  I know the specific address is 1600.  I want to be able to individually turn on and off or set each bit of this 16 bit address to 1 or 0 from Mach.  On the PLC side I just set B1600.10 to turn on bit 10 of the V1600 output register.  I just can't see how to do that from the Mach side in VB.  I do realize how to deal with bytes on the mach side but not bits.


Thanks!

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
Re: controlling bits in Mach for PLC communication
« Reply #7 on: January 02, 2012, 08:00:54 AM »
Sorry cant help with the plugin as I have never used it as I believe you can not access via VB when using it, could be wrong though ;)

I only ever learn enough to do what I want to do so I dont know a huge amount about ModBus, you may have gathered that ;)
I think if using the Non Plugin serial interface then you would have similar to mine above, your output start register would be 896 (dec for 1600 oct) and if you have the bitpacked option chosen like I do the for each set of 16 outs you would only need to look at one register. Ok so if you set up as mentioned then I think you should be able to set the output by calling SetModOutput(0,1) or (1,1) or (2,1) or (1,0) etc.

Maybe I am still not grasping what you are asking though, very likely ;D
Peter Homann would be the guy to ask for the plugin interface if you wanted to use that.
Hood
Re: controlling bits in Mach for PLC communication
« Reply #8 on: January 02, 2012, 01:33:51 PM »
Hood,

I looks like it is too difficult to work at the bit level in Mach so I switched to just changing the bytes and it worked out nicely.  That way I can load and output integers to the registers in a byte wise fashion.  It takes a little more effort to load and output on the PLC side but straight forward on the Mach VB side.  Now setuserdro(1407,1) in Mach to turn on spindle and PCL checks 1407 = 1 to turn on spindle.  Then when spindle off setuserdro(1407,0) written on Mach side and on PLC side read 1407=0 to turn off.  When spindle is off on PLC side 1607=0 and when on 1607=1  Mach can read with getuserdro(1607) to check the status of the PLC.  That way there is a check back and forth.  Also must interlock with chuck clamp and tail stock in and out to be sure they are not able to change while spindle is on.  Lots of fun now to actually start making this machine work.  I love retrofitting!  Hope to actually see it work later today if wife will let me sneak back to the shop on a holiday...

Thanks
Keith
« Last Edit: January 02, 2012, 01:35:59 PM by thespindoctor »