Jump to content

Not Clicking

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
16 replies to this topic

#1
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
I'm trying to figure out how to get two programs to talk properly to each other.

C# Code

namespace Hello

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            PubNames.Responce = "Did This Work";

            MessageBox.Show(PubNames.Responce);

        }


        public void AddLog(string Texttoadd)

        {

            SayLog.Text = SayLog.Text + Texttoadd + Environment.NewLine;

        }


    }

    public class PubNames

    {

        public static string Responce = "Why";

        public static string SayHello(string WhatToSay)

        {

            MessageBox.Show(WhatToSay);

            return Responce;

            

        }

    }


}



VB Code
(Included in References is Hello.exe, shows up as type ".NET"

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        MsgBox(Hello.PubNames.Responce)

    End Sub

End Class



Now when I start the C# Program, the MsgBox shows "Did This Work" as I would expect.

But when the VB Program runs it only shows "WHY" even though the C# Program is running (And should of already set Responce to "Did This Work"

What am I doing wrong :confused::confused::confused:

#2
dot_developer

dot_developer

    Newbie

  • Members
  • PipPip
  • 14 posts
You can't make two programs 'talk' in that manner. I don't know how to explain this lol, just know that this won't work and you can't modify it any way to make it work.


There are different methods you can use for inter-application communication, some are:
    Use window messages if you need to communicate something very basic.
    Use Pipes (http : // msdn.microsoft . com/en-us/library/aa365781(VS.85).aspx]Pipe Functions (Windows))
    Use Sockets just like you would when creating a network application.
    Shared memory

There are definitely other methods but these are the good ones I can think of.

#3
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
My final application will be returning data (not just a single string, just using that to learn how to do it) in the form of

    public static double[] TestData = new double[50000];

This will happen about every 2-4 Seconds (50K Data points)
Some Test will return This every 1/4 A Second

    public static double[] Test2Data = new double[500000];

So I was hoping for some way to run App1 as a service so that App2 (That calls for the data) can be restarted without needing to restart App1.

I can get App1 to work as a DLL, but I don't trust the end user to always initialize it correctly or in time, that's sorta why I'm trying to get it to run as its own Service / Application while allowing the second program to interface with it.

The First generation of this program (Already working) is using a GPIB Bus for communication, but transferring this amount of data is slowing down the system, and also requires the use of two computers (They would like it to only require one system).

#4
dot_developer

dot_developer

    Newbie

  • Members
  • PipPip
  • 14 posts
I did not understand much of your previous post :S.

Why is a Pipe or Socket not good enough?

#5
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
They might :D (I'm still trying to figure this out)

Are there any limitations with the Data Types / Amounts of Data / Speed
When using Sockets / Pipes ?

(Also any good examples)

I'm so used to writing single apps that don't have to communicate with other apps (other than the via GPIB (think USB) and user interface comunication)

#6
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
How much are you wanting to send? I mean, sockets are what you would use to send data from one system to another, which can be pretty large ;). Therefore sending data from one program to another in this way ought to work, and be pretty fast (sending locally).

Have not really had much experience with pipes. But I do know it is how a lot of programs written on the .NET platform 'talk' to each other, therefore I don't think the limitations would have much of an effect for most programs.

#7
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts

so1i said:

How much are you wanting to send? I mean, sockets are what you would use to send data from one system to another, which can be pretty large ;). Therefore sending data from one program to another in this way ought to work, and be pretty fast (sending locally).

Have not really had much experience with pipes. But I do know it is how a lot of programs written on the .NET platform 'talk' to each other, therefore I don't think the limitations would have much of an effect for most programs.
One Test will Generate about a 1/2 Meg of Raw Data
(2 Sets per point Location & Value)

Looking over the sockets now

                ASCIIEncoding asen = new ASCIIEncoding();

                IPAddress ipAd = IPAddress.Parse("127.0.0.1"); //use local m/c IP address, and use the same in the client

                TcpListener myList = new TcpListener(ipAd, 8001);

                myList.Start();

                Socket MyComSocket = myList.AcceptSocket();

                MyComSocket.Send(asen.GetBytes(StringData));

                MyComSocket.Close();

                myList.Stop();


This example I found sends String Data between the two Applications without issue so far.


Now I need to see how to send an Array of Data
public static double[,] TestData = new double[2, 50000];
public static double[] Test2Data = new double[500000];

They can run one of two test (That returns either of the above)

now looking at System.Net.Sockets.Socket.Send I see
Send(byte[] buffer);
Send(IList<ArraySegment<byte>> buffers);
Send(byte[] buffer, SocketFlags SocketFlags);
Send(IList<ArraySegment<byte>> buffers, SocketFlags SocketFlags);
Send(byte[] buffer, int size, SocketFlags socketFlags);
Send(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode);
Send(byte[] buffer, int offset, int size, SocketFlags socketFlags);
Send(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode);

And am trying to figure out which version of Send would work best for a large array (and how to send a Double[,] as a byte[]

#8
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
Ok I see how to send a Single Double as a byte[] using ComBuffer=BitConverter.GetBytes(Test2Data[1]);

But how do I convert ALL of Test2Data to byte[] ?
(This example Test2Data is double[] Test2Data = new double[500000]; )

#9
dot_developer

dot_developer

    Newbie

  • Members
  • PipPip
  • 14 posts
500000 is a big array. How often would you need to transfer this much data?

#10
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts

dot_developer said:

500000 is a big array. How often would you need to transfer this much data?

The Max Size Array can be run about every Second (1/2 Million Voltage Samples for Noise Testing)

#11
dot_developer

dot_developer

    Newbie

  • Members
  • PipPip
  • 14 posts
Every second is quite often. I was initially going to sugges that you iterate through the array and convert every double value individually but that will be too slow - however, give it a try.

If that proves to be slow then a faster method would be to pin the array and read it directly from memory.

Also, I do not think a TCP socket would handle so much load effeciently.

#12
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts

dot_developer said:

Every second is quite often. I was initially going to sugges that you iterate through the array and convert every double value individually but that will be too slow - however, give it a try.

If that proves to be slow then a faster method would be to pin the array and read it directly from memory.

Also, I do not think a TCP socket would handle so much load effeciently.

How do I transfer the array from Program A to Program B (or the Memory Location) as the array size can change from test to test (depending on the test parameters)


The more I look into this the more it's looking like I'll have to do this as a DLL (This will work, but I just don't believe it's the best solution)