Example #1
0
 void ConnectToHyPrDevice(string portname)
 {
     try
     {
         _serialPort = null;
         _serialPort = new SafeSerialPort(portname, BaudRate);
         _serialPort.DataReceived += serialPort_DataReceived;
         _serialPort.Open();
         Console.WriteLine("Found HyPR device at: " + portname);
     }
     catch (Exception ex)
     {
         Console.WriteLine("NOT connected to: " + portname);
         Console.WriteLine(ex.ToString());
     }
 }
Example #2
0
        public OltProtocol()
        {
            Version     = OltProtocolVersion.OltDiagV1;
            diagRequest = OltDiagV1DataRequest;
            ReadFreq    = 0;
            Requests    = new Queue <Request>();
            readThread  = new BackgroundWorker {
                WorkerSupportsCancellation = true
            };
            readThread.DoWork += readThread_DoWork;
            serialPort         = new SafeSerialPort("COM1", 10400, Parity.None, 8, StopBits.One)
            {
                WriteTimeout = 100,
                ReadTimeout  = 100
            };

            ecuSn           = new byte[8];
            ecuSnHashBuffer = DiagProtocolHelper.InitEcuSnHashBuffer(ecuSn, 240);
        }
Example #3
0
        void Disconnect(string reason)
        {
            lock (commandSendLock)
            {
                if (target != null)
                {
                    //AppLog.Write(Strings.Default.DisconnectHeader + reason, AppLog.LogEntryType.Warning, AppLog.LogEntrySource.MsregDevice, TargetPort);

                    target.Dispose();
                    target = null;

                    GC.Collect();

                    //OnDisconnected(reason);
                }

                if (lineReceiver != null)
                {
                    lineReceiver.Abort();
                    lineReceiver = null;
                }

                //ConnectedDeviceInfo = null;

                //ackReplies.Clear();
            }
        }
Example #4
0
        void SetupComPort()
        {
            if (target != null)
                target.Dispose();

            target = new SafeSerialPort();
            target.BaudRate = 4800;
            target.Handshake = Handshake.None;
            target.NewLine = "\r\n";
            target.Parity = Parity.None;
            target.ReadTimeout = 10000;
            target.StopBits = StopBits.One;

            if (lineReceiver != null)
                lineReceiver.Abort();

            lineReceiver = new Thread(ReceiveLine_T);
            lineReceiver.IsBackground = true;
            lineReceiver.Name = this.ToString() + "_LineReceiver";
            lineReceiver.Start();

            commandQueue.Clear();
        }