Usage Examples

The following are usage examples of events.

Copy Input Bit to Output Bit

The following code defines an event that sets the output bit 0.0 to 1 when the input bit 0.0 becomes 1. The IoEventInput class used in this code inherits EventInput, and is defined by the Io module. Similarly, the IoEventOutput class used in this code inherits EventOutput, and is also defined by the Io module.

IoEventInput ievi;
IoEventOutput ievo;
EventOption opt;
int id;

//Set the input function to "the input bit 0.0 is 1"
ievi.inputFunction = IoEventInput::IoEventInputType::IOBit;
ievi.input.ioBit.ioSourceType = IOSourceType::Input;
ievi.input.ioBit.bitAddress = 0;
ievi.input.ioBit.byteAddress = 0;

//Set the output function to "the output bit 0.0 is set to 1"
ievo.outputFunction = IoEventOutput::IoEventOutputType::SetIOOutBit;
ievo.output.setIOOutBit.bitAddress = 0;
ievo.output.setIOOutBit.byteAddress = 0;

//Set the initial state of the event to enabled
opt.enable = 1;

wmxlib_EventControl->SetEvent(&id, &ievi, &ievo, &opt);

Copy Input Bit to User Memory When Axis Passes Specific Position

The following code defines two events that copy the value of an input bit to a user memory bit whenever the axis passes a specific position.

The first event in this code will enable another event when another axis passes through the specified position. The other event will be disabled after the axis passes through the specified position. The time that the other event remains enabled depends on the velocity of the axis as it passes through the position, but is at least 1 cycle even at the fastest velocity. If the axis stops within 0.5 user unit of the specified position, the other event remains enabled until the axis is moved away.

The second event in this code will copy the value of an input bit to a user memory bit. When the input bit is 1, the user memory bit is set to 1. When the input bit is 0, the user memory bit is set to 0.

This code is uses the event IDs 0 and 1. If these event IDs will be used by other events, the event IDs that are specified in the code must be changed.

CoreMotionEventInput evi;
EventApiEventOutput evo;
EventOption opt;

IoEventInput evi2;
UserMemoryEventOutput evo2;
EventOption opt2;

int id;

//Set the input function of event 0 to "the position is equal to or passes through 10000"
evi.inputFunction = CoreMotionEventInput::CoreMotionEventInputType::EqualPos;
evi.input.equalPos.pos = 10000; //The position to trigger the event
evi.input.equalPos.axis = 0; //The axis to trigger the event
evi.input.equalPos.useFeedback = 1; //Set to 1 to use the feedback position, or 0 to use the command position

//Set the output function of event 0 to "enable event 1, and also disable event 1 when the input function is false"
evo.outputFunction = EventApiEventOutput::EventApiEventOutputType::EnableAnotherEvent;
evo.output.enableAnotherEvent.targetEventID = 1; //Event ID of the event to enable
evo.output.enableAnotherEvent.setOffState = 1; //Event 1 is disabled when the input function is false (while the axis is not passing through the specified position)

//Set the initial state of event 0 to enabled
opt.enable = 1;

//Set the input function of event 1 to "the input bit 0.0 is 1"
evi2.inputFunction = IoEventInput::IoEventInputType::IOBit;
evi2.input.ioBit.ioSourceType = IOSourceType::Input;
evi2.input.ioBit.bitAddress = 0;
evi2.input.ioBit.byteAddress = 0;

//Set the output function of event 1 to "the user memory bit 0.0 is set to 1, and also set to 0 when the input function is false"
evo2.outputFunction = UserMemoryEventOutput::UserMemoryEventOutputType::SetMBit;
evo2.output.setMBit.setOffState = 1; //The user memory bit is set to 0 when the input function is false (when the input bit is 0)
evo2.output.setMBit.bitAddress = 0;
evo2.output.setMBit.byteAddress = 0;

wmxlib_EventControl->SetEvent(&id, &evi, &evo, 0, &opt);
wmxlib_EventControl->SetEvent(&id, &evi2, &evo2, 1, &opt2);