You are not logged in.
Pages: 1
Topic closed
I need more than 16 outputs in the REXLANG function block and I was wondering if I could multiplex all internal values into a vector and assign it to an output. Then a VTOR can be used to demultiplex the vector again into separate values......
If possible then what syntax should be used inside the REXLANG FB?
Maybe an example...? :-)
Offline
Hey scoobsalamander,
thank you for your tricky question
Unfortunately, it is not possible to use a vector as a REXLANG output.
However it is possible to split range of all the outputs if you don't need the full 32b range. Therefore you can use up to 16x32b = 512 binary outputs with one REXLANG block
Please, see the basic example on how to pass two 16b numbers through one 32b REXLANG output:
REXLANG_MultiOutput.zip
Hope that it will solve your issue.
Regards, Tomas
Last edited by tomáš čechura (2016-04-06 09:31:41)
Offline
The problem is that I have +30 signals coming in from various wireless sensors (Jeenode) all over the house. These sensors are sending packages (RFM12B 868Mhz) to a monitoring node (Nanode RF)
This board uses the JeeUDP program (to be found in the Jeelib library) to send all received packages over ethernet (UDP) to my RasPi (REXcontrols)
I tried using multiple REXLANG function blocks but somehow only one is working, I guess it is not possible to use several REXLANG FB's who are listening to the same port for UDP packages.... This makes that I have now only one working block with only 16 outputs......
(in the future I might change over to a JeeLink which can be put directly onto one of the USB ports of the RasPi.....)
Offline
You are right that it is not possible to use more REXLANGs listening to the same port. Eventually, there is a workaround. You can use UDP communication between two REXLANGs on localhost (and with different listening port) and forward the data from "master" REXLANG (which is listening to your UDP port with JeeUDP) to the "slave" one.
Do you really need full 32b range for all the 16 outputs? The solution with more outputs "emulated" on one output signal would be much more convenient from my point of view.
Regards, Tomas
Offline
....forgot to mention that all those signals are from the double type :-)
Offline
This master-slave thing could work...maybe I can sort the incoming messages into different streams depending on their address/function with the switch-case functionality.....although I think at the end it will be better to buy the Jeelink and by-pass all this UDP stuff....but then I will need to use the REXLANG FB again for the serial communication and I will be stuck again with this bottleneck of 16 outputs.
Last edited by scoobsalamander (2016-04-06 08:57:15)
Offline
In the new version of REX, it will be possible to write from REXLANG to parameters of other blocks (e.g. CNR, PARR, etc.) outside the REXLANG function block. So you will be able to operate with more than the native 16 outputs of REXLANG.
Beta version of the new release will be available soon
Offline
Nice to hear! Thanks for the support and for the constant developing......
Offline
The solution with the localhost UDP connection is working fine.
By means of a switch statement I'll check for the node address (which is a part of the received message) and if it is not assigned to that particular REXLANG FB then the buffer will be passed to the following block by an internal UDP link until the corresponding block is found where it will be send to the output. (can be daisy chained....)
Thx for the hint.....
/*******************************************************
* *
* REXLANG - data exchange via UDP protocol *
* *
* (c) REX Controls, www.rexcontrols.com *
* *
*******************************************************/
#define CON_UDP 64 //internal constant for UDP communication
#define RECEIVER_IP 0xC0A8B236 //192.168.178.54 - REXControl RasPi
#define SENDER_IP 0xC0A8B21F //192.168.178.31 - Nanode RF (message relay board)
#define senderPort 23456
#define receiverPort 4001
#define nextRexlangPort 4003 //port on next rexlang block
#define BUFFER_SIZE 80 //maximum number of bytes to receive
//assigning variables to outputs
//SENSOR NODE 11 :
double output(0) signal0; //battery voltage
double output(1) signal1; //room temperature
double output(2) signal2; //room humidity
double output(3) signal3; //counter
//SENSOR NODE 12 :
double output(4) signal4; //battery voltage
double output(5) signal5; //room temperature
double output(6) signal6; //room humidity
double output(7) signal7; //counter
//SENSOR NODE 10 :
double output(8) signal8; //Power 1
double output(9) signal9; //Power 2
double output(10) signal10; //Power 3
double output(11) signal11; //Vrms
//SENSOR NODE 13 :
double output(12) signal12; //battery voltage
double output(13) signal13; //room temperature
double output(14) signal14; //room humidity
double output(15) signal15; //counter
//declaration of variables
long hRecvLoc; //socket handle
long buffer[BUFFER_SIZE]; //buffer for incoming data
long dataCnt; //number of received bytes
long sendDataCnt;
long convData[2]; //array for data conversions
double node;
long hSendLoc;
long sendBuffer(long rexlangPort)
{
if (hSendLoc<0)
{
hSendLoc = Open(CON_UDP,0x7F000001,4002,0x7F000001,rexlangPort); //opening UDP socket- localhost
}
else
{
sendDataCnt = Send(hSendLoc,buffer,BUFFER_SIZE); //send data
signal6 = hSendLoc;
}
return 0;
}
/* Initialization of the REXLANG algorithm */
// the init procedure is executed once when the REXLANG function block initializes
long init(void)
{
hRecvLoc = -1;
hSendLoc = -1;
dataCnt = 0;
sendDataCnt = 0;
return 0;
}
/* The body of REXLANG algorithm */
// the main procedure is executed once in each sampling period
long main(void)
{
long i;
if (hRecvLoc<0)
{
hRecvLoc = Open(CON_UDP,RECEIVER_IP,receiverPort,SENDER_IP,senderPort); //opening UDP socket
}
else
{
//receive the data
dataCnt = Recv(hRecvLoc,buffer,BUFFER_SIZE); //receive data, max number of bytes = BUFFER_SIZE
node = (((buffer[43]-48)*10)+((buffer[44]-48))); //node number is in ASCII format
//signal3 = node;
switch(node)
{
case 11: //Node 11
signal0 = buffer[60] ; //Battery voltage
signal0 = signal0/100;
signal1 = buffer[58]<<16 | buffer[59]<<24; //Room temperature SHT22
signal1 = signal1/1048576; //divide by (256*256*100)
//signal2 = not used
//signal2 = not used
signal3 = buffer[54] | buffer[55]<<8 | buffer[56]<<16 | buffer[57]<<24; //Message counter
break;
case 12: //Node 12
signal4 = buffer[60] ; //Battery voltage
signal4 = signal4/100;
signal5 = buffer[58]<<16 | buffer[59]<<24; //Room temperature SHT22
signal5 = signal5/1048576; //divide by (256*256*100)
//signal6 = not used
//signal6 = not used
signal7 = buffer[54] | buffer[55]<<8 | buffer[56]<<16 | buffer[57]<<24; //Message counter
break;
case 13: //Node 13
signal12 = buffer[63] ; //Battery voltage
signal12 = signal12/100;
signal13 = buffer[59]<<16 | buffer[60]<<24; //Room temperature SHT22
signal13 = signal13/6553600; //divide by (256*256*100)
signal14 = buffer[61]<<16 | buffer[62]<<24; //Room humidity SHT22
signal14 = signal14/6553600; //divide by (256*256*100)
signal15 = buffer[55] | buffer[56]<<8 | buffer[57]<<16 | buffer[58]<<24; //Message counter
break;
case 10: //Node 10
signal8 = buffer[55]<<16 | buffer[56]<<24; //Power 1
signal8 = signal8/65536; //divide by (256*256)
signal9 = buffer[57]<<16 | buffer[58]<<24; //Power 2
signal9 = signal9/65536; //divide by (256*256)
signal10 = buffer[59]<<16 | buffer[60]<<24; //Power 3
signal10 = signal10/65536; //divide by (256*256)
signal11 = buffer[61]<<16 | buffer[62]<<24; //Vrms
signal11 = signal11/6553600; //divide by (256*256*100)
break;
default:
sendBuffer(nextRexlangPort);
}
}
return 0;
}
/* Closing the REXLANG algorithm */
//the exit procedure is executed once when the task is correctly terminated
// (system shutdown, downloading new control algorithm, etc.)
long exit(void)
{
if(hRecvLoc>=0) Close(hRecvLoc);
return 0;
}
Last edited by scoobsalamander (2016-04-07 00:27:43)
Offline
Good to hear!
Thank you for your feedback and sharing your code. Nice piece of work
Cheers, Tomas
Offline
Pages: 1
Topic closed