tcpWrite

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
Search

Post Reply
5 posts • Page 1 of 1
User avatar
miks
Posts: 6
Joined: Wed Nov 23, 2011 4:02 pm

tcpWrite

Post by miks »

Hi all

It's the first time I have to send some states of pvss datapoints to an external system via a tcp/ip connection using a stream of characters in XML format.
A test master is echoing all received data to a console window.
Generally it is working, I get a connection and the data I sent is displayed at the console window.

But, it looks like I have some problems with string of different length, in some cases strange characters are displayed at the server, like >$³? and others.

I build the string like

Code: Select all

string GetXMLFBFSYSTEM(int idx)
{
string	tmp1, xt;

xt = formatTime("%Y.%m.%d %H:%M:%S", gSystemeZeit[idx]);   //gSystemeZeit ist a dyn_time

tmp1 = "";

return tmp1;
}
and send it simply by using

Code: Select all

sendbuffer = GetXMLFBFSYSTEM(s);                                                //sendbuffer is a string
DebugTN(gVers + ":ThreadWriteData","INFO", sendbuffer);
rc = tcpWrite(gSocket, sendbuffer);
if data has changed.

in PVSS log it looks like:
PVSS00ctrl20:2011.12.13 11:49:47.556["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:47.665["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:47.775["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:47.884["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:47.994["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.103["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.212["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.322["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.431["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.540["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.650["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.759["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.869["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:48.978["1.1X:ThreadWriteData"]["INFO"][""]
PVSS00ctrl20:2011.12.13 11:49:49.087["1.1X:ThreadWriteData"]["INFO"][""]
which looks like expected

the TCP server outputs:
server: [$³?]
server: [$³?]
server: []
server: []
server: []
server: []
server: []
server: []
server: []
server: []
server: []
server: [N"/>]
server: [N"/>]
server: []
server: []
which has some strange characters at the end of some lines

Anyone a idea why this happens and how I can solve the problem?

User avatar
clicht
Posts: 24
Joined: Tue Aug 03, 2010 8:11 am

Re: tcpWrite

Post by clicht »

If you are using "char *" a '\\0' is missing in the char*.

User avatar
miks
Posts: 6
Joined: Wed Nov 23, 2011 4:02 pm

Re: tcpWrite

Post by miks »

Thanks for your reply.

I'm not complete shure what you mean but I changed the code of the GetXMLFBFSYSTEM function like this:

Code: Select all

string GetXMLFBFSYSTEM(int idx)
{
	string	tmp1, xt;

	xt = formatTime("%Y.%m.%d %H:%M:%S", gSystemeZeit[idx]);

	tmp1 = "";
	tmp1 = tmp1 + "\\0";

	return tmp1;
}

but the problem still remains :dry:
like described in my starting post the transmitted strings with lower amount of characters got strange characters at the end
(please have a look at row 1,2,12 and 13)

User avatar
leoknipp
Posts: 2926
Joined: Tue Aug 24, 2010 7:28 pm

Re: tcpWrite

Post by leoknipp »

Hello Mr. Schweitzer,

for further progress concerning this issue please refer to the common WinCC OA support, mailto:support.automation@siemens.com.
At the topic of the mail please write which WinCC OA-version you are using.

Please notice that the ETM Portal does not substitute the common WinCC OA support.

Best Regards
Leopold Knipp
Senior Support Specialist

User avatar
aorange
Posts: 147
Joined: Thu Nov 04, 2010 10:07 am

Re: tcpWrite

Post by aorange »

Hi Michael,

Welcome to the forum, the only thing that springs to mind is that you are not terminating the string that you are sending using tcpWrite()

For example, I had to build a couple of functions to send SOAP XML messages to a web-service and since only XML-RPC is supported in WinCC-OA, I ended up building and sending everything as TCP packtets.

Code: Select all

string strRequest;
string strHeader;
strRequest  = "POST  ........... \\r\\n";
strHeader  += "Host: ......... \\r\\n";
strHeader  += "Authorization: ..... \\r\\n"; // Base64 encoding
strHeader  += "Content-Type: text/xml; charset=utf-8\\r\\n";
strHeader  += "Content-Length:" + ........ + "\\r\\n";
strHeader  += "SOAPAction: .............. \\r\\n";
strHeader  += "\\r\\n";
Also, I would suggest that you build the XML message using xmlNewDocument() instead of concatenating a very long string, it becomes easier to manage.

For example:

Code: Select all

int node;
int parent;
xmlDoc = xmlNewDocument();
  
node = xmlAppendChild(xmlDoc, -1, XML_PROCESSING_INSTRUCTION_NODE, "xml version=\\"1.0\\" encoding=\\"UTF-8\\"");
node = xmlAppendChild(xmlDoc, -1, XML_ELEMENT_NODE, "soap:Envelope");
  
xmlSetElementAttribute(xmlDoc, node, "xmlns:soap", "http://www.w3.org/2003/05/soap-envelope");
xmlSetElementAttribute(xmlDoc, node, "xmlns:xsi",  "http://www.w3.org/2001/XMLSchema-instance");
xmlSetElementAttribute(xmlDoc, node, "xmlns:xsd",  "http://www.w3.org/2001/XMLSchema");

node = xmlAppendChild(xmlDoc, node, XML_ELEMENT_NODE, "soap:Body");
node = xmlAppendChild(xmlDoc, node, XML_ELEMENT_NODE, "StartOptimisation");
  
xmlSetElementAttribute(xmlDoc, node, "xmlns", "http://tynemarch.co.uk/org");
All you need to do then is:

Code: Select all

tcpWrite(intTcpPort, strRequest + strHeader + xmlDocumentToString(xmlDoc));

Post Reply
5 posts • Page 1 of 1