Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            ComReader comReader = ComReader.Instance;

            comReader.DataReceived   += ComReader_DataReceived;
            comReader.LostConnection += ComReader_LostConnection;

            Console.WriteLine("Key: '1' - Init, '2' - Start, 3 - 'Stop'");

            while (true)
            {
                var keyInfo = Console.ReadKey();

                switch (keyInfo.KeyChar)
                {
                case '1':
                    comReader.Init();
                    break;

                case '2':
                    comReader.Start();
                    break;

                case '3':
                    comReader.Stop();
                    break;

                default:
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private async Task ScanIcpDevices(BznModel bznModel)
        {
            ComReader comReader = new ComReader(bznModel.ComDevice.Port);

            if (comReader.Open())
            {
                bznModel.IcpDevices = new ObservableCollection <IcpDeviceModel>(await IcpDeviceManager.ScanIcpDevicesAsync(comReader));
            }
        }
Ejemplo n.º 3
0
        private static bool SendCommand(ComReader comReader, IcpDeviceModel icpDevice, IcpCommand command, int addr)
        {
            string request  = IcpDcom.CreateIcpDcomRequest(command, addr);
            string response = comReader.SendCommand(request);
            bool   result   = IcpDcom.ParseIcpResponse(command, response, icpDevice);

            if (!result)
            {
                logger.Error($"Cant send {command} to {icpDevice.Name}, addr: {addr}, com: {comReader.Port}");
            }
            return(result);
        }
Ejemplo n.º 4
0
        private static IcpDeviceModel GetFullInfo(ComReader comReader, int addr)
        {
            IcpDeviceModel icpDeviceModel = new IcpDeviceModel {
                Address = addr
            };

            SendCommand(comReader, icpDeviceModel, IcpCommand.GetName, addr);
            SendCommand(comReader, icpDeviceModel, IcpCommand.GetFirmware, addr);
            SendCommand(comReader, icpDeviceModel, IcpCommand.GetInputState, addr);

            return(icpDeviceModel);
        }
Ejemplo n.º 5
0
        // parse the assembly definitions using metadata reader
        public MethodParser(string assemblyPath)
        {
            var comReader = new ComReader(assemblyPath);

            foreach (MetadataMethod method in comReader.getMethodsWithCustomAttribute(ComReader.exportAttribute))
            {
                var tokens = method.typeName.Split('.');
                if (tokens.Length > 1)
                {
                    methods.Add(new Method(method.name, tokens[0], tokens[1]));
                }
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            ComReader      comReader     = new ComReader("COM1");
            IcpDeviceModel deviceModel_3 = new IcpDeviceModel();
            IcpDeviceModel deviceModel_9 = new IcpDeviceModel();

            if (comReader.Open())
            {
                string cmd = "";
                {
                    string request  = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetName, 9);
                    string response = comReader.SendCommand(request);
                    bool   res      = IcpDcom.ParseIcpResponse(IcpCommand.GetName, response, deviceModel_9);

                    request  = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetModuleStatus, 9);
                    response = comReader.SendCommand(request);
                    res      = IcpDcom.ParseIcpResponse(IcpCommand.GetModuleStatus, response, deviceModel_9);

                    request  = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetFirmware, 9);
                    response = comReader.SendCommand(request);
                    res      = IcpDcom.ParseIcpResponse(IcpCommand.GetFirmware, response, deviceModel_9);

                    request  = IcpDcom.CreateIcpDcomRequest(IcpCommand.SetOutputs, 9, "", 15);
                    response = comReader.SendCommand(request);
                    res      = IcpDcom.ParseIcpResponse(IcpCommand.SetOutputs, response, deviceModel_9);
                }
                {
                    string request  = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetName, 3);
                    string response = comReader.SendCommand(request);
                    bool   res      = IcpDcom.ParseIcpResponse(IcpCommand.GetName, response, deviceModel_3);

                    request  = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetFirmware, 3);
                    response = comReader.SendCommand(request);
                    res      = IcpDcom.ParseIcpResponse(IcpCommand.GetFirmware, response, deviceModel_3);

                    request  = IcpDcom.CreateIcpDcomRequest(IcpCommand.GetInputState, 3);
                    response = comReader.SendCommand(request);
                    res      = IcpDcom.ParseIcpResponse(IcpCommand.GetInputState, response, deviceModel_3);
                }

                do
                {
                    Console.Write("Enter command: ");
                    cmd = Console.ReadLine();

                    var resp = comReader.SendCommand(cmd);
                    Console.WriteLine($"Response: {resp}");
                    Console.WriteLine();
                } while (cmd != "quit");
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Action <string> foundAction = s =>
            {
                //var client = new RestClient("https://www.size.com");
                //var request = new RestRequest("/doorbell.asp", Method.POST);
                //client.Proxy = new WebProxy("proxy...");
                //client.Execute(request);
                System.Console.WriteLine(s);
            };

            ComReader.Register(foundAction);
            System.Console.ReadLine();
        }
