Messages
Sending value between threads
Thread1 code (sending thread):
For sending thread - use simple Messages(SEND_val,...); function to send single value.
Sending Thread
main(){
while(1){
Messages(SEND_val, 115, "script1"); //send any number (in this case - counter number) to Script named script1.
Delay(1000);
}
}
Thread2 code (receiving thread) :
For the receiving thread - use "Messages_received" callback. Also, always use Messages(CLEAN); after you saved the information or completed all of the operations that you wanted to do with your new data.
This needs to be done so that next message could be received.
Reading thread
new sender_name[20]; // max script name length is 20 bytes
new value; // received value;
new str_temp[50];
public callback (event)
{
switch(event)
{
case Messages_received:
{
Read_messages();
}
}
return 0;
}
Read_messages(){
Messages(Message_length, value); //get message length and store it to previously defined variable
Messages(READ_buf, value, str_temp); //read message the size of value and store it to buffer str_temp
write_buf(RS232, value ,str_temp); //do something with received data, in this case we'll just print it via RS232
Messages(CLEAN); //clean message so that next message could be received
}
main(){
Init(RS232, 9600, WORDLENGTH_8, STOPBITS_1, PARITY_NONE);
while(1){
Delay(100);
}
}Sending data array (like a text string) from one thread to another:
Thread1 code (sending thread):
For sending thread - use simple Messages(SEND_buf,...); function to send array of data or a string.
Sending Thread
main(){
while(1){
Messages(SEND_buf, 5, "Hello", "script1); //send any number (in this case - counter number) to Script named script1.
Delay(1000);
}
}
Thread2 code (receiving thread) :
For the receiving thread - use "Messages_received" callback. Also, always use Messages(CLEAN); after you saved the information or completed all of the operations that you wanted to do with your new data.
This needs to be done so that next message could be received.
Receiving Thread
new sender_name[20]; // max script name length is 20 bytes
new value; // received value;
new str_temp[50];
public callback (event)
{
switch(event)
{
case Messages_received:
{
Read_messages();
}
}
return 0;
}
Read_messages(){
Messages(Message_length, value); //get message length and store it to previously defined variable
Messages(READ_buf, value, str_temp); //read message the size of value and store it to buffer str_temp
write_buf(RS232, value ,str_temp); //do something with received data, in this case we'll just print it via RS232
Messages(CLEAN); //clean message so that next message could be received
}
main(){
Init(RS232, 9600, WORDLENGTH_8, STOPBITS_1, PARITY_NONE);
while(1){
Delay(100);
}
}