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

)
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
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
}
}