Wonderware FileWriteMessage() saving line one and a half times

evanmars

Member
Join Date
Nov 2005
Location
MI
Posts
16
So, I've got this little Condition script:

On True
Code:
string_to_save = datetime + "," + $Operator + "," + "Machine1," + job + "," + part + "," + RealToString(w1) + "," + RealToString(w2) + "," +RealToString(w3)
FileWriteMessage(path, -1, string_to_save, 1)

This will add a line to my .csv file with all the correct parts, but then it saves another line with the $Operator field as "None" and no job or part fields. Not even blank cells, the RealToString() entries are shifted two cells to the left.

So I get something like this for every entry:
2024-11-26 16:15, Bob, Machine1, Acme, Widget, 123.45, 543.21, 152.43
2024-11-26 16:15, None, Machine1, 123.45, 543.21, 152.43

Any ideas why?
 
Any ideas why?
the variable Operator is declared but does not have a defined value (a value assigned to it; yet?). I suspect that, in that environment (Wonderware?), there is a null "constant" called None, which is automatically assigned to variables that declared, but not yet defined.

the solution will be to either ensure a value is a assigned, or detect that the value is None and use a default value in that case (e.g. 'UnknownUser')

Python has a None data type, so in Python you could do it like this:
Code:
string_to_save = datetime + "," + (not (Operator is None)) and Operator or 'UnknownUser' + ...
something similar might be available in WW.
 
the variable Operator is declared but does not have a defined value (a value assigned to it; yet?). I suspect that, in that environment (Wonderware?), there is a null "constant" called None, which is automatically assigned to variables that declared, but not yet defined.

the solution will be to either ensure a value is a assigned, or detect that the value is None and use a default value in that case (e.g. 'UnknownUser')

Python has a None data type, so in Python you could do it like this:
Code:
string_to_save = datetime + "," + (not (Operator is None)) and Operator or 'UnknownUser' + ...
something similar might be available in WW.

$tags in wonderware are predefined read only tags. $Operator is the current user logged in. It should always have a value.

OP, why are you using filewritemessage and artificially injecting commas? Use filewritefields instead and the CSV format is automatic.
 
@drbitboy I realize that. But if you'll notice, I said it prints two lines every time. One with the operator's name ($Operator is a system tag that holds the currently logged in user), and then another line without the user name, but None. And also without the job and part names.

