?
Solved

Read from OPCServer

Posted on 2009-12-17
10
Medium Priority
?
203 Views
Last Modified: 2013-11-25
    Hello I have some problem that I want some help with.
I will try to explain.


I read some tags from a OPC-server.
exemple 1:
Operator string [64]
And when I fill upp this string   then I get
item.Key = "Operator"
item.Value.Value = "1234567891234567892123456789312345678941234567789512345678961234" {String}
and when I replace it I get the correct value
1234567891234567892123456789312345678941234567789512345678961234
So if the string is full then I get the  start  "  and the end " 
" value "

But when I do the same with Decca string [64]
And only fill the string some parts in the string
123456789123456789212345678931234
then i get this
item.Value.Value = "123456789123456789212345678931234 {String}
"123456789123456789212345678931234

Only the start " and not the end "    so I gets some problem when I use the value then..  because I don´t get the end "

I only have the problem when I read the "string" tags. When I read the  Real and shorst and other tags theres no problem.

For Each item As KeyValuePair(Of String, OPCItem) In plcValues
            textfile = textfile.Replace("{" & item.Key & "}", item.Value.Value)
        Next


I hope someone understand what I mean can show more info if you want..
Thank you
0
Comment
Question by:kavvis
  • 4
  • 3
  • 3
10 Comments
 
LVL 9

Expert Comment

by:Stephan_Schrandt
ID: 26070102
I've only seen this behaviour in old programs when a string has chr(0) at the end as this marks the end of the variable. Try to get it into a byte array to see what byte is at the end of this string.
0
 
LVL 10

Expert Comment

by:joriszwaenepoel
ID: 26070116
Hi,

Where do you see those " characters?  In Visual Studio, they are added automatically when you look at strings in the watch window for example.  
Maybe the string you get (when not full with actual data) is filled by the the OPC server with other characters that do not display well in Visual Studio (nulls, or linefeeds, or ???).  Can you test the length of the returned string values?  If the length is bigger then what you expect, then you probably need to trim the resulting string by stripping off the extra unnecessary characters.

Hope this helps,

Joris
0
 

Author Comment

by:kavvis
ID: 26070245
I see this charaters in the visual studio yes..
When I look at  "DirectCast(item.Value.Value,System.Object)"  then I se for example on a not fullyfield string this
"123456789123456789212345678931234

And in a totally filled
1234567891234567892123456789312345678941234567789512345678961234

so I think maybe I need to trim away the "sign  

Can this be a idé?

I´m a bit new VB so sorry if I explain very bad.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:Stephan_Schrandt
ID: 26070393
As joris mentioned, the double quotes are not really there, they are only marker for the type 'String'. If you do a item.value.value.Substring(0,1)  then you'll see the first char is 1 and not "
0
 

Author Comment

by:kavvis
ID: 26070431
But in the text filed then I see the in the not fully    "12232434344343
and in the correct one in the text view I see  121334345456566778889823432424242
(but without the  " in the start)

 
0
 
LVL 9

Expert Comment

by:Stephan_Schrandt
ID: 26070477
Please paste the code which you use to retrieve the values. Surely you can replace the " sign with item.value.value.Replace("""","") but this will not explain why this happens.
0
 
LVL 10

Expert Comment

by:joriszwaenepoel
ID: 26070532
Maybe you can try to look at those values using the Trim function:
item.Value.Value.Trim

That will strip off all the whitespace characters from the end of the string, and you will probably see that both strings will be displayed with between " characters (but those are not part of the value).
0
 

Author Comment

by:kavvis
ID: 26071416
Maybe I can explain better with a picutre.

Take a look at this.

These to strings is defined [64] both

And in the first the value I written from the PLC is ollegoop
And in the second I have written  1234567891234567892123456789312345678941234567789512345678961234

There you se       "ollegoop  
and "1234567891234567892123456789312345678941234567789512345678961234"

Thank you all for your help...

fell.JPG
0
 
LVL 10

Accepted Solution

by:
joriszwaenepoel earned 2000 total points
ID: 26071563
I just tested with a string that has null-characters (Chr(0)) appended.
Trim doesn't seems to work as expected, so try the following:

        Dim shortValue as String = item.Value.Value
        If shortValue.Contains(Chr(0)) Then
            shortValue = shortValue.Substring(0, shortValue.IndexOf(Chr(0)))
        End If
        textfile = textfile.Replace("{" & item.Key & "}", shortValue)
0
 

Author Closing Comment

by:kavvis
ID: 31667227
Perfect and fast answears! Thank you very very mutch I works greate!!!!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question