Welcome, Guest. Please login or register.
Did you miss your activation email?
September 23, 2014, 09:19:27 AM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  Mach SDK plugin questions and answers.
| | |-+  SetLED function
Pages: 1   Go Down
Print
Author Topic: SetLED function  (Read 3656 times)
0 Members and 1 Guest are viewing this topic.
freedom2000
Active Member

Offline Offline

Posts: 36


View Profile
« on: August 16, 2010, 03:53:23 AM »

Hi all,

I have successfully connected my PICDem custom board as an HID device to Mach3 using Ed's MachPuginWizard and a dll provided by Microchip.
This board is using a PIC18F4550 USB device

So currently, I am able to :
- input digital IO to Mach3
- input analog IO to Mach3
- output digital IO to my board
- output DRO  "value" to my board

The code is extremly simple and works very well for :
- GetDRO()
- SetDRO()
- GetLED()
- code()

BUT I still have a strange behavior with the SetLED function.

It is well recognized, the compilation and link work well. But when running nothing happens... The led state doesn't change at all.

Here is the code of the piUpadte function.

As you will see it is still a quite simple prototype (just to discover the great capabilities of Mach3 plugins  Wink)

It does the following :

- check if the PICDem board is connected
if yes
- looks at if a button is pressed
- if yes toggles the Spindle (M3, M5 Gcode)
- Tries to toggle the flood  with the SetLED function which doesn't work
- clears the Z DRO

and finally gets an analog input to update the Spindle Speed DRO


Please any help would be appreciated for the SetLED function !!!

Regards
JP


Code:
void piUpdate()
{
if (MG::xyzDemoDialog)
{
double ADCValue = 0;

XYZDemoDialog^ xyzDemoDialog = MG::xyzDemoDialog;
if (MCHPHIDClass::USBHIDIsConnected () == true)
{
xyzDemoDialog->textBoxX->Text =  "Connected";
unsigned char OutputPacketBuffer[64]; //Allocate a memory buffer equal to our report size
unsigned char InputPacketBuffer[64]; //Allocate a memory buffer equal to our report size


OutputPacketBuffer[0] = 0x81; //0x81 is the "Get Pushbutton State" command in the firmware

if (MCHPHIDClass::USBHIDWriteReport (OutputPacketBuffer, 1) == true)
{
MCHPHIDClass::USBHIDReadReport (InputPacketBuffer);
//InputPacketBuffer[0] is an echo back of the command.
//InputPacketBuffer[1] contains the I/O port pin value for the pushbutton (1 = not pressed, 0 = pressed). 
if(InputPacketBuffer[1] == 0x01)
{
xyzDemoDialog->textBoxY->Text = "Not Pressed"; //Update the pushbutton state text label on the form, so the user can see the result
}
else //InputPacketBuffer[1] must have been == 0x00 instead
{
xyzDemoDialog->textBoxY->Text =  "Pressed"; //Update the pushbutton state text label on the form, so the user can see the result

SetDRO(802, 0); // clears the Z DRO

if (GetLED(11)== true) // get the staus of the Spindle
{
Code("M5"); // stops the spindle (if running)
xyzDemoDialog->textBoxY->Text =  "spindle OFF";

SetLED(13, false); //DOES NOT WORK (should stop the flood)
}
else
{
Code("M3"); // start the spindle (if not running)
xyzDemoDialog->textBoxY->Text =  "spindle ON";

SetLED(13, true); // DOES NOT WORK (should start the flood)
}

}

ADCValue = (double)(((InputPacketBuffer[3] << 8) + InputPacketBuffer[2])*30); //Need to reformat the data from two unsigned chars into one unsigned int.
SetDRO(817, ADCValue); //SpindleSpeed 817 updated with analog input from PICDem

}
}

else
{
xyzDemoDialog->textBoxX->Text = "Disconnected";
xyzDemoDialog->textBoxY->Text = "Not Pressed"; //Update the pushbutton state text label on the form, so the user can see the result
}


xyzDemoDialog->textBoxZ->Text = GetDRO(202).ToString("F4"); //SpindleSpeed Overwrite


}
}
Logged
poppabear
S S SYSTEMS, LLC
Global Moderator
*
Offline Offline

Posts: 2,083


Briceville, TN, USA


View Profile WWW
« Reply #1 on: August 16, 2010, 07:17:29 PM »

