hmi passing messages

For starters im not a programmer. I have worked with c+ a little and am pretty good with PLC's but i dont have any formal training and i really dont know what im talking about. That being said, im working on this HMI by RedLion that is mostly configured visually but also has its own C like language for performing more complicated tasks, but the library is limited. I have this HMI receiving a raw ascii stream of data from a C+ programmed solid state engine control unit. Occasionaly this streaming data is interrupted by a message such as "hydraulic pump low oil". I have this message and all others being parsed correctly but where i stumble is keeping the last message. I want ever new message to bump the last, such as : 1st message becomes second when new arrives,2nd becomes 3rd and on. basically passing the message from one identifier to the next when a new one comes in. here is what i have, i think i know why its wrong but i cant come up with something that works. PLEASE HELP!!


cstring LastMess = input1;
cstring noMess = "No Message";
cstring PrevMess = noMess;
cstring PrevMess1 = noMess;
cstring PrevMess2 = noMess;
cstring PrevMess3 = noMess;


if(PrevMess2 != PrevMess3)
PrevMess3 = PrevMess2;
if(PrevMess1 != PrevMess2)
PrevMess2 = PrevMess1;
if(PrevMess != PrevMess1)
PrevMess1 = PrevMess;
if(LastMess != PrevMess)
PrevMess = LastMess;
Take a look at this, and see if it gives you any ideas:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>

using namespace std;

string noMess = "No Message";
string LastMess = noMess;
string PrevMess = noMess;
string PrevMess1 = noMess;
string PrevMess2 = noMess;
string PrevMess3 = noMess;

void NewMessage(std::string msg) {
		PrevMess3 = PrevMess2;
		PrevMess2 = PrevMess1;
		PrevMess1 = PrevMess;
		PrevMess = LastMess;
		LastMess = msg;
}

void PrintMessage(string label, string msg) {
	cout << label << ": " << msg << endl;
}

void PrintMessages() {
	PrintMessage("LastMess", LastMess);
	PrintMessage("PrevMess", PrevMess);
	PrintMessage("PrevMess1", PrevMess1);
	PrintMessage("PrevMess2", PrevMess2);
	PrintMessage("PrevMess3", PrevMess3);

}

int main (int argc, char* argv[]) {
	for (int i = 1; i < 5; i++) {
		cout << "Round " << i << endl;
		NewMessage("Hello, World!");
		PrintMessages();
	}
	return 0;
}


Note: Line 20 is the end of the important stuff. The rest is just there to make sure it all works.
Last edited on
I actually tried something similar to this but the problem is that i am not able to #include any libraries. i am not actually programing this in C+ but it is C like in syntax. In short this thing is almost as dumb as i am. It doesnt recognise #include or namespace std. The documentation on the website is terrible but if your curious about what im working with its this. Can you think of something even more ridiculously simple than your last example. using if, then type operators?

http://www.redlion.net/Products/HumanMachineInterface/OperatorInterface/G315.html

Im still working what you gave me though, thanks alot.
for example, this code compiles but just passes lastmsg to all other msg.

cstring LastMsg = input1;
cstring NoMsg = "No Message";
cstring Msg0 = NoMsg;
cstring Msg1 = NoMsg;
cstring Msg2 = NoMsg;
cstring Msg3 = NoMsg;


if(Msg3 != Msg2)
Msg3 = Msg2;
if(Msg2 != Msg1)
Msg2 = Msg1;
if(Msg1 != Msg0)
Msg1 = Msg0;
if(Msg0 != LastMsg)
Msg0 = LastMsg;

So the result of the code above means the variables LastMsg, Msg0, Msg1, Msg2, and Msg3 all are the same as input1?
yes, no previous message is kept. input1 is written to all Msg. I want LastMsg to always = input1 but if input 1 changes the old needs to move to msg0.
Last edited on
It sounds to me that when you say

Msg1 = Msg0 what it is really saying is

Copy the MEMORY ADDRESS of Msg0 into Msg1. which means in the end that all variables point to the same memory address, which contains the new value.

And what we want to figure out how to say is:

Copy the CONTENTS of Msg0 into Msg1, and keep the MEMORY ADDRESSes separate.

Perhaps documentation about the language will talk about this? Look for keywords like "Pointer" or "Address" or "Reference"

The subject can also be called "Pass by Reference" vs "Pass by Value"
awesome, sounds exactly like what i was thinking but dont have the vocabulary to say. Ill keep plugging away with the new keywords. Thanks, i hope to have an update soon.
Topic archived. No new replies allowed.