The source code below demonstrates the ability of the PLC acts the retransmitter of information with active inner processing.
plcReceive_Transmit_Bytes// Receive bytes in the Port 0, invert the position of its nibbles (the two halfs of 4 bits of the byte) and then retransmit them in the Port 1.
// Functioning:
// 1) Move the focus to the field of edition that simulates the buffer of the Port 0 (click left mouse above this);
// 2) Enter the byte in this field (it's enough to press the character key or, keeping hold the <Alt> key pressed, to type the decimal value of the byte (from 0 to 255) in the numeric keyboard and, after this, to liberate the <Alt> key - observing that, in this case, the typed values and the correspondent printable characters will depend of the code page set in the operational system);
// 3) Press the button next to the field (buffer) that simulates reception or transmission (mouse click on this, or type <Tab> and <Enter>);
// 4) In this moment an event of reception occurs; then the interrup handle receives the byte, does the programmed processing and returns the already processed byte to the Port 1, waiting the event which will indicate the final of its transmission by the hardware of the equipment;
// 5) Simulate the occurrence of this event of final of transmission pressing the button next to the "buffer" of the Port 1 (the byte will be erased in this instant, completing the simulation of the event);
// 6) End of the cycle, that, done repeatedly, simulates the continual flow of reception, processing and retransmission of bytes by the equipment.
// Obs.: which can occur if the byte is received and, previously it have been processed and retransmitted, other byte comes to be received in the port? Suggestion: alter this program to it to deal with this situation by appropriate way.
network 1 // Enables the interrupt handling and attachs the events to be treated to the respective handles.
if (immediateEnable_Interrup) {
if (notStart) {
enable_interrupt;
attachReceive_Byte to_the interruptreception_Port0;
attachTransmit_Byte to_the interrupttransmission_Port1;
turn_onimmediateByte_was_Sent;
turn_onStart;
}
}
else{
turn_offStart;
}
network 2 // Handling of the occurrence of reception byte from the Port 0 event
interrupt_handleReceive_Byte ( )
if (Byte_was_Sent) {
receive_byteinByte_Received_P0come_inPort0;
Byte_to_be_Transmitted_P1B:= 16 * (Byte_Received_P0B& 2#00001111) + (Byte_Received_P0B& 2#11110000) / 16; // Inverts position of the nibbles of the received byte
transmit_byteByte_to_be_Transmitted_P1inPort1;
turn_offimmediateByte_was_Sent;
}
end_interrupt_handle
network 3 // Handling of the occurrence of conclusion of the transmission byte sent in the Port 1 event
interrupt_handleTransmit_Byte ( )
if (notByte_was_Sent) {
turn_onimmediateByte_was_Sent;
}
end_interrupt_handle
end
As result of the compilation of the Receive_Transmit_Bytes program above, the SimuPLC 4.1.0 has generated, exactly, the following code, in Instruction List - IL:
// PLC Receive_Transmit_Bytes // Receive bytes in the Port 0, invert the position of its nibbles (the two halfs of 4 bits of the byte) and then retransmit them in the Port 1. // Functioning: // 1) Move the focus to the field of edition that simulates the buffer of the Port 0 (click left mouse above this); // 2) Enter the byte in this field (it's enough to press the character key or, keeping hold the <Alt> key pressed, to type the decimal value of the byte (from 0 to 255) in the numeric keyboard and, after this, to liberate the <Alt> key - observing that, in this case, the typed values and the correspondent printable characters will depend of the code page set in the operational system); // 3) Press the button next to the field (buffer) that simulates reception or transmission (mouse click on this, or type <Tab> and <Enter>); // 4) In this moment an event of reception occurs; then the interrup handle receives the byte, does the programmed processing and returns the already processed byte to the Port 1, waiting the event which will indicate the final of its transmission by the hardware of the equipment; // 5) Simulate the occurrence of this event of final of transmission pressing the button next to the "buffer" of the Port 1 (the byte will be erased in this instant, completing the simulation of the event); // 6) End of the cycle, that, done repeatedly, simulates the continual flow of reception, processing and retransmission of bytes by the equipment. // Obs.: which can occur if the byte is received and, previously it have been processed and retransmitted, other byte comes to be received in the port? Suggestion: alter this program to it to deal with this situation by appropriate way.