How to set I/O values in siemens PLC Device? - c#

I am creating a Web API for a local network in the .net framework(C#). In that user can import/export IO Tags from excel or set them as a static string array. I have added (Siemens.Engineering.Hmi.dll) but still, it shows a not found compile-time error.
We have also connected to TIAPortal and it works well the only roadblocks are I/O tags import/export or set static values and HMISoftware.
Project: Web API(.Net Framework 4.6.1)
Tia Portal: v16.0
License Type: Trial
Kindly revert me if anyone have idea or any suggestion. It would be highly appriciated.

The issue you are experiencing is that (most probably) you didn't set the copy local property of the referenced Siemens.Engineering.Hmi.dll to false. So, the dependencies of the referenced Siemens.Engineering.Hmi.dll cannot be found. As a remark: add the Siemens.Engineering.dll as a reference besides Siemens.Engineering.Hmi.dll
Having a not-local-assembly then requires AssemblyResolving. The simplest way of doing it is to use the App.config file.
Please see this page from Siemens about this topic:
support.industry.siemens.com
The second issue I see is the access of Tags. As you most certainly know, there are HMI Tags and PLC Tags. Accessing them is possible through the respective DeviceItems. These DeviceItems expose different Services. You can access the Services through the <YourEngineeringObject>.GetService<T>() method. In this case you will need the SoftwareContainer service.
To become familiar with the data model of TIA Openness, please have a look at the TIA Openness Explorer
Also, to deepen your understanding of working with TIA Openness, please refer to SIMATIC TIA Portal Openness: API for automation of engineering workflows

The solution I'm importing IO tags is to use .xml files
Its advantage is that it can access and set the properties of IO tags, such as IO tagstable's name, datatypename, externalaccessible, externalvisible, externalwritable, logicaladdress, tagName, comment.
For Example .xml
<?xml version="1.0" encoding="utf-8"?>
<Document>
<Engineering version="V16" />
<SW.Tags.PlcTagTable ID="0">
<AttributeList>
<Name>IO Table</Name>
</AttributeList>
<ObjectList>
<SW.Tags.PlcTag ID="1" CompositionName="Tags">
<AttributeList>
<DataTypeName>Bool</DataTypeName>
<ExternalAccessible>true</ExternalAccessible>
<ExternalVisible>true</ExternalVisible>
<ExternalWritable>true</ExternalWritable>
<LogicalAddress>%I0.0</LogicalAddress>
<Name>Tag</Name>
</AttributeList>
<ObjectList>
<MultilingualText ID="2" CompositionName="Comment">
<ObjectList>
<MultilingualTextItem ID="3" CompositionName="Items">
<AttributeList>
<Culture>en-US</Culture>
<Text>Tag</Text>
</AttributeList>
</MultilingualTextItem>
</ObjectList>
</MultilingualText>
</ObjectList>
</SW.Tags.PlcTag>
</ObjectList>
</SW.Tags.PlcTagTable>
</Document>
You only need to modify the tags attribute in. XML, including the ID value. For example, first tag ID = 1, and the second tag ID = 2.ID's value is not repeatable!
For Example .cs
var fileInfo = new FileInfo(#"IO MAP.xml");
SoftwareContainer softwareContainer = Project.Devices[0].DeviceItems[1].GetService<SoftwareContainer>();
Software softwareBase = softwareContainer.Software;
PlcSoftware plcSoftware = softwareBase as PlcSoftware;
PlcTagTableGroup PlcTagTableGroup = plcSoftware.TagTableGroup;
PlcTagTableGroup.TagTables.Import(fileInfo, ImportOptions.Override);
You only need to modify the target of SoftwareContainer , which depends on the PLC model you use, in the case of s7-1516.
If you have any questions, please contact me。

Related

Creating XML Banking document from template

I have this template from a bank that is used to make payments on bank account transfers.
See xml below. I have included the sample data that has to be entered when sending the file to the bank.
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CstmrCdtTrfInitn>
<GrpHdr>
<MsgId>Cart Urgent28052018_57894</MsgId>
<CreDtTm>2018-06-29T11:52:23</CreDtTm>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>667896.00</CtrlSum>
<InitgPty>
<Nm>CART LIMITED</Nm>
<Id>
<OrgId>
<Othr>
<Id>S001234/PJones</Id>
<SchmeNm>
<Cd>CUST</Cd>
</SchmeNm>
</Othr>
</OrgId>
</Id>
</InitgPty>
</GrpHdr>
<PmtInf>
<PmtInfId>Payment for addon development SAP B1</PmtInfId>
<PmtMtd>TRF</PmtMtd>
<BtchBookg>false</BtchBookg>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>667896.00</CtrlSum>
<PmtTpInf>
<InstrPrty>HIGH</InstrPrty>
</PmtTpInf>
<ReqdExctnDt>2018-06-29</ReqdExctnDt>
<Dbtr>
<Nm>CART LIMITED</Nm>
</Dbtr>
<DbtrAcct>
<Id>
<Othr>
<Id>0112345110846</Id>
</Othr>
</Id>
<Ccy>KES</Ccy>
</DbtrAcct>
<DbtrAgt>
<FinInstnId>
<BIC>SBICKENX</BIC>
</FinInstnId>
</DbtrAgt>
<CdtTrfTxInf>
<PmtId>
<EndToEndId>156335578965</EndToEndId>
</PmtId>
<Amt>
<InstdAmt Ccy="KES">667896.00</InstdAmt>
</Amt>
<ChrgBr>DEBT</ChrgBr>
<CdtrAgt>
<FinInstnId>
<BIC>DTKEKENA</BIC>
<ClrSysMmbId>
<MmbId>63000</MmbId>
</ClrSysMmbId>
</FinInstnId>
</CdtrAgt>
<Cdtr>
<Nm>EOH SEAL LTD</Nm>
<PstlAdr>
<StrtNm>P.O. Box 10496</StrtNm>
<TwnNm>Nairobi</TwnNm>
<Ctry>KE</Ctry>
<AdrLine>P.O. Box 10496</AdrLine>
<AdrLine>00100 NAIROBI</AdrLine>
</PstlAdr>
</Cdtr>
<CdtrAcct>
<Id>
<Othr>
<Id>0112406001</Id>
</Othr>
</Id>
</CdtrAcct>
<RmtInf>
<Ustrd>Cart Urgent28052018_57894</Ustrd>
</RmtInf>
</CdtTrfTxInf>
</PmtInf>
</CstmrCdtTrfInitn>
</Document>
The file is quite long as has to be in the format given. The black letters represent the details to be passed to the xml. To test if I understood what data goes where I filled it manually and sent to bank for testing. That is all good now.
I have a SAP addon program that captures details from a form and generates a list. Each payment must follow this structure.
Looking at the below:
<Nm>CART LIMITED</Nm>
<Id>
<OrgId>
<Othr>
<Id>S001234/PJones</Id>
<SchmeNm>
<Cd>CUST</Cd>
</SchmeNm>
</Othr>
</OrgId>
</Id>
Is creating a class with all properties according to the template the best way to create the xml needed.
How do I stagger the
<Id>
<OrgId>
<Othr>
as in the case above?
Also the <CtrlSum>667896.00</CtrlSum> is found in the group header and payment info tags. How do I deal with this?
For what i see, the problem is you have a addon in SAP to specify multiple payments methods, but in the XML template given from the bank you don't the structure for multiple payments, so you need to get this information to know how can you work with it.
when you have this information you can use a better XML template with VS or another tool to generate the correct class to work with the XML

How to add a customer with custom fields to Quickbooks POS using QBPOSXML

So my problem is pretty simple: I am trying to add a customer to Quickbooks using ASP.NET and QBWebConnector, and thankfully I am succeeding. The problem occurs when I try to add custom fields to the customer.
Here's the qbposxml I am sending:
<?xml version="1.0" encoding="UTF-8"?>
<?qbposxml version="3.0"?>
<QBPOSXML>
<QBPOSXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="1">
<CustomerAdd>
<Salutation>Mr.</Salutation>
<FirstName>Ammar</FirstName>
<LastName>Ahmed</LastName>
<BillAddress>
<Street>asascc, asdas</Street>
</BillAddress>
<Phone>03321221221</Phone>
</CustomerAdd>
</CustomerAddRq>
<DataExtModRq>
<DataExtMod>
<OwnerID>0</OwnerID>
<DataExtName>IDNumber</DataExtName>
<ListDataExtType>Customer</ListDataExtType>
<ListObjRef>
<FullName>Ammar Ahmed</FullName>
</ListObjRef>
<DataExtValue>12331</DataExtValue>
</DataExtMod>
</DataExtModRq>
<DataExtModRq>
<DataExtMod>
<OwnerID>0</OwnerID>
<DataExtName>GebDatum</DataExtName>
<ListDataExtType>Customer</ListDataExtType>
<ListObjRef>
<FullName>Ammar Ahmed</FullName>
</ListObjRef>
<DataExtValue>21/22/12</DataExtValue>
</DataExtMod>
</DataExtModRq>
</QBPOSXMLMsgsRq>
</QBPOSXML>
Now the response I get is this:
<?xml version="1.0" encoding="UTF-8"?>
<QBPOSXML>
<QBPOSXMLMsgsRs>
<CustomerAddRs requestID="1" statusCode="0" statusMessage="Status OK" statusSeverity="Info">
<CustomerRet>
<ListID>755269278256496897</ListID>
<TimeModified>2017-03-08T14:00:42+05:00</TimeModified>
<AccountBalance>0.00</AccountBalance>
<AccountLimit>0.00</AccountLimit>
<CustomerDiscPercent>0.00</CustomerDiscPercent>
<CustomerDiscType>None</CustomerDiscType>
<FirstName>Ammar</FirstName>
<FullName>Mr. Ammar Ahmed</FullName>
<IsAcceptingChecks>True</IsAcceptingChecks>
<IsUsingWithQB>False</IsUsingWithQB>
<LastName>Ahmed</LastName>
<Phone>03321221221</Phone>
<PriceLevelNumber>1</PriceLevelNumber>
<Salutation>Mr.</Salutation>
<StoreExchangeStatus>Modified</StoreExchangeStatus>
<BillAddress>
<Street>asascc, asdas</Street>
</BillAddress>
</CustomerRet>
</CustomerAddRs>
<DataExtModRs statusCode="20036" statusMessage="Extension error (ListID is missing)" statusSeverity="Error">
<DataExtRet />
</DataExtModRs>
</QBPOSXMLMsgsRs>
</QBPOSXML>
I don't know how to get the ListID of the customer I am adding since it is created after the customer is added.
Thing to note: Customer is added but without custom fields. From this and this I gathered that I didn't need ListID.
Any help would be highly appreciated.
Update:
So after the answer by William Lorfing, I checked out Chapter 6 of QBPOS Programmer's Guide and discovered macros. Here's how I ended up using them, with outstanding results:
My CustomerAdd Request became:
<?xml version="1.0" encoding="UTF-8"?>
<?qbposxml version="3.0"?>
<QBPOSXML>
<QBPOSXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="1">
<CustomerAdd defMacro="ListID:Cust1"> NOTICE THE INITIALIZATION OF MACRO!
<Salutation>Mr.</Salutation>
<FirstName>Ammar</FirstName>
<LastName>Ahmed</LastName>
<BillAddress>
<Street>asascc, asdas</Street>
</BillAddress>
<Phone>03321221221</Phone>
</CustomerAdd>
</CustomerAddRq>
<DataExtModRq>
<DataExtMod>
<OwnerID>0</OwnerID>
<DataExtName>IDNumber</DataExtName>
<ListDataExtType>Customer</ListDataExtType>
<ListObjRef>
<ListID useMacro="ListID:Cust1" /> NOTICE THE USE OF MACRO!
</ListObjRef>
<DataExtValue>12331</DataExtValue>
</DataExtMod>
</DataExtModRq>
<DataExtModRq>
<DataExtMod>
<OwnerID>0</OwnerID>
<DataExtName>GebDatum</DataExtName>
<ListDataExtType>Customer</ListDataExtType>
<ListObjRef>
<ListID useMacro="ListID:Cust1" /> NOTICE THE USE OF MACRO!
</ListObjRef>
<DataExtValue>21/22/12</DataExtValue>
</DataExtMod>
</DataExtModRq>
</QBPOSXMLMsgsRq>
</QBPOSXML>
First we initialize the macro and then we use it, thus avoiding additional request and don't know how many lines of useless code just to add custom fields.
Thanks William Lorfing for the hint in the right direction.
For QBPOS SDK, ListObjRef required ListID and not fullname.
You will either have to do the customeradd and then in the next request do the DataExtAdd with the ListID or you can try using Macros. See Chapter 6 of the POS SDK Programmers Guide.
The guide is included in the POS SDK.

QuickFIX counterparty DataDictionary gieves invalid type exception

I am developing a FIX4.4 messaging application in C# and trying to use a counterparty provided data dictionary. In the project I use QuickFIX as a library, and when using the original dictionary provided within the library (FIX44.xml) everything works fine.
However, using such dictionary causes some rejections which, according to the counterparty, should disappear once I switch to their own data dictionary.
Now, when I do that I get the following exception of type 'QuickFix.DictionaryParseException':
"invalid type: TENOR"
Below is my config file, if it might help...
[DEFAULT]
ConnectionType=initiator
ReconnectInterval=20
FileStorePath=store
FileLogPath=log
StartTime=07:00:00
EndTime=00:00:00
UseDataDictionary=Y
ValidateFieldsHaveValues=N
ValidateFieldsOutOfOrder=N
ValidateUserDefinedFields=N
AllowUnknownMsgFields=Y
# DataDictionary=P:\...\FixSource\bin\spec\fix\FIX44.xml
#HttpAcceptPort=0000
[SESSION]
# inherit ConnectionType, ReconnectInterval and SenderCompID from default
BeginString=FIX.4.4
ResetOnLogon=Y
SenderCompID=MyID
TargetCompID=MyCPID
SocketConnectHost=xxx
# SocketConnectHost=yyy
SocketConnectPort=000
HeartBtInt=30
DataDictionary=P:\...\MyCounterpartyDataDictionary.xml
Also, the line that causes the issue in the DD xml is the following:
<field number="6215" name="Tenor" type="TENOR"/>
and another two lines that give the same exception type turned out to be:
<field number="41135" name="OptionExerciseLatestTime" type="LOCALMKTTIME"/>
<field number="41510" name="LegOptionExerciseLatestTime" type="LOCALMKTTIME"/>
Thanks a lot for your help,
GPP
Your problem is the Tenor FIX datatype was not introduced until FIX 4.4 EP-1
http://fixwiki.org/fixwiki/TenorDataType
Apparently the quick and dirty solution is the one suggested by Grant i.e. using the string type, it works. Thanks for that.

Preparing XSD of a complex xml

Thank you all for suggesting things and helping whenever in need.
Yesterday I was trying to develop and web app in asp.net 4.0 where I needed to parse the data from xml and save it in database. But before that I will also have to validate it.
I tried using .net provided tool xsd.exe to generate the schema file, but I dont know how will it know to mark which nodes or attributes are compulsory?
Like in my xml below items are mandatory
Root node <Market>
<Login> and its sub element
<ProductType> and its <ProductTypeID/>
The attribute DML is mandatory but should have only 3 values NONE, PUT or MODIFY
<ProductType> may or may not have <ProductItem>
If <ProductItem> is present then it should have <ProductItemID>
<ProductItem> may or may not have <Brand>
If <Brand> is present then it should have <BrandID>
Below is my xml
<?xml version="1.0" encoding="utf-8" ?>
<Market>
<Login>
<LoginId />
<Password />
</Login>
<ProductType DML="NONE">
<ProductTypeID/>
<Name/>
<Detail/>
<ProductItem DML="PUT">
<ProductItemID/>
<Name/>
<Detail/>
<Brand DML="PUT">
<BrandID/>
<Name/>
<Detail/>
</Brand>
<Brand DML="MODIFY">
<BrandID/>
<Name/>
<Detail/>
</Brand>
</ProductItem>
<ProductItem DML="MODIFY">
<ProductItemID/>
<Name/>
<Detail/>
</ProductItem>
</ProductType>
</Market>
How and where should I specify all the mandatory and optional parameters, so that my xsd is generated as per the requirement.
Thanks,
M.
xsd.exe can only try to infer, which elements/attributes are in you xml, but it cannot find out which information is mandatory. But this is a good startingpoint.
use a graphical XML_Schema_Editor to edit the genrated xsd to mark your mandatory fields. That is much easier than learning the xsd-language
I don't think XSD support nested XML. I would try to load the XML into an XmlDocument and check mandatory fields manually.

Pivotviewer's .cxml parsing

I'm trying to do very simple operations on a .cxml file. As you know it's basically an .xml file. This is a sample file I created to test the application:
<?xml version="1.0" encoding="utf-8"?>
<Collection xmlns:p="http://schemas.microsoft.com/livelabs/pivot/collection/2009" SchemaVersion="1.0" Name="Actresses" xmlns="http://schemas.microsoft.com/collection/metadata/2009">
<FacetCategories>
<FacetCategory Name="Nationality" Type="LongString" p:IsFilterVisible="true" p:IsWordWheelVisible="true" p:IsMetaDataVisible="true" />
</FacetCategories>
<!-- Other entries-->
<Items ImgBase="Actresses_files\go144bwo.0ao.xml" HrefBase="http://www.imdb.com/name/">
<Item Id="2" Img="#2" Name="Anna Karina" Href="nm0439344/">
<Description> She is a nice girl</Description>
<Facets>
<Facet Name="Nationality">
<LongString Value="Danish" />
</Facet>
</Facets>
</Item>
</Items>
<!-- Other entries-->
</Collection>
I can't get any functioning simple code like:
XDocument document = XDocument.Parse(e.Result);
foreach (XElement x in document.Descendants("Item"))
{
...
}
The test on a generic xml is working. The cxml file is correctly loaded in document.
While watching the expression:
document.Descendants("Item"), results
the answer is:
Empty "Enumeration yielded no results" string
Any hint on what can be the error? I've also add a quick look to get Descendants of Facet, Facets, etc., but there are no results in the enumeration. This obviously doesn't happen with a generic xml file I used for testing. It's a problem I have with .cxml.
Basically your XML defines a default namespace with the xmlns="http://schemas.microsoft.com/collection/metadata/2009" attribute:
That means you need to fully qualify your Descendants query e.g.:
XDocument document = XDocument.Parse(e.Result);
foreach (XElement x in document.Descendants("{http://schemas.microsoft.com/collection/metadata/2009}Item"))
{
...
}
If you remove the default namespace from the XML your code actually works as-is, but that is not the aim of the exercise.
See Metadata.CXML project under http://github.com/Zoomicon/Metadata.CXML sourcecode for LINQ-based parsing of CXML files.
Also see ClipFlair.Metadata project at http://github.com/Zoomicon/ClipFlair.Metadata for parsing one's CXML custom facets too
BTW, at http://ClipFlair.codeplex.com can checkout the ClipFlair.Gallery project for how to author ASP.net web-based forms to edit metadata fragments (parts of CXML files) and merge them together in a single one (that you then convert periodically to DeepZoom CXML with PAuthor tool from http://pauthor.codeplex.com).
If anyone is interested in doing nesting (hierarchy) of CXML collections see
http://github.com/Zoomicon/Trafilm.Metadata
and
http://github.com/Zoomicon/Trafilm.Gallery

Categories

Resources