コード例 #1
0
ファイル: Com.cs プロジェクト: lf73/JediComlink
        public SB9600Message SendSB9600(SB9600Message message)
        {
            int attempts = 0;

            while (true)
            {
                if (_sbepMode)
                {
                    ExitSbepMode();
                }
                var packetSize = message.Bytes.Length;

                _port.DtrEnable = true;
                _port.RtsEnable = true;
                Thread.Sleep(30);
                _port.DiscardInBuffer();
                _port.DiscardOutBuffer();
                UpdateStatus("Sending: " + String.Join(" ", Array.ConvertAll(message.Bytes, x => x.ToString("X2"))));
                _port.Write(message.Bytes, 0, packetSize);
                var echo = ReceiveSB9600();
                if (echo == null || echo.Bytes.Max() == 0x00)
                {
                    if (attempts == 4)
                    {
                        throw new Exception("RIB or interface cable does not appear to be connected to the computer. Is the cable connected, and if using a RIB, is it powered on? Is the correct COM port selected?");
                    }
                    Thread.Sleep(500);
                    attempts++;
                    continue;
                }

                if (!message.ResponseExpected)
                {
                    _port.DtrEnable = false;
                    _port.RtsEnable = false;
                    return(null);
                }

                var response = ReceiveSB9600();
                _port.DtrEnable = false;
                _port.RtsEnable = false;
                Thread.Sleep(30);
                _port.DiscardInBuffer();
                _port.DiscardOutBuffer();

                if (response == null || response.Bytes.Max() == 0x00)
                {
                    if (attempts == 4)
                    {
                        throw new Exception("No response from radio. The RIB and/or cable appears to be connected to computer. Is the cable connected to the radio and is the radio powered on?");
                    }
                    Thread.Sleep(500);
                    attempts++;
                    continue;
                }
                return(response);
            }
        }
コード例 #2
0
ファイル: Com.cs プロジェクト: lf73/JediComlink
        public SB9600Message ReceiveSB9600()
        {
            SB9600Message message = null;

            byte[] buffer = new byte[5];
            var    sw     = Stopwatch.StartNew();

            while (sw.ElapsedMilliseconds < 100)
            {
                if (_port.BytesToRead < 5)
                {
                    Thread.Sleep(10);
                    continue;
                }
                _port.Read(buffer, 0, 5);
                message = new SB9600Message(buffer, 5);
                break;
            }

            return(message);
        }