Ejemplo n.º 8
0
        public static bool PingDevice(int addr, ComReader comReader)
        {
            var req  = CreateIcpDcomRequest(IcpCommand.GetModuleStatus, addr);
            var resp = comReader.SendCommand(req);

            if (string.IsNullOrEmpty(resp))
            {
                return(false);
            }

            if (resp[0] == '!')
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 9
0
        //[TestMethod]
        public async Task TestMethod1Async()
        {
            ComReader comReader = new ComReader("COM1");

            if (comReader.Open())
            {
                IcpDeviceManager icpDeviceManager = new IcpDeviceManager(comReader);
                var devices = await icpDeviceManager.ScanIcpDevicesAsync();

                foreach (var item in devices)
                {
                    Debug.WriteLine($"-- {item.Name}");
                }
            }

            comReader.Close();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Notifier.header("############################################################");
            Notifier.header("###########  ~°~   Welcome to the ICU 0.0   ~°~  ###########");
            Notifier.header("############################################################");
            Notifier.header("");

            // Listen from UDP for incoming requests
            UdpReceive recv = new UdpReceive();

            // Read from the COMPORT
            ComReader comReader = new ComReader();

            //UdpSend.Instance.SendMessage("127.0.0.1", 5000, "HELLOOO");

            // And that's it !
            Console.ReadLine();
        }
Ejemplo n.º 11
0
        protected override void OnStart(string[] args)
        {
            EventLog.WriteEntry("Knocker Service Starting...");
            Action <string> foundAction = s =>
            {
                EventLog.WriteEntry(s);

                // launch the application
                ApplicationLoader.PROCESS_INFORMATION procInfo;
                ApplicationLoader.StartProcessAndBypassUAC(@"C:\Services\Tallon.Knocker.Notification.exe", out procInfo);

                //var client = new RestClient("https://www.size.com");
                //var request = new RestRequest("/doorbell.asp", Method.POST);
                //client.Proxy = new WebProxy("proxy...");
                //client.Execute(request);
            };

            ComReader.Register(foundAction);
        }
Ejemplo n.º 12
0
        //[TestMethod]
        public void ComReaderTestMethod()
        {
            ComReader comReader = ComReader.Instance;

            if (comReader.Init())
            {
                comReader.Start();
            }
            else
            {
                Debug.WriteLine($"Cant Init ComReader");
            }
            comReader.DataReceived   += ComReader_DataReceived;
            comReader.LostConnection += ComReader_LostConnection;

            while (true)
            {
                var key = Console.ReadKey();
            }
        }
Ejemplo n.º 13
0
        public static async Task <List <IcpDeviceModel> > ScanIcpDevicesAsync(ComReader comReader)
        {
            await TaskEx.Run(() =>
            {
                List <IcpDeviceModel> icpDevices = new List <IcpDeviceModel>();
                for (int i = 1; i < 10; i++)
                {
                    if (!IcpDcom.PingDevice(i, comReader))
                    {
                        continue;
                    }

                    IcpDeviceModel devInfo = GetFullInfo(comReader, i);
                    icpDevices.Add(devInfo);
                }
                return(icpDevices);
            });

            return(null);
        }
Ejemplo n.º 14
0
        public void TestMethod1()
        {
            ComReader comReader = new ComReader("COM1");

            comReader.Close();
            Thread.Sleep(200);
            comReader.Close();

            Thread.Sleep(200);

            if (comReader.Open())
            {
                string resp = comReader.SendCommand("$02M");
                resp = comReader.SendCommand("$02C");
                resp = comReader.SendCommand("$03C");
                resp = comReader.SendCommand("$03M");
                resp = comReader.SendCommand("$03L0");
                resp = comReader.SendCommand("$02L0");
                resp = comReader.SendCommand("$@03");
                resp = comReader.SendCommand("$@02");
            }
        }
Ejemplo n.º 15
0
 public void init()
 {
     _assemblyPath = createAssembly();
     _comReader    = new ComReader(_assemblyPath);
 }
Ejemplo n.º 16
0
        public void FoundArduinoPortTest()
        {
            var result = ComReader.FoundPort();

            Assert.IsTrue(result);
        }
Ejemplo n.º 17
0
 public IcpDeviceManager(ComReader comReader)
 {
     ComReader = comReader;
 }
Ejemplo n.º 18
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Action <string> resultAction = s => MessageBox.Show(s);

            ComReader.Register(resultAction);
        }