You are not logged in.
test_rexlang1.cmotor_taskv5.mdlI am trying to program a REXLANG block to change a single output variable multiple times in one run of the program. In the C program associated with the REXLANG block, I used LoadValue(4, -1) tot get the next line in the file. However, when I try to loop to continuously change the output, it doesn't work. Attached is the C and mdl file - test_rexlang1.c & motor_taskv5.mdl.
Also, is there a way to print out the value of the variable to the REX console in RexDraw for debugging purposes? Thanks
Last edited by ier123 (2016-04-27 15:49:00)
Offline
I think you forgot to include your files....
Offline
The community is not able to see your uploads before you post the link. You can do that by editing your post (or making a new one) and in "Uploads" window there is an icon in lower right corner "Insert" which will insert the link of chosen file to your post.
Offline
Are you able to see the files now?
Offline
Yes, all ok now. (but now you have them twice in your post, tomas already corrected your post for you...)
I think it is not possible, I guess that the outputs of the REXLANG FB are only written at the end of the cycle as the inputs are read in the beginning. Once the REXLANG FB is executed the next function block will be executed, all FB's one by one. So even if your outputs are changing multiple times the connected FB will only see one value.
I might be wrong as I'm completely new to all this....
Last edited by scoobsalamander (2016-04-27 18:06:34)
Offline
Scoobsalamander is completely right about writing REXLANG outputs at the end of the period and also about executing all FB's in certain order, thank you, scoobsalamander!
It is not possible to make multiple changes to one output of REXLANG in one period.
One thing to your .mdl file: be sure about the functionality of "PWM" function block. It is primary not intended to be used with Raspberry PI PWM output. You can connect any integer signal in range (0, 1023) to the "RPI__PWM18" flag in order to get duty cycle (0 %, 100 %).
Hope that helps.
Regards, Tomas
Offline
If the REXLANG block doesn't contain that functionality, is there another way to loop through a text file so that the number being sent to the PWM pin out is updated continuously without having to stop and restart the program?
Offline
What refresh rate do you need?
What is the time between two executions of your REXLANG block?
You just cannot stick in a loop inside the REXLANG block. Instead the block will be executed every x milliseconds. So if you read at every cycle the last line of value(s) and send this to your output it will be ok I guess....
Offline
Hi ier123,
here is an example which reads a sequence of values from a text file.
REXLANG_Reading_values_from_file.zip
See the README.md file for description. Please let me know if it worked or if there is some clarification needed. I'll include it in our examples repository afterwards.
If you need to read more than a single signal, we have the EPC function block for that.
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
As for debugging your code, you can use the Trace command, see the REXLANG documentation.
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
Ok, I've been working on this a while. I'm trying to use a lookup table for a pressure gauge and I'm not getting anything from the file. In case something was wrong with my source file I switched to the text file in the example above. I also switched to and modified the code from the example (Attached). The code attached is where I'm at now. The second output (answer) is to verify the loop switches when it sees the input go non-zero. I've also removed the variable from the LoadValue statement so I know what value to expect from the text file.
Watching the block execute, the input changes as I expect and answer changes in response but output 0 is always 0. The values in the example text file are non-integers, thinking that might be the problem I changed them to integers, still no joy. I checked and the source text file is on the target device (/rex/rexcore/values.txt).
I also tried using the SILO function with similar results. I downloaded the examples (SILO_Reading_value_from_file) but get error 27 when opening. I'm using V 2.10.8.59.10.
Thanks!
Last edited by coldh2odvr (2016-05-11 01:24:07)
Offline
Hi coldh2odvr,
I tried your Rexlang.c code together with REXLANG Reading values from file example Jaroslav posted above and it works for me.
REXLANG output "y0" is set to the value stored on 10th line of "values.txt" file once REXLANG input "u0" is ">0" (e.g. 1).
Please, can you share all of your project files so I can try to track your issue? Everything you mentioned in your post seems to be correct (both implementation and expectation).
Regards, Tomas
Offline
Hi Tomáš,
Here's my project and project files. This is kind of a scratch pad as I'm learning Rex so it's a bit of a mess. Thanks for your help!
Dave
Offline
Hi coldh2odvr,
the file to read from is specified in "fname" parameter in REXLANG block. In your case the "fname" parameter of REXLANG1 block (the one responsible for reading data from file) is "Rexlang.txt":
I assume that the "Rexlang.txt" file is missing on target device according to your previous post:
... I checked and the source text file is on the target device (/rex/rexcore/values.txt). ...
Check the file names and it should be working
Good luck with your project!
Regards, Tomas
Offline
Thank you for the reply. The Rexlang.txt is there; I had started writing, thought of something, made some changes then resumed writing (sorry). I've cleaned up the task to avoid further confusion and uploaded the files.
For now, Rexlang.txt is a text file with numbers from 0 to 1000
It takes a while for the Modbus read to complete. While the Modbus read supplies 0 to REXLANG1 u0, y0= 0 and y1=2. Once u0 sees a value >0, y1 changes to 1 but y0 still stays at 0. So REXLANG1 is seeing and responding to the input, it's just not reading the file.
REXLANG1\Rexlang.c:
long input(0) read;
double output(0) value;
double output(1) answer;
long init(void)
{
return 0;
}
long main(void)
{
if (read > 0)
{
value = LoadValue(4,10); //read text line 10
answer = 1;
}
else
{
LoadValue(4,5); //read text line 5
answer = 2;
}
return 0;
}
long exit(void)
{
return 0;
}
Offline
Hey coldh2odvr,
please, can you try to connect a constant to the "REXLANG" input as seen in the screenshot below? Because this setup works for me.
Once you change the constant to something ">0" "REXLANG" should output the tenth item of your text file.
Let me know if you made it work.
Regards, Tomas
Offline
Still no dice, changing from 0 to non-zero on u0 (using a constant) changes the y1 output but only 0's from y0. I'm using Notepad in Windows to generate the text file, any chance there's something wrong with the way it formats the file? I double checked and the text file is in the \rex\rexcore folder. Also can't get the demo to run due to the Code 27 error.
PS. Thanks for all the help, you guys are awesome!
Offline
Hey coldh2odvr,
have you tried to run the example REXLANG Reading values from file itself? Just want to eliminate any other influences (e.g. Modbus, ...) in order to test the functionality of reading values from file.
Looking forward to hearing from you!
Regards, Tomas
Offline
Hi Tomas,
I compiled and ran the example (no changes, no modbus stuff), no Code 27 error this time. Still not reading the text file. I set u0 (read) to 1 and y0 (value) remains 0. I edited values.txt and changed the first line from 0 to 17 (no reason for 17 other than a random non-zero) and y0 still reads 0. I added an output y1 (state) and set the value in the if statement, it responds appropriately to changes in u0.
REX version 2.10.8, Rev 5910, Date 2016-02-28.
Device arm, OS Linux 3.x
System log
date;time;severity;message;
2016-05-18;09:24:28.326;Verbose;Waiting for command ...;
2016-05-18;09:24:29.276;Verbose;IntpArcRead;
2016-05-18;09:24:29.276;Verbose;Waiting for command ...;
2016-05-18;09:24:29.276;Verbose;IntpTrndRead;
2016-05-18;09:24:29.276;Verbose;IntpTrndRead: No more archive items nBytes = 414;
2016-05-18;09:24:29.276;Verbose;Waiting for command ...;
2016-05-18;09:24:29.276;Verbose;IntpGetExecDgn;
... repeats
I've tried to open the text file on the rPi itself but get a don't have permission error. I'm assuming it's locked by Rex?
Thoughts?
Offline
I also tried the 'REXLANG Reading values from file' but without success.
Then I've been fooling around a little and suddenly I could read a text file with the name rexlang.dat with the following function
value = LoadValue(7,-1);
Offline
I also tried the 'REXLANG Reading values from file' but without success.
Well this is something we should figure out prior to anything else. Can we please focus on this example and find out what is wrong here? Can you please run the following commands on your RPi and post here the output?
uname -a
cat /etc/*-release
RexCore -v
ls -l /rex/rexcore
cat /rex/rexcore/values.txt
Here is my output:
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.9-v7+ #884 SMP Fri May 6 17:28:59 BST 2016 armv7l GNU/Linux
pi@raspberrypi:~ $ cat /etc/*-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~ $ RexCore -v
RexCore version: 2.10.8 revision 5910
pi@raspberrypi:~ $ ls -l /rex/rexcore
total 8
-rw-r--r-- 1 root root 1986 May 19 14:20 exec.rex
-rw-r--r-- 1 root root 1682 May 5 14:15 values.txt
pi@raspberrypi:~ $ cat /rex/rexcore/values.txt
0
0.049979169
0.099833417
0.149438132
...
-0.083089403
-0.033179217
pi@raspberrypi:~ $
Thanks a lot for your cooperation, this is a real mystery...
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
I'm sorry, I should have told that I'm running everything on Windows now until I'm back home again....no RasPi for me the coming two weeks...
Offline
Here's what I get:
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux
pi@raspberrypi:~ $ cat /etc/*-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~ $ RexCore -v
RexCore version: 2.10.8 revision 5910
pi@raspberrypi:~ $ ls -l /rex/rexcore
total 8
-rw-r--r-- 1 root root 1986 May 19 09:52 exec.rex
-rw-r----- 1 root root 0 May 18 17:14 readfile_rexlang.dat
-rw-r----- 1 root root 0 May 18 17:14 readfile_task.REXLANG.dat
-rw-r----- 1 root root 0 May 5 16:17 Rexfile.dat
-rw-r----- 1 root root 0 May 12 10:10 Rexfile.txt
-rw-r----- 1 root root 0 May 5 16:21 Rexlang.dat
-rw-r----- 1 root root 25 May 10 17:50 Rexlang.txt
-rw-r----- 1 root root 0 May 5 17:10 values.txt
pi@raspberrypi:~ $ cat /rex/rexcore/values.txt
cat: /rex/rexcore/values.txt: Permission denied
That last line looks a bit suspicious...
I tried scoobsalamander's 7 with no change.
Last edited by coldh2odvr (2016-05-19 18:08:54)
Offline
Success (or at least a work around). What I know about Linux wouldn't fill the back of a stamp, but I'm learning. Since I couldn't open the text file I searched the web on permissions and changed the permissions on the rex folder so I could read and write. Once I was finally able to open the text files I found they were empty. I thought the new permissions might be all that Rex needed to write the new files but they still came over empty. Finally, I created the files on the rPi directly and the program works like a charm! Cleaned up my original program and, with the locally written lookup table, I can read my pressure gauge.
Gauge -(analog)-> DL250 PLC -(scaled voltage, BCD, TCP/IP)-> DL260 -(modbus)->rPi -(convert from BCD to decimal, read mTorr from lookup table)-> HMI. Pretty convoluted but it works. Now it's time to work on the HMI!
Offline
Hey coldh2odvr,
good to hear that your project is working now! Good work!
As you had difficulties with downloading files to your Raspberry Pi you might find useful tool called WinSCP. However be sure to grant WinSCP root rights (more details about setup root rights to WinSCP).
Good luck with your HMI!
Cheers, Tomas
Offline