Machsupport Forum

Mach Discussion => Brains Development => Topic started by: Kisssys on October 20, 2008, 08:49:16 PM

Title: Update DRO from Modbus
Post by: Kisssys on October 20, 2008, 08:49:16 PM
I programmed a PIC chip to be a mini ModBus and it seems to be working great

I created a little VB script to step thru to see how it's doing and it does just what I want, It  inputs 64,65,66,67 and assign's the correct values to the variables.
As you can see from the script I have a DRO assigned 1010 that it displays the XaxisRegister and it does that all correctly.

TabletXaxisPos = GetInput(64)/1000
TabletYaxisPos = GetInput(65)/1000
ButtonValue    = GetInput(66)
FlagValue      = GetInput(66)
SetOemDRO(1010,TabletXaxisPos)

All of the script works fine!!!

I am trying to write a brain to automatically update the DRO instead of a macropump and I'm not having any luck.

My brain shows MOD:4-P:64     Formula = A/1000     OEMDRO:1010    I divide by 1000 to scale the 0 to 12000 input to inches

My Mod bus is Address 01  and its the first 4 registers.  I must be doing something wrong in the Mod bus definition somewhere but can't see it.

I'm trying to display my Graphics Tablet on the Screen

Kisssys


Title: Re: Update DRO from Modbus
Post by: Kisssys on October 20, 2008, 09:29:31 PM
Well I installed the plug in and configured CFG0 and it works. 

Probably more to come but I'm working now

Thanks
Kisssys
Title: Re: Update DRO from Modbus
Post by: poppabear on October 21, 2008, 09:47:48 AM
I would LOVE to hear about your progress in this area!!!  By all means, PLEASE keep up posted!!  Also, is you Pic design for sale?  Can you assign different device numbers to your Pic so that you could have multiple of these devices on a 485 or 422 drop net work??

How much I/O do you have? (Discrete and Analog?)

Scott
Title: Re: Update DRO from Modbus
Post by: Kisssys on October 21, 2008, 05:24:38 PM
I would be glad to keep you posted on the progress.  Modbus is a pretty simple once you get the CRC code working.  It's as easy to do RS-485 as RS-232 so that's not a problem and
addressing is no problem.  Don't know much about Modbus but it's not very complicated.  I needed a way to get the Graphics tablet *********xx,yyyyy,n data in and that's the simplist way I could find.  I read the tablet into the pick and store the data in the registers that Modbus calls, pretty simple.

I'd be glad to make a few boards if the demand is their.

Kisssys
Title: Re: Update DRO from Modbus
Post by: poppabear on October 21, 2008, 07:45:20 PM
Please list total specs, and can each be addresssed differently so they can be Chained to gether with a drp network for expandability??

est. Price, etc. 

Also:  ETHERNET Options!!!!!!!!!!!!!

Scott
Title: Re: Update DRO from Modbus
Post by: Kisssys on October 27, 2008, 08:43:19 PM
Well I thought I was ready to go out to the shop and run some tests with my plasma cutter and the code locks up at a point I'm waiting for a button press
from the graphics tablet.

The code was written on my laptop and works fine and it works on my other computer in the office all of which I would suspect running Mach3 might have an issue but
it dies on the plain old generic dell 1gig in the garage.   It locks the computer up so tight I have to hold the off switch to shut it down.  When I view the brain tablet.brn
it is reading correctly, it opens the file and as soon as I go into the code

While getUserLed(1200)
Wend             'wait here for the "tablet.brn" to see I've pressed the button on the tablet

it locks up.  I'm sure your not used to seeing something like that but its common in embedded controllers to wait for something to happen this way. 
Once it locks up I can't go look at anything to see what's going on so kinda at a loss.  I'm going to start all over in the garage with just those 2 lines of code but don't have time for a while and I was wondering if anyone has seen a script or brain act up like this.  I guess I can move my cutter into the living room

Any ideas
Kisssys
Title: Re: Update DRO from Modbus
Post by: fer_mayrl on October 28, 2008, 07:52:53 AM
Hello
Try adding a:

SLEEP 100

between the

While getUserLed(1200)
Wend             'wait here for the "tablet.brn" to see I've pressed the button on the tablet

To get

While getUserLed(1200)
SLEEP 100
Wend             'wait here for the "tablet.brn" to see I've pressed the button on the tablet