The SetLED(####);

ONLY works for USER LEDs range 1000-2255, the other OEM LEDs status are set internally by MACH, YOU cannot set them.
the only way you can change the state of an OEM LED is to use a mach Button function if that LED has one, the OEMs are display/read only, you can do a GetLED on any LED both OEM and User.

Look at a "DoButton(###);" code to toggle the OEM functions that have status LEDs associated with them.

Look at the VB docs (member docs, the new docs, there are several plus the wiki floating around).  You can look at the VB Button functions and codes and the OEM LED codes and see which ones you can tie together.

BTW: Very nice job on the PIC and USB!!!  U DA MAN!!!

Scott
Logged

Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
https://sites.google.com/site/sssystemsautomation/
freedom2000
Active Member

Offline Offline

Posts: 36


View Profile
« Reply #2 on: August 17, 2010, 01:52:18 AM »

Thank you Scott for this clear answer.

I had in mind something like this but I wanted to be sure  Wink

I have found another way to do the trick : with Engine->InSigs(x).Activated = true;

This PIC18F4550 is really a simple device. Here is a simplified version of the PICDem board (which can be simplified even more if you supress the RS232 connector and circuitry). I have equiped it with a few leds, buttons and pots to test the board.
35 IOs are accessible includng 13 AD converters on 10 bits.



The board itself remains very compact. This is a simulation but the real one looks the same !!



And finally a working small plugin based on the excellent Ed Byron's MachPluginWizard.

It does nothing but :
- checking the connection
- when pushing a button : reset Z DRO, Spindle toggle
- when turning a potentiometer : Spindle Speed adjustment

This a simple exemple, but it is so funny to see how easily a plugin can be done --> Great program Art !

The youtube video is here : http://www.youtube.com/watch?v=El08JLbPhG8

Thanks again for your help Scott

JP
Logged
poppabear
S S SYSTEMS, LLC
Global Moderator
*
Offline Offline

Posts: 2,083


Briceville, TN, USA


View Profile WWW
« Reply #3 on: August 17, 2010, 10:02:14 PM »

NP,

   Ed Bryson is a TOTAL programming GURU!!!!  He does alot with PICs as well, and he turned me on to the using a demo PIC board and MPLAB. Ed lives close to me, and I am lucky enough to go over to his house and sit at the feet of Yoda.......  Smiley

Really nice job, and especially the USB stuff, that crap can be a super duper pain in the but to use the windows native HID/USB.

scott
Logged

Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
https://sites.google.com/site/sssystemsautomation/
freedom2000
Active Member

Offline Offline

Posts: 36


View Profile
« Reply #4 on: August 18, 2010, 01:49:42 AM »

NP,

   Ed Bryson is a TOTAL programming GURU!!!!  He does alot with PICs as well, and he turned me on to the using a demo PIC board and MPLAB. Ed lives close to me, and I am lucky enough to go over to his house and sit at the feet of Yoda.......  Smiley

Really nice job, and especially the USB stuff, that crap can be a super duper pain in the but to use the windows native HID/USB.

scott

You are right, I have been really impressed by Ed's skills and even more by his video tutorials which are a real evidence of his kindness.
You are lucky to live close to Yoda !
As he doesn't read his own forum, if you see him please tell him that he begins to be famous in France too :-)

The Usb stuff is a real pain, but thanks to Microchip's dll it's no more than 1 line to discover and attach the device.
I will post the pcb layout and the source code both for the plugin and the PIC when a bit more "finished".
With less than 15 you can increase Mach3's IO in an easy and affordable way !
I know that the pokeys is there and its plugin really nice... but I wanted to do mine, just for fun !

JP
Logged
shad71
Active Member

Offline Offline

Posts: 13


View Profile
« Reply #5 on: March 19, 2011, 09:46:43 AM »

Hi!
I'm working on creating a plugin to disable Automatic Voltage Control at the end of the cut path in plasma cutting.
Tell me, can I directly control the output LPT port pins from the plugin?
Now I turn on the LED (SetLED(1005,1)), and monitor its state in macro.
Thank you!
Logged
shad71
Active Member

Offline Offline

Posts: 13


View Profile
« Reply #6 on: April 14, 2011, 03:48:12 AM »

Both on and off the desired pin.

if (Engine->OutSigs[EXTACT4].Activated == TRUE)      Engine->OutSigs[EXTACT4].Activated = FALSE;

EXTACT4 - Output #4
Logged
Pages: 1   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!