// ================================================================================================
// Arduino Modbus I/O sample
// ================================================================================================
ushort Inputs = 0;
ushort Pot1 = 0;
ushort Pot2 = 0;
exec.GetModbusregister(0, out Inputs);
exec.GetModbusregister(4, out Pot1);
exec.GetModbusregister(5, out Pot2);
int FRO = Convert.ToInt32(AS3.Getfield(232).Replace("%", ""));
int JRO = Convert.ToInt32(AS3.Getfield(913));
int newFRO = (int)((double)Pot1 / 1023.0 * 300.0 / 5.0) * 5; // 5% step
int newJRO = (int)((double)Pot2 / 1023.0 * 100.0);
if (newFRO != FRO)
{
AS3.Setfield(newFRO, 232);
AS3.Validatefield(232);
}
if (newJRO != JRO)
{
AS3jog.Setfield(newJRO, 913);
AS3jog.Validatefield(913);
}
int newInputs = ((int)Inputs & 0x0F) ^ 0x0F; // 4 inputs, change to active high
if (lastInputs == 16) lastInputs = newInputs;
if (newInputs != lastInputs)
{
int change = newInputs ^ lastInputs;
// NC reset switch -> force reset to switch state
if ((change & 0x01) != 0)
{
if ((newInputs & 0x01) != 0)
exec.Callbutton(513);
else
exec.Callbutton(512);
}
// Compare SPST switch state to screen button state -> press button if needed
if ((change & 0x02) != 0)
{
if (((newInputs & 0x02) != 0) != AS3.Getbuttonstate(114))
exec.Callbutton(114);
}
// NO pushbutton
if ((change & 0x04) != 0)
{
if ((newInputs & 0x04) != 0)
exec.Callbutton(130); // Button pressed
// else
// exec.Callbutton(0); // Button released
}
// NO pushbutton
if ((change & 0x08) != 0)
{
if ((newInputs & 0x08) != 0)
exec.Callbutton(522);
// else
// exec.Callbutton(0);
}
lastInputs = newInputs;
}
bool LED1 = exec.GetLED(19);
bool LED2 = exec.GetLED(54);
bool LED3 = false;
bool LED4 = false;
ushort digitalOut = (ushort)((LED1 ? 0x01 : 0) + (LED2 ? 0x02 : 0) + (LED3 ? 0x04 : 0) + (LED4 ? 0x08 : 0));
ushort analogOut1 = (ushort)(AS3.Getfielddouble(2451) / AS3.Getfielddouble(178) * 255); // Overridden RPM / max. RPM
ushort analogOut2 = (ushort)(0);
ushort[] data = new ushort[3];
data[0] = digitalOut;
data[1] = analogOut1;
data[2] = analogOut2;
exec.SetModbusregisters(10, data);
// ================================================================================================
#Events
// ================================================================================================
int lastInputs = 16;
while(loop)//The built in loop in the UCCNC macroloop core:
{
while(loop)//Your own loop. While this loop is running it will not allow the code execution to the end of the built in loop to execute the 40msec sleep and so you will have to execute a sleep to not overload the computer.
{
//Some code here and add a thread sleep also...
}
Threat.Sleep(40);
} //Built in loop in the UCCNC macroloop core:
Return to Ask a question from support here
Users browsing this forum: No registered users and 30 guests