C# Remoting to access SerialPort?

Discussion in 'C#' started by gumbald, Sep 9, 2010.

  1. gumbald

    gumbald New Member

    Joined:
    Sep 9, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I'm having problems with the telnet on a device, so wanting to run a program attached by serial port to the device and then have other machines access this by C# remoting. However, I can't seem to find a way to give the interface access to this local resource after setting it up?

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting.Channels.Tcp;
    using System.Runtime.Remoting.Channels.Http;
    using System.Net;
    using System.IO;
    using System.IO.Ports;
    
    namespace C7_Serial_Server
    {
            class C7_Serial
            {
                    internal static SerialPort SP { get; set; }
    
                    static void Main(string[] args)
                    {
                            Console.Write("Serial port: ");
                            int SP_Location = Convert.ToInt32(Console.ReadLine());
    
                            SP = new SerialPort("COM" + SP_Location);
                            SP.BaudRate = 57600;
                            SP.Open();
    
                            AcceptConnections();
                    }
    
                    static void AcceptConnections()
                    {
                            HttpServerChannel tcpChannel = new HttpServerChannel(9996);
                            ChannelServices.RegisterChannel(tcpChannel, false);
    
                            Type commonInterfaceType = Type.GetType("C7_Serial_Server.Access");
    
                            RemotingConfiguration.RegisterWellKnownServiceType(commonInterfaceType, "C7_Serial_Access", WellKnownObjectMode.SingleCall);
                            RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
                    }
            }
    
            public interface SetProfile
            {
                    Access.Info C7_SetProfile(Access.Setup Location);
            }
    
            public class Access : MarshalByRefObject, GetStats, SetProfile
            {
                    
    
                    [Serializable]
                    public class Info
                    {
                            public string Equipment { get; set; }
    
                            public Info(string Equipment)
                            {
                                    this.Equipment = Equipment;
                            }
                    }
    
                    [Serializable]
                    public class Setup
                    {
                            public int Slot { get; set; }
    
                            public Setup(int Slot)
                            {
                                    this.Slot = Slot;
                            }
                    }
    
                    public Info C7_SetProfile(Setup Location)
                    {
                            return new Info("Set");
                    }
            }
    }
    I need the "SetProfile" command to access the serial port created by the console program, how is the best way to do this?

    Thanks!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice