@stepan-ozana Hi, yes it is. Please, take a look at Inport and Outport blocks.
Posts made by Jan Reitinger
-
RE: Exchanging data between tasks
-
RE: HW PWM on RPi?
@stepan-ozana Hello, yes PWM flags should work as HW PWM on GPIO12, GPIO13, GPIO18, GPIO19 pins. The functionality should be the same as described here: https://www.raspberrypi.com/documentation/computers/raspberry-pi.html
https://www.electronicwings.com/raspberry-pi/raspberry-pi-pwm-generation-using-python-and-cBest regards,
Jan -
RE: ASCII Commands Over RS485
@georgedumitru I think the best documentation is this thread here on the forum. Byte array reading from communication is also discussed there.
Another helpful tool is definitely the example located at C:\Program Files\REX Controls\REXYGEN 2.50.12.14711\Examples\0203_Function_Blocks_REXLANG.
-
RE: ASCII Commands Over RS485
@georgedumitru
Hello George,It's challenging to give advice remotely when I can't see what's happening. The data might be in a different format than expected. Could you use Trace() to print the contents of the buffer and share it here?
-
RE: Modbus RTU in REXLANG or Python
Hi Mike,
I recommend checking out the examples in the 0401_Modbus_RTU folder or take a look at the 0121-10_Monarco_HAT_Modbus_RTU_ADAM-4024 and 0121-11_Monarco_HAT_Modbus_RTU_Loopback_USB examples. These are all provided in REXLANG. Hopefully, these examples will provide some assistance.
Cheers,
Jan -
RE: Modbus over RS485 and USB
@mikeyh
Hello Mike,Yes, it's possible to use both RS485 for RTU on the Monarco and the USB on the RPi for RTU simultaneously. Check out the illustrative example "0121-11_Monarco_HAT_Modbus_RTU_Loopback_USB." This example features two distinct Modbus drivers: one for /dev/ttyAMA0 (Monarco HAT) and another for /dev/ttyUSB0.
Cheers,
Jan -
RE: ASCII Commands Over RS485
@georgedumitru Hi,
When we refer to a 28-bit number, does this imply that the number is transmitted within 4 bytes? If that's the case, and the number is in floating-point format, you should usedouble buf2double(buf[,endian])
REXLANG function. -
RE: ASCII Commands Over RS485
@georgedumitru Could you post line 111 here or ideally the whole code again?
This minimal example works for me:
#define BUFFER_SIZE 20 string output(1) outputstring; string data[BUFFER_SIZE+1]; long init(void) { data = "hello there"; return 0; } long main(void) { Trace(1,data); outputstring = data; return 0; } long exit(void) { return 0; }
-
RE: ASCII Commands Over RS485
@georgedumitru Hi George,
if you only need a control statement in the log, useTrace(1,data)
. If you want the string to output directly, this should work:... string output(3) outputstring; ... outputstring = data;
Cheers,
Jan -
RE: ASCII Commands Over RS485
@georgedumitru, I believe there's a mistake in the Write command. Instead of using the [CR], it should be the ASCII symbol "\r". My apologies for not thoroughly reading the controller manual. Furthermore, I'm considering putting the switch into an else statement:
long main(void) { /* PUT YOUR CODE HERE */ if(hCom<0) { hCom = OpenCom(serialdevice,COM_BAUDRATE,COM_PARITY_NONE); //Opening Serial Device ConnectionStatus=hCom; } else { switch(status) { case 0: a=Write(hCom,"@00EO\r"); if(a>0){ status=1; } break; case 1: dataCount = Read(hCom, data,BUFFER_SIZE); if(dataCount>0){ if(data=="1"){ ResponseFromDMX="ON"; } else{ ResponseFromDMX="OFF"; } status = 0; } default: break; } } return 0; }
-
RE: ASCII Commands Over RS485
@georgedumitru Hello George,
Would you mind sharing the part of the project related to communication with the controller? If you prefer to keep it private, please feel free to send it to support@rexcontrols.com.
Thank you!
-
RE: ASCII Commands Over RS485
@georgedumitru Let me know how you're doing. I've also found it helpful to set the
status
as an output of REXLANG block and to use tracking using the Trace() function. However, it is necessary to have the "Function block messages: Information" option checked in the System Log Configuration in REXYGEN. -
RE: ASCII Commands Over RS485
@georgedumitru Hi George,
a. To send commands in ASCII format to the device, you can use theWrite()
function. For example, the following code will send the command@00DI[CR]
to the device:a = Write(socketHandle,"@00DI[CR]");
if
a>0
, the write command was successful (see the error codes in the REXLANG doc for Write() function). The value ofa
will be the number of bytes that were written to the device.
b. To receive the response from the motor controller, you can use theRead()
function. For example, the following code will receive up to 10 bytes of data from the device:dataCnt = Read(socketHandle,data,DATA_SIZE); //receive data, max number of bytes = DATA_SIZE if (dataCnt > 0) // data received { DO_SOMETHING }
I've defined data as the string and DATA_SIZE as a constant in the code before:
#define DATA_SIZE 10 //maximum number of bytes to receive string data[DATA_SIZE+1]; //buffer for incoming data
The
main()
procedure body can be a kind of state machine. I personally use a switch-case construction, but it can also be done externally using an ATMT block. For example, the following code will send a command in one tick and then wait to a response in the next ticks:switch(status) { case 0: a = Write(socketHandle,"@00DI[CR]"); if(a == 6) { status = 1; } break; case 1: dataCnt = Read(socketHandle,data,DATA_SIZE); //receive data, max number of bytes = BUFFER_SIZE if (dataCnt > 0) // data received { DO_SOMETHING status = 0; } break; default:
Please note that this is just a simple example, and you will need to modify it to fit your specific needs. Try to go step by step. First get a simple response from the controller and then create complex code.
Is there a reason why you are using the USB<->RS485 converter and not the RS485 directly on the Monarco HAT?
Cheers,
Jan -
RE: What is the easyest way to hide the headers completely
@gerritjan1 Hello,
To remove all headers from the HMI (Human-Machine Interface), you can change the header mode to "thin" or "pack" in the HMI Designer. Unfortunately, it's not possible to completely hide the header, but these modes provide a more compact display. Here's how you can do it:
-
Open the REXYGEN HMI Designer.
-
Access the HMI Configuration menu (you can use the shortcut Ctrl+E without focusing on any component).
-
In the HMI Configuration, navigate to the "Options" tab.
-
Look for the "header_mode" setting and select either "thin" or "pack," depending on which one suits your needs best.
By choosing one of these modes, you'll make the header more minimalistic and compact, which can be helpful when embedding the HMI in an iframe.
Please note that completely hiding the header may not be possible without modifying the HMI's source code, and doing so could have unintended consequences on its functionality. Therefore, using the "thin" or "pack" modes is the recommended approach.
Cheers,
Jan -
-
RE: Conditional exectution of code block.
@gerritjan1 I've observed that you are currently using the flags MTM__readBlock_ReadEnable and MT__writeBlock2_WriteEnable. However, in a previous post, you mentioned flags named MTM__readBlock1 and MTM__writeBlock1. It is important to ensure that the flag names correlate properly. Therefore, for MTM__readBlock1, the corresponding enabling flag should be MTM__readBlock1_ReadEnable, and for MTM__writeBlock1, the enabling flag should be MTM__writeBlock1_WriteEnable.
-
RE: Conditional exectution of code block.
@gerritjan1 Hello,
I wanted to inquire if you utilize data from Modbus in the Level0 task. If not, please verify the factor in the Modbus driver block and adjust it based on the fastest task where you read or write Modbus data.
It is worth noting that a task running on a Raspberry Pi with a 2 ms period can be quite demanding. To assess the situation, you can navigate to Target -> Diagnostics -> <your task> and enable Diagnostics in the Task tab. Check the Max/Average time executing values, which are displayed in milliseconds. It is possible that due to the demanding task at level 0, REXYGEN may not have enough time to execute tasks at other levels effectively. Have you considered increasing the tick value? REXYGEN performs various calculations and tasks during execution, making a direct comparison between reading Modbus in REXYGEN and a Python function inaccurate.
Furthermore, you can try enabling more I/O driver messages in Target -> Configure System Log to verify if the desired events occur within individual periods. Specifically, check if the Modbus data is read during the same period when you set the _ReadEnable flag to true.
Best regards,
Jan -
RE: Conditional exectution of code block.
@gerritjan1 Hi,
thanks for the additional information. To temporarily disable reading/writing to Modbus, I would try using the special flags _ReadEnable and _WriteEnable. In your case, the flags would be called MTM__ReadBlock1_ReadEnable and MTM__WriteBlock1_WriteEnable. Setting TRUE to these flags will enable the corresponding operation. You can find the documentation in Chapter3.4. If you have several Master devices on the bus, it is not a completely standard solution.If I misunderstood your question, please provide more details.
Cheers,
Jan -
RE: Conditional exectution of code block.
Hi @Gerritjan1 ,
as you mentioned in the e-mail, the correct way to provide connection between various tasks are Inport and Outport blocks. The crucial thing is that corresponding Inport a Outport should have the same Block name (for example PinValve).
The connection between two tasks is shown for example here:
Regarding your question about conditional task running: Is there any special reason to run the task only when the value has changed? Modbus master should write the value only when it differs from previous one. From REXYGEN Modbus documentation, Chapter 4:
write - writes the value to cache (if it differs from the previous value, it is transmitted during the nearest Modbus cycle)
Cheers,
Jan -
RE: Is certificate expired?
Hi Serg,
It's possible that the issue you're encountering with the certificate is related to your system being outdated. Have you tried updating your system, set current date and time and then attempting to install the Raspberry Pi runtime again?
Cheers,
Jan -
RE: Floating Run Time License
@mikeyh Hi Mike,
I'm sorry for the late reply. Unfortunately, we do not have a floating licenses yet. We are counting on something similar in the future, but I'm irfaid it will take some time.
Cheers,
Jan