@robertmee I'll give FileWriteFields() a try, but that doesn't (I don't think) give me the answer to why it prints two lines, with the second not having all the data.
 
@drbitboy I realize that. But if you'll notice, I said it prints two lines every time. One with the operator's name ($Operator is a system tag that holds the currently logged in user), and then another line without the user name, but None. And also without the job and part names.

@robertmee I'll give FileWriteFields() a try, but that doesn't (I don't think) give me the answer to why it prints two lines, with the second not having all the data.

Other than you have a typo in your comma after machine1
 
Other than you have a typo in your comma after machine1
I don't think so.
string_to_save is:
2024-11-26 16:15,Bob,Machine1,Acme,Widget,123.45,543.21,152.43

I built the string up by adding commas between tag values, but "Machine1," is a literal. Notice there is no + ',' between "Machine1," and + job
 
I don't think so.
string_to_save is:
2024-11-26 16:15,Bob,Machine1,Acme,Widget,123.45,543.21,152.43

I built the string up by adding commas between tag values, but "Machine1," is a literal. Notice there is no + ',' between "Machine1," and + job

Guess I'm wondering why you didn't include the previous comma then as a single string. ",Machine1'". That threw me.
 
Yeah, could have done that and kept it somewhat consistent. Tomato Tomato
The real typo in my post (not in the actual script) is that it should be StringFromReal() not RealToString(), and I didn't add ; at the end of the statements.

Probably won't be using FileWriteFields(). Not going to name all of the tags the same with just a different number suffix or alias the tags I already have.
I'd have to do something like:
Code:
tag1 = datetime;
tag2 = $Operator;
tag3 = "Machine1";
tag4 = job;
tag5 = part;
tag6 = StringFromReal(w1);
tag7 = StringFromReal(w2);
tag8 = StringFromReal(w3);
FileWriteFields(path, -1, "tag1", 8);

Doesn't seem like it would save me any effort and would just add more tags to the database.
 
Yeah, could have done that and kept it somewhat consistent. Tomato Tomato
The real typo in my post (not in the actual script) is that it should be StringFromReal() not RealToString(), and I didn't add ; at the end of the statements.

Probably won't be using FileWriteFields(). Not going to name all of the tags the same with just a different number suffix or alias the tags I already have.
I'd have to do something like:
Code:
tag1 = datetime;
tag2 = $Operator;
tag3 = "Machine1";
tag4 = job;
tag5 = part;
tag6 = StringFromReal(w1);
tag7 = StringFromReal(w2);
tag8 = StringFromReal(w3);
FileWriteFields(path, -1, "tag1", 8);

Doesn't seem like it would save me any effort and would just add more tags to the database.

Seems if it fixed your problem it would be worth it. Beyond that I would be looking at your condition script, to see if there's a race condition causing it to fire twice.
 
Seems if it fixed your problem it would be worth it.
Fair point.
What's really confusing me, is even if it is some race condition, why is the first line always correct and the second line always reporting $Operator as None and completely missing the job and part fields?

For the moment, I've removed it as a condition script and made it an action script. We'll see how that goes.
 
Fair point.
What's really confusing me, is even if it is some race condition, why is the first line always correct and the second line always reporting $Operator as None and completely missing the job and part fields?

For the moment, I've removed it as a condition script and made it an action script. We'll see how that goes.
If it were any other tag, then I'd say some assignment issue during the write. Some of those tags have null values and why they aren't appearing....job and part. So would focus on where they are getting their values set. Are they memory tags or I/O tags? Any other scripting that is writing to those tags asynchronously to your condition script? A system tag should always have a value in it, and unless you are logging out during this condition script firing, it seems odd that it would be recording None, unless that's the default value of $Operator (don't recall).
 
Even if the tags didn't have values, the commas would still show up with nothing in between. My guess is that there's an earlier version of the write command, that didn't include those fields, that is being executed. Try adding something at the beginning of the line, or right after the DT, and see if it appears on both lines.
 
They are not null. They are I/O tags set in the PLC and never cleared. Just updated with the next batch of parts.
They aren't just not appearing, but there is no field for them. Even if there was no data in them (empty strings) the fields should still be there.
Instead of
| 2024-10-26 16:45 | None | Machine1 | 123.45 | 543.21 | 152.43 |
I should get
| 2024-10-26 16:45 | None | Machine1 | | | 123.45 | 543.21 | 152.43 |

Anyway, I copied the scripts from conditional to action scripts and it seems like it might be working. Notice the last run, I didn't delete the condition script so it ran as well as the action script. I assume the first entry at 12:00 was the action script and the last two were from the condition script.
You'll notice I have 3 machines all saving to this file.

I have now gone through and deleted the condition scripts.
 

Attachments

  • ww.png
    ww.png
    20 KB · Views: 13
Even if the tags didn't have values, the commas would still show up with nothing in between. My guess is that there's an earlier version of the write command, that didn't include those fields, that is being executed. Try adding something at the beginning of the line, or right after the DT, and see if it appears on both lines.
No other version. I just wrote this yesterday. Was nothing like it in the design before.
If I remove the script entirely, nothing gets written. When I put it back in, same problem.

Problem still exists even when it is an action script. Thought that had taken care of it, but nah.
 
Even if the tags didn't have values, the commas would still show up with nothing in between. My guess is that there's an earlier version of the write command, that didn't include those fields, that is being executed. Try adding something at the beginning of the line, or right after the DT, and see if it appears on both lines.

The commas "do show up" as OP is looking at it as a CSV file, and the fields are delimited.
 

Similar Topics

Have a WW v10.1 app running on a Win7 industrial computer. Trying to set up a Win11 backup laptop with a Win7 VM. Wonderware WindowMaker and...
Replies
1
Views
75
Hi guys, I have a Wonderware SCADA project that has a performance issue. The issue is whenever the scada run, it takes a around 10 seconds for the...
Replies
3
Views
95
I don't do Modbus often, but have enough that this should be easy. I have a handful of addresses I need to read from a Modbus TCP device and I'm...
Replies
8
Views
120
Hi all, I am using Wonderware to read Modicon PLC data via the DASMBTCP driver. Recently, I added a few new Boolean tags to Wonderware. However...
Replies
5
Views
133
hi I am working on BOSCH vial washing and filling machine and it controlled by InTouch version 8.0 the industrial pc operating system is windows...
Replies
7
Views
234
Back
Top Bottom