9 Replies - 4148 Views - Last Post: 13 September 2015 - 02:10 PM Rate Topic: -----

#1 SilverFoil   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-September 15

Need help starting with C# and IEC60870-5-104

Posted 12 September 2015 - 03:06 PM

Hi,

I've been assigned the task of writing a client program that takes some data and transmits it via ethernet using the protocol IEC 60870-5-104. I've been told to use C# and .net to do this. The problem is that my background is in electronics, not computer networks, so while I am familiar with the general concepts involved I'm not very clear on the details. I'm hoping someone here could indicate where I should begin or clarify exactly what the task is.

The issues that I'm struggling with, in no particular order and intermingling to some extent:

According to the pdf I was handed, IEC 60870-5-104 is an "application protocol", which is distinct from TCP? Does one replace the other, or does IEC 60870-5-104 exist 'inside' TCP?

I've had a look at the C# language (which I wasn't familiar with before) and found the 'Socket' command. This, so far as I can tell (please correct me if I'm wrong) includes one parameter "ProtocolType.TCP" and the command "Connect". Would this take care of the handshaking/connection establishing part, or would I have to code for that myself?

What information should I be looking for in the pdf that describes IEC 60870-5-104? The description seems very thorough and unambiguous, which is good in general but makes it difficult for someone without much of the relevant education to pick out what I need to know over what I can safely ignore.

Am I even vaguely on the right track? I've been trying to find the answers to these questions online, but my google-fu seems to have failed me in this case. Either that or what I'm trying to find is so monumentally wrong that nobody else has ever tried to find out.

I'll be very grateful for any help that could be provided.

Is This A Good Question/Topic? 0
  • +

Replies To: Need help starting with C# and IEC60870-5-104

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Need help starting with C# and IEC60870-5-104

Posted 12 September 2015 - 03:22 PM

Quote

I've had a look at the C# language (which I wasn't familiar with before) and found the 'Socket' command.


I'm sorry you've been handed something that is outside of your skillset. It always sucks when this happens. That being said, I'm going to strongly urge you ask your boss to re-assign this to a developer. Clearly this is meant to be production code and not some pidly learning exercise. The simple fact is that you can't just walk up to C# with no experience and write a production level program by Googling then copy/pasting some stuff you find. If it were that easy then folks like us that earn a living doing this wouldn't be needed: Would we?

The simple fact is if you spent the next year learning C#, WPF, MVVM - 40 hours a week, full time as your job - Then maybe at the end of that year you might be ready to build this correctly. Sorry if that's not what you wanted to hear, but to paraphrase the immortal Chief Engineer Scott "I canno change the laws of programming."


My standard beginner resources post - Updated June 2013


Plan your study route:
There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

  • First learn the language by working 2-5 "Learn C# in 30 days" type books cover to cover.
  • Do a dozen on-line tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.
  • Learn to plan before you type.
  • THEN you start designing software with a purpose.



I don't learn from reading books: I learn by doing.
Spoiler


Newbie/Rookie said:

I have little/no programming experience but I need to write a program by Friday that does XYZ.
Spoiler



Resources, references and suggestions for new programmers.
Spoiler

Was This Post Helpful? 1
  • +
  • -

#3 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Need help starting with C# and IEC60870-5-104

Posted 12 September 2015 - 11:00 PM

IEC60870-5-104 is an application layer protocol (layer 7 or the ISO/OSI 7 layer model) which runs over a TCP/IP network
http://www.ipcomm.de...4/en/sheet.html

if you do a web seach for IEC60870-5-104 code you will find useful links
however, this is not a simple task if you have little or no experience of implemention communication protocols

This post has been edited by horace: 12 September 2015 - 11:01 PM

Was This Post Helpful? 1
  • +
  • -

#4 SilverFoil   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-September 15

Re: Need help starting with C# and IEC60870-5-104

Posted 13 September 2015 - 01:20 AM

Thanks for the responses. Looking over my original post, I noticed one glaring flaw: I didn't clarify that 'electronics' meant 'formal training in C' and that I also have some experience with Jython. While I'm not familiar with the syntax and the terms used, the concepts underlying programming remain the same regardless of language (so far as I know, at least).

