Example #1
0
        public GmcCommunicator(string portName)
        {
            this.port = OpenPort(portName);
            this.writer = new GmcWriter(this.port);
            this.reader = new GmcReader(this.port);

            this.heartbeatPoller = new Timer(this.PollHeartbeat, null, 0, HeartbeatPollingInterval);
            this.isHeartbeatEnabled = 0;
        }
Example #2
0
        public GmcCommunicator()
        {
            string devicePortName;
            bool devicePortDetected = TryDetectDevicePort(out devicePortName);

            if (!devicePortDetected)
            {
                throw new DeviceNotFoundException("The device could not be automatically detected.");
            }

            this.port = OpenPort(devicePortName);
            this.reader = new GmcReader(this.port);
            this.writer = new GmcWriter(this.port);

            this.heartbeatPoller = new Timer(this.PollHeartbeat, null, 0, HeartbeatPollingInterval);
            this.isHeartbeatEnabled = 0;
        }
Example #3
0
        public GmcCommunicator(SerialPort port)
        {
            this.port = port;
            this.writer = new GmcWriter(this.port);
            this.reader = new GmcReader(this.port);

            this.heartbeatPoller = new Timer(this.PollHeartbeat, null, 0, HeartbeatPollingInterval);
            this.isHeartbeatEnabled = 0;
        }
Example #4
0
        private static bool TryDetectDevicePort(out string devicePortName)
        {
            string[] portNames = SerialPort.GetPortNames();
            foreach (string portName in portNames)
            {
                string version;
                using (SerialPort port = OpenPort(portName))
                {
                    try
                    {
                        port.Open();
                    }
                    catch
                    {
                        continue;
                    }

                    using (GmcReader reader = new GmcReader(port))
                    {
                        using (GmcWriter writer = new GmcWriter(port))
                        {
                            writer.WriteVersionRequest();

                            try
                            {
                                version = reader.ReadVersion();
                            }
                            catch (DeviceUnresponsiveException)
                            {
                                continue;
                            }
                        }
                    }

                    port.Close();
                }

                if (version.StartsWith("GMC"))
                {
                    devicePortName = portName;
                    return true;
                }
            }

            devicePortName = null;
            return false;
        }