Esempio n. 1
0
        public BP_RESPONSE Connect()
        {
            BP_RESPONSE response = BP_RESPONSE.OK;

            if (!IsConnected)
            {
                Open();
                if (handler == null)
                {
                    handler       = new SerialDataReceivedEventHandler(BPPort_DataReceived);
                    DataReceived += handler;
                }

                if ((response = SendWait("", m_prompts, 5, 1000)) == BP_RESPONSE.OK)
                {
                    IsConnected = true;
                    response    = Info();
                }
                else
                {
                    Close();
                }
            }
            return(response);
        }
Esempio n. 2
0
        private void Run_Click(object sender, EventArgs e)
        {
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (bpPort != null && bpPort.IsConnected)
            {
                string script = Script.Text.Trim();
                foreach (string line in script.Split(new char[] { '\r', '\n' }))
                {
                    string cmd = line.Trim();
                    if (!string.IsNullOrEmpty(cmd))
                    {
                        int idx = cmd.IndexOf("//");
                        if (idx >= 0)
                        {
                            cmd = cmd.Substring(0, idx).Trim();
                        }
                        foreach (string subline in cmd.Split(new char[] { '\'' }))
                        {
                            string subcmd = subline.Trim();
                            if (!string.IsNullOrEmpty(subcmd))
                            {
                                response = bpPort.SendWait(subcmd);
                                if (response != BP_RESPONSE.OK)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            DisplayStatus(response);
        }
Esempio n. 3
0
 private void DisplayStatus(BP_RESPONSE response)
 {
     StatusText(response.ToString());
     if (AutoInfo.Checked)
     {
         RefreshVoltage();
     }
 }
Esempio n. 4
0
        public BP_RESPONSE SendWait(string command, List <string> waitFor, int retry, uint timeout)
        {
            BP_RESPONSE response = BP_RESPONSE.Timeout;

            lock (m_lock)
            {
                try
                {
                    if (SendStarted != null)
                    {
                        SendStarted(this, command);
                    }

                    bp_waitFor = waitFor;

                    while (retry-- > 0)
                    {
                        PrepareSend();
                        bp_processing = true;
                        WriteTimeout  = 5000;
                        WriteLine(command);

                        long end_time = DateTime.Now.Ticks + ((long)timeout * TimeSpan.TicksPerMillisecond);
                        while (!bp_waitFound && end_time > DateTime.Now.Ticks)
                        {
                            if (WaitResponse != null)
                            {
                                WaitResponse(this);
                            }
                            Thread.Sleep(10);
                        }
                        if (bp_waitFound)
                        {
                            response = BP_RESPONSE.OK;
                            break;
                        }
                    }
                }
                catch (TimeoutException)
                {
                    response = BP_RESPONSE.Timeout;
                }
                catch
                {
                    response = BP_RESPONSE.Unknown;
                }
                bp_processing = false;
                if (SendEnded != null)
                {
                    SendEnded(this, command);
                }
            }
            return(response);
        }
Esempio n. 5
0
        public BP_RESPONSE ModeI2C(BP_I2C_SPEED speed)
        {
            m_mode = BP_MODE.I2C;
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (IsConnected &&
                (response = SendWait("m4")) == BP_RESPONSE.OK
                )
            {
                response = SendWait(((int)speed));
            }
            return(response);
        }
Esempio n. 6
0
        internal BP_RESPONSE OutputFormat(BP_OUTPUT_FORMAT format)
        {
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (IsConnected)
            {
                if ((response = SendWait("o")) == BP_RESPONSE.OK)
                {
                    response = SendWait(((int)format));
                }
            }
            return(response);
        }
Esempio n. 7
0
        internal BP_RESPONSE Voltage()
        {
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (IsConnected &&
                (response = SendWait("v")) == BP_RESPONSE.OK &&
                (response = ParseVoltage(GetLine(5))) == BP_RESPONSE.OK &&
                (response = ParsePinMode(GetLine(4))) == BP_RESPONSE.OK
                )
            {
                response = ParsePinName(GetLine(3));
            }
            return(response);
        }
Esempio n. 8
0
        public BP_RESPONSE ModeWIRE2(BP_WIRE_SPEED speed, BP_OUTPUT output)
        {
            m_mode = BP_MODE.WIRE2;
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (IsConnected &&
                (response = SendWait("m6")) == BP_RESPONSE.OK &&
                (response = SendWait((int)speed)) == BP_RESPONSE.OK
                )
            {
                response = SendWait((int)output);
            }
            return(response);
        }
Esempio n. 9
0
        public BP_RESPONSE ModeUART(BP_UART_SPEED speed, BP_UART_PROTOCOL protocol, BP_UART_STOP stop, BP_UART_POLARITY polarity, BP_OUTPUT output)
        {
            m_mode = BP_MODE.UART;
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (IsConnected &&
                (response = SendWait("m3")) == BP_RESPONSE.OK &&
                (response = SendWait((int)speed)) == BP_RESPONSE.OK &&
                (response = SendWait((int)protocol)) == BP_RESPONSE.OK &&
                (response = SendWait((int)stop)) == BP_RESPONSE.OK &&
                (response = SendWait((int)polarity)) == BP_RESPONSE.OK
                )
            {
                response = SendWait(((int)output));
            }
            return(response);
        }
Esempio n. 10
0
        public BP_RESPONSE ModeSPI(BP_SPI_SPEED speed, BP_SPI_CLOCK_POLARITY polarity, BP_SPI_CLOCK_EDGE edge, BP_SPI_INPUT_PHASE phase, BP_CS_POLARITY cs, BP_OUTPUT output)
        {
            m_mode = BP_MODE.SPI;
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (IsConnected &&
                (response = SendWait("m5")) == BP_RESPONSE.OK &&
                (response = SendWait((int)speed)) == BP_RESPONSE.OK &&
                (response = SendWait((int)polarity)) == BP_RESPONSE.OK &&
                (response = SendWait((int)edge)) == BP_RESPONSE.OK &&
                (response = SendWait((int)phase)) == BP_RESPONSE.OK &&
                (response = SendWait((int)cs)) == BP_RESPONSE.OK
                )
            {
                response = SendWait((int)output);
            }
            return(response);
        }
Esempio n. 11
0
        public BP_RESPONSE Info()
        {
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (IsConnected &&
                (response = SendWait("i")) == BP_RESPONSE.OK
                )
            {
                response = BP_RESPONSE.BadResponse;
                if (bp_lines.Count >= 5)
                {
                    HardwareVersion = GetLine(1);
                    FirmwareVersion = GetLine(2);
                    PICVersion      = GetLine(3);
                    if (!string.IsNullOrEmpty(HardwareVersion) &&
                        !string.IsNullOrEmpty(FirmwareVersion) &&
                        !string.IsNullOrEmpty(PICVersion)
                        )
                    {
                        string mode = bp_lines[bp_lines.Count - 1];
                        int    idx  = m_prompts.IndexOf(mode);
                        if (idx >= 0)
                        {
                            m_mode   = (BP_MODE)(idx + 1);
                            response = BP_RESPONSE.OK;
                            if (GetLine(7) == "Pinstates:")
                            {
                                if ((response = ParseVoltage(GetLine(11))) == BP_RESPONSE.OK &&
                                    (response = ParsePinMode(GetLine(10))) == BP_RESPONSE.OK
                                    )
                                {
                                    response = ParsePinName(GetLine(9));
                                }
                            }
                        }
                    }
                }
            }
            return(response);
        }
Esempio n. 12
0
        public BP_RESPONSE AuxRead()
        {
            BP_RESPONSE response = BP_RESPONSE.Disconnect;

            if (IsConnected && (response = SendWait("@")) == BP_RESPONSE.OK)
            {
                response = BP_RESPONSE.BadResponse;
                if (bp_lines.Count >= 3)
                {
                    string value = GetLine(1);
                    if (value.EndsWith("0"))
                    {
                        Pins[5].Digital = false;
                        response        = BP_RESPONSE.OK;
                    }
                    else if (value.EndsWith("1"))
                    {
                        Pins[5].Digital = true;
                        response        = BP_RESPONSE.OK;
                    }
                }
            }
            return(response);
        }
Esempio n. 13
0
 private void DisplayStatus(BP_RESPONSE response)
 {
     StatusText(response.ToString());
     if (AutoInfo.Checked)
         RefreshVoltage();
 }