String from WinCC to PLC

Aleksandra

Member
Join Date
May 2018
Location
Belgrade
Posts
35
Hello everyone,

I am trying to send some data from WinCC to PLC. All types of data work fine, except string data type. I am getting the string value from SQL database (defined as nvarchar(50)) and writing it to PLC tag which I have defined as:

1. Firstly as String[16] - didn't work
2. Then as String[150] - didn't work
3. Then as WString[50] - didn't work
4. Then as WString[150] - didn't work
5. Then as String (which is 255 bytes by default) -> only in this case the string is written from WinCC to PLC

6. I came up with an idea to define Array[1 .. 16] of Char and send character by character in a loop -> this also works

The problem is that I have already made complete programs on the PLC side, and changing the the String[16] data type into any other type would be very, very time consuming because I have been using indirect addressing in a lots of places (client required programming in STL, so....šŸ™ƒ)

I very much hope that someone can tell me why there is a problem with transferring string data types... I have read many forums, and posts, found that other people also had the same problem, but didn't find helpful answers..

Looking forward to hearing from you :)
 
I did a test with WinCC Advanced RT and PLCSIM, and it works fine. Can you post more details, especially the code you are using to copy the varchar to STRING[16] in WinCC?

I am not using neither WinCC Proffesional nor WinCC Advanced, but WinCC v7.3.

After I query the SQL database and save the results in the object record set, I use the code below. In the monitoring mode in PLC I see that all values are transferred except CName and ProcessID, which are strings.

j = 1

Do Until objRecordSet.EOF

ProcessID = objRecordset.Fields(0).Value
StepNo = objRecordset.Fields(1).Value
CNr = objRecordset.Fields(2).Value
CQuantity = objRecordset.Fields(3).Value
CName = objRecordset.Fields(4).Value
DrumNr = objRecordset.Fields(5).Value

HMIRuntime.Tags("g_Orders_Order_" & CStr(j) & "_RecipeID").Write ProcessID
HMIRuntime.Tags("g_Orders_Order_" & CStr(j) & "_StepNo").Write StepNo
HMIRuntime.Tags("g_Orders_Order_" & CStr(j) & "_CNr").Write CNr
HMIRuntime.Tags("g_Orders_Order_" & CStr(j) & "_TargetValue").Write CQuantity
HMIRuntime.Tags("g_Orders_Order_" & CStr(j) & "_CName").Write CName
HMIRuntime.Tags("g_Orders_Order_" & CStr(j) & "_DrumNo").Write DrumNr

j = j + 1
objRecordSet.MoveNext

Loop
 
Oh, wait a second... I didn't pay close attention. You are using NVARCHAR and not VARCHAR. There is a big difference!

nvarchar is for 16-bit characters, and varchar is only for 8-bit characters.

I know about this.. If you defined WString instead of String in the PLC side, than it is 16-bit based. But I have already tried with WString, and it didn't work, so I don't know what could be a problem?
 
Did you make sure your WinCC tag type is "Text tag 16-bit character set"?

I made a simpler program with the following:

SQL Database: nvarchar(50)
S7-1500 DB: Wstring[16]
WinCC Datatype: Text tag 16-bit character set

All I did was this:

HMIRuntime.Tags("teststr").write rst.fields("teststr").value
 
Did you make sure your WinCC tag type is "Text tag 16-bit character set"?

I made a simpler program with the following:

SQL Database: nvarchar(50)
S7-1500 DB: Wstring[16]
WinCC Datatype: Text tag 16-bit character set

All I did was this:

HMIRuntime.Tags("teststr").write rst.fields("teststr").value


I have checked everything, and you can also see it in the attachment. I have no idea what I am missing.

In the first picture you see that first two variables in data block are defined as WString[16], the third one is WString[52], and the forth one is String. In the "Monitor value" tag, you see that only forth value is transferred and that the first three are empty. You also see that optimized block access is turned off.

In the second picture Tag Management is shown, where it is clearly that first three tags are 16-bit character set, and only the last one is not (because it is not WString but String in the PLC side).

In the third picture you data type definition of the column in the SQL database. The fun part is that although the nvarchar is 16-bit character set, it doesn't work with HMI tags 16-bit, but only with the last HMI 8-bit character set tag.

P.S. This info is from the test project, where SQL data is transferred to PLC with the following WinCC 7.3 VB code:

i = 1

Do Until objRecordSet.EOF

HMIRuntime.Tags("Test_DB_CHA_Name0" & CStr(i)).Write objRecordset.Fields(0).Value

i = i + 1

objRecordSet.MoveNext

Loop

o_Oo_Oo_Oo_Oo_O

1_Data block.PNG 2_Tag management.PNG 3_Data type SQL.PNG
 
Last edited:
What is the precise version of WinCC? I am using WinCC V7.3+Upd10. I used absolute addressing in WinCC and not the name: example, DB3,DBB0.

Also what is the version of the database?

** WinCC 7.3 without updates
** SQL Server 2008 10.50.4

I have symbolic addresses in WinCC because I read tags from PLC by reading AS symbols (refer to the attachment). You can also see that I have manually changed the address for the first tag, to be an absolute address, but it doesn't help.

I will now search for update, and if that doesn't help, the last thing that I come up with is to upgrade the version of the SQL Server...

4_Symbolic addressing.PNG
 
What is the collation setting of the database? Mine is Latin1_General_100_CI_AS_KS_WS

Mine is Latin1_General_CI_AS
I will change the collation to be the same as yours and I pray to God that this will solve the problem :geek:
Also will do the WinCC Update, and the column name in the parenthesis of the field propery.
Finger crossed!
 
I just realized something... if you have WinCC V7.3 with no updates, you have to install WinCC V7.3 SE (which is V7.3+Upd1, in reality)from the DVD... which requires uninstalling V7.3 first. I went through this pain long ago.

Try the collation first.
 

Similar Topics

Hi all, I'm trying to connect WinCC Pro to SQL server through OBDC. Everything is okie, I'm able to transfer number, DateTime and even a direct...
Replies
2
Views
1,445
Hi everybody In my program I have five bytes MB10 w#16#62 MB11 w#16#50 MB12 w#16#24 MB13 w#16#10 MB14 w#16#00 I want to show these...
Replies
1
Views
2,568
Hello, I'm having troubles with strings... DB761.DBX16.0 is the offset for a string... in the HMI, this works the way it should, but in the PLC...
Replies
3
Views
2,278
Hello guys, I suffer a problem with KTP 600 DP and CP312C I declare my tag, string: String 1: DB [DB_mux] DBB 626 - string length is 30 chars -...
Replies
1
Views
3,134
I'm trying to write a string of 15 characters from a DB (the variable has type STRING[15]) to an I/O field in WinCC flexible. My problem is that I...
Replies
1
Views
3,730
Back
Top Bottom