shmerlard
hi, im new to openplc, i've created this block diagram in 4.1.1
[203128%2F9640889%2Fmceclip0]
where this is the script of serial_test
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

// Called once when the block is initialized
void setup()
{
    Serial.begin(115200);
}

// Called at every PLC scan cycle
void loop()
{
    Serial.println("H");
    delay(10);
}
 
and here is the configuration of the device
[203128%2F9640890%2Fmceclip0]
it does compile and downloads it to the esp but i've noticed two problems
 
  1. there is no printing to the serial port at all, nothing
  2. when i added the `serial_test` block i see that there is a timing problam with the blinking of the led.
is it even possible to use serial.print on openplc?
Reply 0 0
thiagoralves
The problem is not serial.print, but delay(10). You should never use delay() calls in PLC programs as that will halt the runtime for the amount of time you specified EVERY cycle. That’s why you see timing problems when you add your block there.
Reply 0 0
shmerlard
thanks, it solves the second problem but i still dont see any message when im opening a serial monitor, i've made sure its the ame port and baud rate, and it is connected, just nothing appears
Reply 0 0
thiagoralves
Make sure you have not used any serial pins on your mapping as that will affect the serial functionality. Modbus RTU (Serial) must also be disabled on the interface you want to use to print. Also, make sure that after creating your block, you add it to your program, otherwise it will never be called, and nothing will ever happen. It is also advisable to add at least one input to your block to control the flow. For example you can add a BOOL input called print_statement. Then every time you do a True pulse on print_statement the code prints something on serial. Something like this:
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

// Called once when the block is initialized
void setup()
{
    Serial.begin(115200);
}

// Called at every PLC scan cycle
void loop()
{
    if (print_statement)
    {
        Serial.println("H");
    }
}
In general, any code you write on the C/C++ block will be executed by the Arduino API, so the behavior should be exactly the same as running it on the Arduino IDE. The only difference is that the "void loop()" function in this case is called by the OpenPLC Runtime instead of being called by the Arduino framework. There is nothing on the C/C++ code block that isn't supported. If the Arduino API supports it, then the C/C++ also supports it.
Reply 0 0
shmerlard
thanks, appearantly the problem was in the esp board, i used the esp32-c3 super mini oled, for somereason it didnt work, switched to a regular esp32 dev board and it works
Reply 0 0
Reply