Author Topic: Using C#  (Read 15966 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Using C#
« on: May 26, 2015, 09:39:54 PM »
Although AdvancedHMI is based on VB, it is very easy to use C#.

- Open the AdvancedHMI Solution with Visual Studio
- In the Solution Explorer, right click Solution 'AdvancedHMIv35' and select Add->New Project
- Add New Project dialog will pop up
- On the left, drill down Visual C#
- Select Windows Desktop
- On the right, select Windows Forms Application
- Give your project a name, then click OK
- Once the new project is in your solution, Right click the new C# project and select Add->Reference...
- The Reference Manager window will open. Drill down into Solution and select Projects
- Select all three projects in the list
- Click OK to close the Reference Manager
- Build the solution
- You can now add a driver from the Toolbox to your form, then add controls
« Last Edit: August 01, 2016, 06:19:03 PM by Archie »

EE_Kraig

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Using C#
« Reply #1 on: June 29, 2016, 12:23:32 PM »
Here's another way if you prefer.

Start your C# project
In Solution Explorer, right click the Solution name, select Add>Existing Project
Browse to wherever you unzipped the AdvancedHMI project
Add AdvancedHMIControls.vbproj and AdvancedHMIDrivers.vbproj
As soon as I added them, they popped up in the Toolbox

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Using C#
« Reply #2 on: June 29, 2016, 09:54:52 PM »
Here's another way if you prefer.

Start your C# project
In Solution Explorer, right click the Solution name, select Add>Existing Project
Browse to wherever you unzipped the AdvancedHMI project
Add AdvancedHMIControls.vbproj and AdvancedHMIDrivers.vbproj
You have to be careful with this technique because it splits the solution across multiple folders. This makes it more difficult to distribute the complete solution because the end user will have to have the same directory setup. Also if the original extracted AdvancedHMI solution is moved or deleted, it breaks the C# solution.

KaiserEngineering

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Using C#
« Reply #3 on: August 09, 2016, 10:37:31 PM »
I've tried with the second option, creating a new c# Project and then adding the VB Project for the Drivers and Controls... After building the Solution the Toolbars just popped up, but there are some objects missing in the AdvancedHMIDrivers Toolbar like the SerialDF1forSLCMicroCom

Anyone knows why this happened?

dmroeder

  • Global Moderator
  • Full Member
  • *****
  • Posts: 206
    • View Profile
Re: Using C#
« Reply #4 on: August 10, 2016, 12:27:02 AM »

EE_Kraig

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Using C#
« Reply #5 on: November 16, 2016, 12:09:51 PM »
Here's another way if you prefer.

Start your C# project
In Solution Explorer, right click the Solution name, select Add>Existing Project
Browse to wherever you unzipped the AdvancedHMI project
Add AdvancedHMIControls.vbproj and AdvancedHMIDrivers.vbproj
You have to be careful with this technique because it splits the solution across multiple folders. This makes it more difficult to distribute the complete solution because the end user will have to have the same directory setup. Also if the original extracted AdvancedHMI solution is moved or deleted, it breaks the C# solution.
Just got back to this...
After I added the AdvancedHMI projects as I describe, then under the References section I have:
AdvancedHMIControls
AdvancedHMIDrivers

and a few others.

Highlighting any of these shows that the Copy Local is set to true. So when I build, in the bin folder I get my exe and a few dlls. I copied the exe and dlls into a folder on my target machine and my application runs just fine.

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: Using C#
« Reply #6 on: November 16, 2016, 10:07:00 PM »
Yes, genius your copy may run just fine, but what about someoone else need to make a change later on with his laptop, then what?
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

EE_Kraig

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Using C#
« Reply #7 on: November 17, 2016, 10:37:42 AM »
Simple. You set up your development machine like this:

MyProject\AdvancedHMI

then you commit your project to your source code control system. Now anyone can pull that code from the repo, build, and they will get the same output files on any machine and can deploy to the target machine in the same manner. Need to make a change? Pull from repo, build new exe and xcopy to target.