When you have a loop like that, mach makes MANY cycles and uses a lot of resources, adding the sleep command, slows down this cycle as to not lock up your computer.

What version of mach are you using, If you are using the latest version, then just adding that line would do, Art added the declaration of the sleep command internally, if you are using older versions of mach, then you would have to declare it with this at the beginning of your code:

Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)

Hope that gets you going
Fernando
Title: Re: Update DRO from Modbus
Post by: poppabear on October 28, 2008, 05:24:05 PM
If you can,

   I would get away from the while loop all together, there is a friendlier version of it.  I think it is called "WaitForSignal()"  (or something like that, I am in Venezuala so I dont bring my Mach R & D stuff with my work computer.........  Some else here can look it up, OR you can look on the Wiki under "Mach Specific Functions" Its exact syntax and use is in there. It only works on a REAL input signal, NOT a simulated on.......

Scott
Title: Re: Update DRO from Modbus
Post by: Kisssys on October 28, 2008, 06:50:50 PM
   

While getUserLed(1200)
Wend             'wait here for the "tablet.brn" to see I've pressed the button on the tablet
 
 
Do While Not GetUserLed(1200)   'wait a while here so we don't log more than one point

 count = count + 1      'increment delay counter
 
If count > 20000 Then
  Exit Do
End If
Loop

Replace that with
//////////////////////////////////////////////////////////////////////////////
While getUserLed(1200)
Sleep 1
Wend             'wait here for the "tablet.brn" to see I've pressed the button on the tablet

Sleep 300

That gets it to work on all 3 computers and I'm functional.  Little confused at times on the Get and SetUserLed function and how it works.  I was at times unable to NOT the function and reverse the action.  I'm working now so I'll get on with my project.  I thought the hard part would be building the Modbus board.

I looked at Mach Script docs that I have and did not see a Waitforsignal() function but I always seem to have to dig to find what I want.

Thanks for the help everyone, I'm more apt to create code like this if I know someone can bail me out

When I get time I'll add a couple of analog channels,encoder input and 8 switch inputs to the board and I'll see how well that works.  I bought a couple of RS-485 chips and when time permits I might convert my pendant to modbus instead of Keygrabber and put them on RS-485.

Kisssys
Title: Small change
Post by: Kisssys on March 26, 2009, 07:42:20 PM
I have been using the brain and script that was discussed in this thread for quite a while with great success and would like to make a small improvement but can't seem to make it work.

To refresh everyones memory quickly, I take the output of a graphics tablet into a modbus controller.  I use the data points to create a simple plasma cut file.

Everything works great but I'd like to activate the script mentioned above by a button press on the graphics controller instead of a mouse click or keyboard entry.

I modified the brain to look at another button and then "1034- Execute Button Script"  which of course doesn't do what I want or I wouldn't be posting this.  I'm confused how Mach3 stores button scripts and how to call any one individually without pressing the button with the mouse.  When I use the button editor, no matter which button I select on any page, even though the code is obviously different the file name is always "hiddenscript.m1s".

Can Poppabear or someone lead me in the right direction as how to do this.

I really appreciate the help I've gotten in the past and hope to save some time figuring this out.

Thanks
Kisssys
Title: Re: Update DRO from Modbus
Post by: poppabear on March 26, 2009, 08:08:51 PM
While you can run a "button/macro" from a Brian, it is a major pain in the ass.....

So, I would probably move your script to the Macro pump, like this: I will call your script, "My script here"
Map your hand held script trigger button to something like OEMTRIGGER1 or something (enable that in PP).

macropump.m1s

counter = GetUserDRO(2200)

if IsActive(OEMTRIGGER1) and counter = 0 then
"My script here"
counter =1
end if

if NOT(IsActive(OEMTRIGGER1)) and counter = 1 then
counter =0
end if


'Shamless plug here as well: if you want you could by a copy of my Mach MAD plug in, you can then run upto 15
'different Macros from upto 15 different input LED triggers............. hehehe

'scott
Title: Re: Update DRO from Modbus
Post by: Kisssys on March 26, 2009, 08:46:31 PM
Thanks Poppabear
Title: Re: Update DRO from Modbus
Post by: poppabear on March 26, 2009, 10:24:22 PM
 ;D