What I also did not specify is that all this program would need to do is send a single message once a second or so, attempting to automatically re-establish the connection if lost. To my understanding, that means it would only need to know how to establish a connection (the handshake) and then send data. I'm only using this protocol at all because the server side software (written by another company and beyond our ability to change) requires it.

This is a classic example of my assuming that everyone knows what I mean, made even more amusing by the fact that I regularly lambast others for making the same mistake. Does this narrow the field somewhat?

@tlhIn`toq: Very useful resources, thank you. I'll go through those.

@horace: If I understand you correctly, you mean I can let TCP handle the minutiae of creating the connection, and only worry about what happens after the connection is formed, i.e. the answer to my question in fourth paragraph, second sentence is "The first one". Have I understood that right?
Was This Post Helpful? 0
  • +
  • -

#5 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Need help starting with C# and IEC60870-5-104

Posted 13 September 2015 - 03:30 AM

if you have a good background in C and have used the OO concepts of Jython you should be able to learn C# without problems. For examples of using TCP/IP with C# see
https://msdn.microso...=vs.110%29.aspx

this may also worth looking at
http://sourceforge.n...ts/iedexplorer/
Was This Post Helpful? 1
  • +
  • -

#6 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7105
  • View blog
  • Posts: 24,124
  • Joined: 05-May 12

Re: Need help starting with C# and IEC60870-5-104

Posted 13 September 2015 - 06:36 AM

From itworkbooks.com:

Posted Image
Was This Post Helpful? 1
  • +
  • -

#7 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Need help starting with C# and IEC60870-5-104

Posted 13 September 2015 - 07:07 AM

View PostSilverFoil, on 13 September 2015 - 09:20 AM, said:

What I also did not specify is that all this program would need to do is send a single message once a second or so, attempting to automatically re-establish the connection if lost. To my understanding, that means it would only need to know how to establish a connection (the handshake) and then send data. I'm only using this protocol at all because the server side software (written by another company and beyond our ability to change) requires it.

it appears that you require to implement a TCP client
probably the simplest thing is to download a C# TCP client
https://msdn.microso...=vs.110%29.aspx

and a server
https://msdn.microso...=vs.110%29.aspx

build and run the programs on your machine
experiment sending messages between the programs - possibly use a timer?
if possible run them on different machines so the client needs to set up the correct server IP address
once you understand what is happening you can adapt the client to talk to the IEC60870-5-104 server

it may also be worth looking at
http://www.ipcomm.de...P/en/sheet.html

there is demo version of their test and simulation program for the telecontrol protocol IEC 60870-5-104

also
http://www.infotech.pl/?p=products,protester,1

This post has been edited by horace: 13 September 2015 - 07:49 AM

Was This Post Helpful? 1
  • +
  • -

#8 SilverFoil   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-September 15

Re: Need help starting with C# and IEC60870-5-104

Posted 13 September 2015 - 11:52 AM

Thanks for the clarification.

Just so I'm absolutely sure, I can first establish a connection using TCP, without any influence whatsoever from IEC 60870-5-104. After that, I send what I want by taking the data I'm interested in and attaching the protocol-specified portion to the front. Do I have this right?
Was This Post Helpful? 0
  • +
  • -

#9 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Need help starting with C# and IEC60870-5-104

Posted 13 September 2015 - 12:38 PM

I have never communicated with a IEC60870-5-104 server but I would assume you
1. open a socket to the server IP address and port, e.g. Socket sender = new Socket()
2. connect to the server, e.g. sender.Connect(remoteEP);
3. format a message to suit the IEC60870-5-104 protocol, e.g. the C# client sample of post #7 puts some text into a byte[] array
// Encode the data string into a byte array.
   byte[] msg = Encoding.ASCII.GetBytes("This is a test<EOF>");


4. send the message, e.g. sender.Send(msg)
5. wait for a reply, e.g. sender.Receive(bytes);

decode the received message and display the results

This post has been edited by horace: 13 September 2015 - 12:41 PM

Was This Post Helpful? 1
  • +
  • -

#10 SilverFoil   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-September 15

Re: Need help starting with C# and IEC60870-5-104

Posted 13 September 2015 - 02:10 PM

@horace: That was exactly the information I was looking for. As soon as someone invents a means of transmitting warm cookies through the internet I'll give you one. Cheers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1