I know it is common to have your complete build environment on the target machine but this may not always be feasible, possible, etc. I work in the highly regulated medical device industry and if you had the build tools and source codes on your target machine, where anyone could walk up and make changes to a validated piece of production equipment, that could get you shut down.

Same thing if the target machine dies, you need to have documentation on how to reproduce the system.

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: Using C#
« Reply #8 on: November 17, 2016, 06:07:14 PM »
I never said you need to have the source code in the tartget machine which is normally on the shop floor.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Godra

  • Hero Member
  • *****
  • Posts: 1436
    • View Profile
Re: Using C#
« Reply #9 on: November 17, 2016, 08:50:32 PM »
If EE_Kraig's approach works then some users might find it acceptable and some might not.

leovailati

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Using C#
« Reply #10 on: November 18, 2016, 12:11:24 PM »
Simple. You set up your development machine like this:

MyProject\AdvancedHMI

then you commit your project to your source code control system. Now anyone can pull that code from the repo, build, and they will get the same output files on any machine and can deploy to the target machine in the same manner. Need to make a change? Pull from repo, build new exe and xcopy to target.

I know it is common to have your complete build environment on the target machine but this may not always be feasible, possible, etc. I work in the highly regulated medical device industry and if you had the build tools and source codes on your target machine, where anyone could walk up and make changes to a validated piece of production equipment, that could get you shut down.

Same thing if the target machine dies, you need to have documentation on how to reproduce the system.

See: http://advancedhmi.com/forum/index.php?topic=1402.msg7606#msg7606

In short:

The licensing also requires distribution of the complete solution source code to the end user.

In other words: if you don't distribute the full source code with your product, you are violating the license. They claim the reason for that is because if in the future an engineer wants to modify the program, they can immediately do so. I proposed that that article of the license be reviewed and maybe changed to something like "must give credit". But it is ultimately the author's choice and we must respect that - he is the one that put in all the hours to develop this project and decided to open source it!
« Last Edit: November 18, 2016, 12:18:51 PM by leovailati »

EE_Kraig

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Using C#
« Reply #11 on: November 18, 2016, 12:32:55 PM »
Can't you provide a USB stick to your end customer with the full solution and just deploy the necessary files onto the target machine and still meet the license??

Actually, I just reread the FAQ on licensing. This should be perfectly acceptable.
« Last Edit: November 18, 2016, 12:37:47 PM by EE_Kraig »

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: Using C#
« Reply #12 on: November 25, 2016, 08:37:21 AM »
I've tried with the second option, creating a new c# Project and then adding the VB Project for the Drivers and Controls... After building the Solution the Toolbars just popped up, but there are some objects missing in the AdvancedHMIDrivers Toolbar like the SerialDF1forSLCMicroCom

Anyone knows why this happened?

In regarding to the missing driver problem, I am not  sure that it's VS 2015 fault since  I can consistently add driver from 399a without any problem.
VS 2015 update 1 did not fix it. I downloaded update 3, and the problem still  there. And now I am downloading 2017 RC. It's still downloading at 11.2 GB :=(.

Archie, why version a works?
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Using C#
« Reply #13 on: December 06, 2016, 08:47:20 AM »
To make things easier for those that prefer C#, version 3.99s now comes with a pre-configured C# projects.

EE_Kraig

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Using C#
« Reply #14 on: March 03, 2017, 10:41:04 AM »
In the interest of completeness in case anyone uses this method, updated procedure.

Start your C# project
In Solution Explorer, right click the Solution name, select Add>Existing Project
Browse to wherever you unzipped the AdvancedHMI project
Add the following (I did it in this order):
AdvancedHMI.vbproj
AdvancedHMIControls.vbproj
AdvancedHMIDrivers.vbproj

Right-click on AdvancedHMI and Build.
After this, the toolbox gets populated (I did have to close and restart VS one time to get the Drivers to pop up).