public BinaryChunkWriterTest(string fileName)
        {
            using (SpiDevice spi = SpiDevice.Create(new SpiConnectionSettings(1, 0)
            {
                Mode = SpiMode.Mode0, ClockFrequency = 900000
            }))
            {
                _accelerometerDevice = new Mcp3208Custom(spi, (int)Channel.X, (int)Channel.Y, (int)Channel.Z);
            }
            // _accelerometerDevice = new Accelerometer(new SpiConnectionSettings(0, 0) { Mode = SpiMode.Mode0, ClockFrequency = 1900000 });
            _gyroscopeDevice = new Gyroscope(new SpiConnectionSettings(0, 0)
            {
                Mode = SpiMode.Mode0, ClockFrequency = 900000
            });
            _cpuDevice = new CpuTemperature();
            _rtcDevice = new RTC();
            _uart      = new UART();

            fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
        }
Example #2
0
 /// <summary>
 /// 將搜尋到的Com Port置入清單
 /// </summary>
 void SearchPort()
 {
     string[] tmpPortList = UART.SearchPort();
     cbxCom.Items.Clear();
     cbxCom.Items.AddRange(tmpPortList);
     portList.Clear();
     portList.AddRange(tmpPortList);
     if (serial_port_dongle != null)
     {
         if (portList.Contains(serial_port_dongle.getPort.PortName))
         {
             cbxCom.Text = serial_port_dongle.getPort.PortName;
             return;
         }
     }
     if (cbxCom.Text == "" && cbxCom.Items.Count > 0)
     {
         cbxCom.SelectedIndex = 0;
     }
 }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            const bool trigger = true;

            Sequential handler = () =>
            {
                byte data = 0;
                UART.Read(115200, RXD, out data);

                byte result = 0;
                Lookpup(data, out result);

                UART.Write(115200, result, TXD);
            };

            FPGA.Config.OnSignal(trigger, handler);
        }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            Sequential handler = () =>
            {
                while (true)
                {
                    byte start = UART.Read(115200, RXD);

                    for (uint counter = 0; counter < 100; counter++)
                    {
                        ulong fib = 0;
                        SequentialMath.Fibonacci(counter, out fib);

                        if (fib > uint.MaxValue)
                        {
                            break;
                        }

                        bool isPrime = false;
                        SequentialMath.IsPrime((uint)fib, out isPrime);

                        if (isPrime)
                        {
                            for (byte i = 0; i < 4; i++)
                            {
                                byte data = (byte)fib;
                                UART.Write(115200, data, TXD);
                                fib = fib >> 8;
                            }
                        }
                    }
                }
            };

            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, handler);
        }
Example #5
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            Sequential handler = () =>
            {
                byte  data = 0;
                ulong tmp = 0;
                ulong op1 = 0, op2 = 0;

                for (byte i = 0; i < 2; i++)
                {
                    for (byte j = 0; j < 8; j++)
                    {
                        UART.Read(115200, RXD, out data);
                        tmp = ((ulong)data << 56) | (tmp >> 8);
                    }

                    if (i == 0)
                    {
                        op1 = tmp;
                    }
                    else
                    {
                        op2 = tmp;
                    }
                }

                tmp = op1 + op2;

                for (byte j = 0; j < 8; j++)
                {
                    UART.Write(115200, (byte)tmp, TXD);
                    tmp = tmp >> 8;
                }
            };
            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, handler);
        }
Example #6
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            Sequential handler = () =>
            {
                ulong tmp = 0;
                ulong op1 = 0, op2 = 0;

                for (byte i = 0; i < 2; i++)
                {
                    for (byte j = 0; j < 8; j++)
                    {
                        byte data = UART.Read(115200, RXD);
                        tmp = ((ulong)data << 56) | (tmp >> 8);
                    }

                    if (i == 0)
                    {
                        op1 = tmp;
                    }
                    else
                    {
                        op2 = tmp;
                    }
                }

                FunctionalTest.Pipeline_Pipelined64BitAdder.PipelinedAdder(op1, op2, out tmp);

                for (byte j = 0; j < 8; j++)
                {
                    UART.Write(115200, (byte)tmp, TXD);
                    tmp = tmp >> 8;
                }
            };
            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, handler);
        }
Example #7
0
        private void bntReady_Click(object sender, EventArgs e)
        {
            try
            {
                UART.Write("D");
                CountDown.Stop();
                Watch.Stop();
                TimerWatch.Stop();
                TimerWatch2.Stop();
                //if (bntMode.Text == "MODE 1")
                //    UART.Write("1");
                //else if (bntMode.Text == "MODE 2")
                //    UART.Write("2");

                isPass           = false;
                isFinish         = false;
                isPass2          = false;
                isFinish2        = false;
                bntReady.Enabled = false;
                bntStart.Enabled = true;
            }
            catch { }

            if (int.Parse(tbCount.Text) > 0)
            {
                cntGo = int.Parse(tbCount.Text);
            }
            else
            {
                cntGo = 5;
            }

            this.lbCountDown.Text = cntGo.ToString("00") + "  READY";
            this.lbWatch1.Text    = "00:00:000";
            this.lbWatch2.Text    = "00:00:000";
            frm.lbCountDown.Text  = cntGo.ToString("00") + "  READY";
            frm.lbWatch.Text      = "00:00:000";

            lbStripStatus.Text = "READY";
        }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            Controllers.eShiftCommand cmd = 0;

            Sequential readHandler = () =>
            {
                byte data = 0;
                UART.Read(115200, RXD, out data);
                cmd = (eShiftCommand)data;
            };
            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, readHandler);

            byte write = 0;

            FPGA.Signal <bool> dataWritten = false;

            Sequential writeHandler = () =>
            {
                UART.Write(115200, write, TXD);
                dataWritten = true;
            };

            FPGA.Config.OnRegisterWritten(write, writeHandler);

            Sequential cmdHandler = () =>
            {
                byte result = 0;
                ValueForCommand(cmd, out result);

                write = result;
                FPGA.Runtime.WaitForAllConditions(dataWritten);
            };

            FPGA.Config.OnRegisterWritten(cmd, cmdHandler);
        }
Example #9
0
        public static unsafe void Clear()
        {
            if (!Initialised)
            {
                return;
            }

            //Clear out every character on the screen
            int numToClear = rows * cols;

#if MIPS
            //Loop through all video memory
            while (numToClear > 0)
            {
                //Set output to no character, no foreground colour, just the
                //  background colour.
                UART.Write(' ');
                //And decrement the count
                numToClear--;
            }
#elif x86
            //Start at beginning of video memory
            char *vidMemPtr = vidMemBasePtr;
            //Loop through all video memory
            while (numToClear > 0)
            {
                //Set output to no character, no foreground colour, just the
                //  background colour.
                vidMemPtr[0] = bg_colour;
                //Then move to the next character in
                //  video memory.
                vidMemPtr++;
                //And decrement the count
                numToClear--;
            }

            //And set our offset to 0
            offset = 0;
#endif
        }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            Sequential handler = () =>
            {
                FPU.FPUScopeNoSync();

                while (true)
                {
                    float data = 0;
                    UART.ReadFloat(115200, RXD, out data);

                    data = FPGATrigonometryTools.TaylorSin(data);

                    UART.WriteFloat(115200, data, TXD);
                }
            };

            FPGA.Config.OnStartup(handler);
        }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            const uint baud = 115200;

            Sequential handler = () =>
            {
                FPU.FPUScopeNoSync();

                while (true)
                {
                    float data = 0;
                    UART.ReadFloat(baud, RXD, out data);

                    var result = (long)ReturnExpression(data);
                    UART.WriteUnsigned64(baud, (ulong)result, TXD);
                }
            };

            FPGA.Config.OnStartup(handler);
        }
Example #12
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            const uint baud = 115200;

            Sequential handler = () =>
            {
                FPU.FPUCastNoSync();

                while (true)
                {
                    ulong data = 0;
                    UART.ReadUnsigned64(baud, RXD, ref data);

                    var floatCast = (float)(long)data;
                    UART.WriteFloat(baud, floatCast, TXD);
                }
            };

            FPGA.Config.OnStartup(handler);
        }
Example #13
0
        private void CountDown_Tick(object sender, EventArgs e)
        {
            cntGo--;
            this.lbCountDown.Text = cntGo.ToString("00") + "  READY";
            frm.lbCountDown.Text  = cntGo.ToString("00  READY");

            if (cntGo == 0)
            {
                TimerWatch2.Reset();
                TimerWatch.Reset();
                UART.Write("O");          // OPEN
                UART.Write("G");          // OPEN

                this.lbCountDown.Text = "GO !!!";
                frm.lbCountDown.Text  = "GO !!!";
                bntGate.Text          = "CLOSE";

                CountDown.Stop();
                Watch.Start();

                lbStripStatus.Text = "Timer is starting.";
            }
        }
Example #14
0
        //----------------------------------------------
        //....................BUTON.....................
        //----------------------------------------------

        private void bntMode_Click(object sender, EventArgs e)
        {
            if (bntMode.Text == "MODE 1")
            {
                UART.Write("1");
                bntMode.Text = "MODE 2";
                state        = 1;
                lbWatch2.Hide();
                btn_team_2.Hide();
                textBox_name_team_2.Hide();
                btn_both.Hide();
            }
            else if (bntMode.Text == "MODE 2")
            {
                UART.Write("2");
                bntMode.Text = "MODE 1";
                state        = 2;
                lbWatch2.Show();
                btn_team_2.Show();
                textBox_name_team_2.Show();
                btn_both.Show();
            }
        }
        private void BtnDisconnect_Click(object sender, EventArgs e)
        {
            try
            {
                if (UART.IsOpen)
                {
                    while (UART.BytesToWrite > 0)
                    {
                    }
                    UART.DiscardInBuffer();
                    UART.Dispose();
                    UART.Close();

                    btnConnect.Enabled    = true;
                    btnDisconnect.Enabled = false;
                    lblStatus.Text        = "Port is closed !";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);

            Sequential mainHandler = () =>
            {
                byte   data = 0;
                byte[] buff = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };

                UART.Read(115200, RXD, out data);

                for (byte i = 0; i < buff.Length; i++)
                {
                    byte tmp = 0;
                    tmp     = buff[i];
                    tmp    += data;
                    buff[i] = tmp;

                    UART.RegisteredWrite(115200, tmp, out internalTXD);
                }

                for (byte jjj = 0; jjj < buff.Length; jjj++)
                {
                    buff[jjj] = jjj;
                }
                ;
            };

            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, mainHandler);
        }
Example #17
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            Sequential handler = () =>
            {
                byte data = UART.Read(115200, RXD);

                Func <byte>        dFunc       = () => (byte)(data * 2);
                FPGA.Signal <bool> writeEnable = false;

                FPGA.Register <byte> result = new FPGA.Register <byte>(0);

                FPGA.Config.RegisterOverride(result, dFunc, writeEnable);

                FPGA.Runtime.Assign(FPGA.Expressions.AssignSignal(true, writeEnable));

                UART.Write(115200, result, TXD);
            };
            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, handler);
        }
 private void BtnConnect_Click(object sender, EventArgs e)
 {
     try
     {
         if (UART.IsOpen == true)
         {
             UART.DiscardInBuffer();
             UART.Close();
         }
         UART.PortName = cbxCom.Text;
         UART.Open();
         lblStatus.Text = "PC is connecting with " + UART.PortName.ToString();
         if (UART.IsOpen == true)
         {
             btnConnect.Enabled    = false;
             btnDisconnect.Enabled = true;
             btnStart.Enabled      = true;
         }
     }
     catch
     {
         MessageBox.Show("Bạn chưa chọn cổng COM !");
     }
 }
Example #19
0
        public void BindAnalyzer(IOProvider io)
        {
            this.io      = io;
            io.ByteRead += b =>
            {
                if (!TimeDomainsManager.Instance.TryGetVirtualTimeStamp(out var vts))
                {
                    // it happens when writing from uart analyzer
                    vts = new TimeStamp(default(TimeInterval), EmulationManager.ExternalWorld);
                }

                UART.GetMachine().HandleTimeDomainEvent(UART.WriteChar, (byte)b, vts);
            };

            Action <byte> writeAction = (b =>
            {
                lock (lockObject)
                {
                    io.Write(b);
                }
            });

            var mre = new ManualResetEventSlim();

            Task.Run(() =>
            {
                lock (lockObject)
                {
                    mre.Set();
                    RepeatHistory();
                    UART.CharReceived += writeAction;
                    actionsDictionary.Add(io, writeAction);
                }
            });
            mre.Wait();
        }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            const int  baud    = 115200;
            Sequential handler = () =>
            {
                while (true)
                {
                    byte op = UART.Read(baud, RXD);

                    uint op1 = 0, op2 = 0;
                    UART.ReadUnsigned32(baud, RXD, ref op1);
                    UART.ReadUnsigned32(baud, RXD, ref op2);

                    var result = TestMethod(op, (int)op1, (int)op2);

                    UART.WriteUnsigned64(baud, (ulong)result, TXD);
                }
            };

            FPGA.Config.OnStartup(handler);
        }
Example #21
0
        /// <summary>
        /// Created to receive the telemetry events from the full system test
        /// </summary>
        private static void ReceiveTelemetryEvents()
        {
            int    fileNum = 1;
            string subDir  = Path.Combine(Directory.GetCurrentDirectory(), $"FullSystemSharedRTC_{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}");

            Directory.CreateDirectory(subDir);

            string port = SerialPort.GetPortNames().First();

            string fileName = Path.Combine(subDir, $"file{fileNum}.txt");

            bool isReading = true;

            try
            {
                using (UART telemetry = new UART(port))
                {
                    //telemetry.Open();
                    //ReliableSerialPort.DataReceivedEventHandler handler = new ReliableSerialPort.DataReceivedEventHandler(Event);
                    //telemetry.DataReceived += handler;

                    telemetry.Subscribe((s, e) =>
                    {
                        SerialPort port = (SerialPort)s;

                        string line = port.ReadLine();
                        Console.WriteLine(line);

                        if (line == EOP)
                        {
                            isReading = false;
                        }
                        else
                        {
                            fileQueue.Enqueue(line);
                        }
                    });

                    CancellationTokenSource source = new CancellationTokenSource();
                    source.CancelAfter(1000 * 10 * 60); //run for 10 minutes
                    Console.WriteLine("Starting to read from telemetry for 10 minutes");


                    int lineNumber = 1;

                    while (!source.IsCancellationRequested)
                    {
                        if (!fileQueue.IsEmpty && fileQueue.TryDequeue(out string line))
                        {
                            if (line == EOP)
                            {
                                isReading = false;
                            }
                            else
                            {
                                using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
                                {
                                    using (StreamWriter writer = new StreamWriter(fs))
                                    {
                                        writer.WriteLine(line);
                                        lineNumber++;
                                    }
                                }
                            }


                            if (lineNumber >= 1000000)
                            {
                                Console.WriteLine($"Saved {fileNum++} files so far!");
                                fileName   = Path.Combine(subDir, $"file{fileNum}.txt");
                                lineNumber = 1;
                            }
                        }
                    }
                    telemetry.Unsubscribe();
                    Console.WriteLine("Program Finished Successfully!");

                    //telemetry.DataReceived -= handler;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Whoops!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    Console.WriteLine("Inner exception details:");
                    Console.WriteLine(ex.InnerException.Message);
                    Console.WriteLine(ex.InnerException.StackTrace);
                }
            }
        }
Example #22
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            const int baud = 115200;

            uint clockCounter = 0;

            Diag.ClockCounter(clockCounter);

            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);

            byte  testOp;
            float op1, op2, res = 0;

            Sequential handler = () =>
            {
                FPU.FPUScope();

                while (true)
                {
                    uint start = 0, end = 0;
                    res = 0;

                    UART.Read(baud, RXD, out testOp);
                    UART.ReadFloat(baud, RXD, out op1);
                    UART.ReadFloat(baud, RXD, out op2);

                    switch ((FPUTimingType)testOp)
                    {
                    case FPUTimingType.Add:
                        start = clockCounter;
                        res   = op1 + op2;
                        end   = clockCounter;
                        break;

                    case FPUTimingType.Sub:
                        start = clockCounter;
                        res   = op1 - op2;
                        end   = clockCounter;
                        break;

                    case FPUTimingType.Mul:
                        start = clockCounter;
                        res   = op1 * op2;
                        end   = clockCounter;
                        break;

                    case FPUTimingType.Div:
                        start = clockCounter;
                        res   = op1 / op2;
                        end   = clockCounter;
                        break;

                    default:
                        start = clockCounter;
                        end   = clockCounter;
                        break;
                    }
                    UART.RegisteredWriteFloat(baud, res, out internalTXD);
                    UART.RegisteredWriteUnsigned32(baud, end - start, out internalTXD);
                }
            };

            FPGA.Config.OnStartup(handler);
        }
Example #23
0
        private void bntConnect_Click(object sender, EventArgs e)
        {
            if (bntConnect.Text == "CONNECT")
            {
                try
                {
                    if (cbCom.Text == "" || cbBaur.Text == "")
                    {
                        lbStripStatus.Text = "Please select PORT setting.";
                    }
                    else
                    {
                        UART.PortName = cbCom.Text;
                        UART.BaudRate = Convert.ToInt32(cbBaur.Text);
                        UART.Open();
                        progressBar.Value = 100;

                        UART.Write("R");

                        if (bntMode.Text == "MODE 1")
                        {
                            UART.Write("2");
                        }
                        else if (bntMode.Text == "MODE 2")
                        {
                            UART.Write("1");
                        }


                        lbStripStatus.Text = "CONNECT TO " + UART.PortName;
                        bntConnect.Text    = "DISCONNECT";

                        cbCom.Enabled    = false;
                        cbBaur.Enabled   = false;
                        bntGate.Enabled  = true;
                        bntReset.Enabled = true;
                        bntReady.Enabled = true;
                        bntSend.Enabled  = true;
                        bntMode.Enabled  = true;
                        tbTx.Enabled     = true;
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    lbStripStatus.Text = "Unauthor Access.";
                }
            }
            else
            {
                progressBar.Value = 0;
                UART.Write("R");
                UART.Close();



                CountDown.Stop();
                Watch.Stop();
                TimerWatch.Stop();
                lbCountDown.Text = "READY";
                lbWatch1.Text    = "00:00:000";
                lbWatch2.Text    = "00:00:000";

                bntConnect.Text = "CONNECT";
                cbCom.Enabled   = true;
                cbBaur.Enabled  = true;

                bntGate.Enabled  = false;
                bntReady.Enabled = false;
                bntStart.Enabled = false;
                bntSend.Enabled  = false;
                bntMode.Enabled  = false;
                tbTx.Enabled     = false;
            }
        }
Example #24
0
        //_____________________________________________________________
        //
        //_____________________________________________________________

        private void Watch_Tick(object sender, EventArgs e)
        {
            if (isFinish == true && state == 1)
            {
                try
                {
                    CountDown.Stop();
                    Watch.Stop();
                    TimerWatch.Stop();
                    min                = TimerWatch.Elapsed.Minutes;
                    sec                = TimerWatch.Elapsed.Seconds;
                    milisec            = TimerWatch.Elapsed.Milliseconds;
                    this.lbWatch1.Text = min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000");
                    System.IO.File.WriteAllText("result\\" + textBox_name_team_1.Text + ".txt", "Team " + textBox_name_team_1.Text + ":\nCheck point " + check_point.ToString() + ": " + min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000"));
                    UART.Write("F");
                } catch { }


                this.lbCountDown.Text = "FINISH !!!";
                frm.lbCountDown.Text  = "FINISH !!!";
            }

            if (isFinish == true && state == 2)
            {
                try
                {
                    TimerWatch.Stop();
                    min                = TimerWatch.Elapsed.Minutes;
                    sec                = TimerWatch.Elapsed.Seconds;
                    milisec            = TimerWatch.Elapsed.Milliseconds;
                    this.lbWatch2.Text = min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000");
                    System.IO.File.WriteAllText("result\\" + textBox_name_team_1.Text + ".txt", "Team " + textBox_name_team_1.Text + ":\nCheck point " + check_point.ToString() + ": " + min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000"));
                }
                catch { }


                this.lbCountDown.Text = "PLAYER 1 FINISH !!!";
                frm.lbCountDown.Text  = "PLAYER 1 FINISH !!!";
            }

            if (isFinish2 == true && state == 2)
            {
                try
                {
                    TimerWatch2.Stop();
                    min     = TimerWatch2.Elapsed.Minutes;
                    sec     = TimerWatch2.Elapsed.Seconds;
                    milisec = TimerWatch2.Elapsed.Milliseconds;
                    System.IO.File.WriteAllText("result\\" + textBox_name_team_2.Text + ".txt", "Team " + textBox_name_team_2.Text + ":\nCheck point " + check_point2.ToString() + ": " + min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000"));
                }
                catch { }


                this.lbCountDown.Text = "PLAYER 2 FINISH !!!";
                frm.lbCountDown.Text  = "PLAYER 2 FINISH !!!";
            }

            if (isFinish2 == true && isFinish == true && state == 2)
            {
                try
                {
                    Watch.Stop();
                    UART.Write("F");
                }
                catch { }


                this.lbCountDown.Text = "FINISH !!!";
                frm.lbCountDown.Text  = "FINISH !!!";
            }

            if (isFinish == false)
            {
                min     = TimerWatch.Elapsed.Minutes;
                sec     = TimerWatch.Elapsed.Seconds;
                milisec = TimerWatch.Elapsed.Milliseconds;

                this.lbWatch1.Text = min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000");
                frm.lbWatch.Text   = min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000");
            }

            if (isFinish2 == false)
            {
                min     = TimerWatch2.Elapsed.Minutes;
                sec     = TimerWatch2.Elapsed.Seconds;
                milisec = TimerWatch2.Elapsed.Milliseconds;

                this.lbWatch2.Text = min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000");
                frm.lbWatch.Text   = min.ToString("00") + ":" + sec.ToString("00") + "." + milisec.ToString("000");
            }
        }
Example #25
0
 private void bntSend_Click(object sender, EventArgs e)
 {
     UART.Write(tbTx.Text);
 }
Example #26
0
        ////ST, GS,+    0.0 g
        ////ST, GS,+  106.9 g
        ////US, GS,+    1.2 g

        /// <summary>
        /// Return null if device is not connect
        /// </summary>
        /// <returns></returns>
        public static string GetWeight()
        {
            if (device != null)
            {
                device.Close();
            }
            device = new UART();
            device.Open(
                MyGlobal.MySetting.SerialPortName,
                MyGlobal.MySetting.SerialBaudRate,
                MyGlobal.MySetting.SerialDataBits,
                myConverter.FromStringToSerialParity(MyGlobal.MySetting.SerialParity),
                myConverter.FromStringToSerialStopBits(MyGlobal.MySetting.SerialStopBits)
                );

            if (device == null)
            {
                return(null);
            }
            if (device.IsConnected() == false)
            {
                return(null);
            }

            int count = 0;

REP:
            count++;
            //clear serial receive buffer
            string data = null;

            device.Read();

            int wait_time; bool r = int.TryParse(MyGlobal.MySetting.WaitTime, out wait_time);

            wait_time = r ? wait_time : 100;
            Thread.Sleep(wait_time);

            //get data newest
            data = device.Read();

            //process data
            string value = null;
            string sign  = "";

            if (data.Contains("\r\n"))
            {
                string[] buffer = data.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                value = buffer[buffer.Length - 2].Trim();

                try {
                    buffer = value.Split(',');
                    value  = buffer[2].Replace("g", "").Replace("-", "").Replace("+", "").Trim();
                    sign   = buffer[2].Contains("-") ? "-" : "";
                    value  = sign + value;
                }
                catch {
                    if (count < 3)
                    {
                        goto REP;
                    }
                }
            }
            device.Close();

            if (count >= 3)
            {
                return(null);
            }
            else
            {
                return(value);
            }
        }
Example #27
0
 static void serial_OnStateChange(UART.EDeviceState state, SerialManager sm)
 {
     if (state == EDeviceState.Online || state == EDeviceState.PortOpen)
     {
         Info(sm.PortName + " -> " + state);
         return;
     }
     if (state == EDeviceState.Offline)
     {
         Serials.Remove(sm.PortName);
         Warn(sm.PortName + " -> " + state);
         return;
     }
     if (state == EDeviceState.Error)
     {
         Error(sm.PortName + " -> " + state);
         return;
     }
     Log(sm.PortName + " -> " + state);
 }
Example #28
0
        public static void DeviceControl(
            FPGA.OutputSignal <bool> DOUT,
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);
            object commsLock = new object();

            bool internalDOUT = false;

            FPGA.Config.Link(internalDOUT, DOUT);

            const uint baud = 115200;

            FPGA.SyncStream <uint> heartBeat = new FPGA.SyncStream <uint>();

            const int servosCount = 5;

            byte[] servosBuff = new byte[servosCount];

            Sequential servosHandler = () =>
            {
                FPGA.OutputSignal <bool> ServoItem = new FPGA.OutputSignal <bool>();
                bool servoOut = false;
                FPGA.Config.Link(servoOut, ServoItem);

                while (true)
                {
                    uint idx       = FPGA.Config.InstanceId();
                    byte servoData = 0;
                    servoData = servosBuff[idx];

                    MG996R.Write(servoData, out servoOut);
                }
            };

            FPGA.Config.OnStartup(servosHandler, servosCount);


            // SERVOs driver
            Sequential <uint> servosDataHandler = (iteration) =>
            {
                byte data = 0;

                lock (commsLock)
                {
                    UART.RegisteredWrite(baud, 2, out internalTXD);

                    for (int i = 0; i < servosCount; i++)
                    {
                        data          = UART.Read(baud, RXD);
                        servosBuff[i] = data;
                    }
                }
            };

            FPGA.Config.OnStream(heartBeat, servosDataHandler);

            // LED driver
            Sequential <uint> ledHandler = (iteration) =>
            {
                uint   data = 0;
                uint[] buff = new uint[64];

                lock (commsLock)
                {
                    UART.RegisteredWrite(baud, 1, out internalTXD);

                    for (int i = 0; i < buff.Length; i++)
                    {
                        UART.ReadUnsigned32(baud, RXD, ref data);
                        buff[i] = data;
                    }
                }

                WS2812B.SyncWrite(buff, 0, buff.Length, out internalDOUT);
            };

            FPGA.Config.OnStream(heartBeat, ledHandler);


            // main application driver
            uint       beat             = 0;
            Sequential heartBeatHandler = () =>
            {
                heartBeat.Write(beat);
                beat++;
            };

            FPGA.Config.OnTimer(TimeSpan.FromMilliseconds(100), heartBeatHandler);
        }
Example #29
0
 static void serial_OnStateChange(UART.EDeviceState state, SerialManager sm)
 {
     Console.WriteLine("UART -> " + state);
 }
Example #30
0
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // banks
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,
            FPGA.OutputSignal <bool> Bank5,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);
            QuokkaBoard.OutputBank(Bank5);
            IsAlive.Blink(LED1);

            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);

            const int servosCount = 3;

            byte[] servosData = new byte[servosCount];

            Sequential servoHandler = () =>
            {
                uint instanceId     = FPGA.Config.InstanceId();
                var  servoOutputPin = new FPGA.OutputSignal <bool>();
                byte value          = 0;
                bool servoOutput    = false;
                byte requestValue   = 0;

                FPGA.Config.Link(servoOutput, servoOutputPin);

                while (true)
                {
                    requestValue = servosData[instanceId];

                    if (requestValue != value)
                    {
                        if (requestValue < value)
                        {
                            value--;
                        }
                        else
                        {
                            value++;
                        }
                    }

                    MG996R.Write(value, out servoOutput);
                }
            };

            FPGA.Config.OnStartup(servoHandler, servosCount);

            Sequential readHandler = () =>
            {
                byte data    = 0;
                byte counter = 0;
                while (true)
                {
                    data = UART.Read(115200, RXD);
                    if (data == 255 || counter == 255)
                    {
                        // begin of packet or overflow
                        counter = 0;
                    }
                    else
                    {
                        if (counter < servosCount)
                        {
                            servosData[counter] = data;
                        }

                        counter++;
                    }
                }
            };

            FPGA.Config.OnStartup(readHandler);
        }
 public Form1()
 {
     InitializeComponent();
     rs232 = new UART();
 }
Example #32
0
        public static bool Output(LampStatus lampstatus)
        {
            try {
                if (thrlamp != null)
                {
                    if (thrlamp.IsAlive == true)
                    {
                        thrlamp.Abort();
                        device.Write("0");
                        Thread.Sleep(100);
                        device.Close();
                    }
                }

                if (device != null)
                {
                    device.Close();
                }
                device = new UART();
                device.Open(
                    MyGlobal.MySetting.LampPortName,
                    MyGlobal.MySetting.LampBaudRate,
                    MyGlobal.MySetting.LampDataBits,
                    myConverter.FromStringToSerialParity(MyGlobal.MySetting.LampParity),
                    myConverter.FromStringToSerialStopBits(MyGlobal.MySetting.LampStopBits)
                    );

                if (device == null)
                {
                    return(false);
                }
                if (device.IsConnected() == false)
                {
                    return(false);
                }

                int _ref = (int)lampstatus;
                switch (_ref)
                {
                case -1: {
                    MyGlobal.OutputLamp = "0";         // off all lamp
                    break;
                }

                case 0: {
                    MyGlobal.OutputLamp = "p";         //on led green
                    break;
                }

                case 1: {
                    MyGlobal.OutputLamp = "f";         //on led red
                    break;
                }

                case 2: {
                    MyGlobal.OutputLamp = "w";         //on led yellow
                    break;
                }

                default: {
                    MyGlobal.OutputLamp = "0";
                    break;
                }
                }

                thrlamp = new Thread(new ThreadStart(() => {
                    if (MyGlobal.OutputLamp == "0")
                    {
                        device.Write("0");
                        Thread.Sleep(100);
                        device.Close();
                    }
                    else
                    {
                        device.Write(MyGlobal.OutputLamp);
                        int delay = MyGlobal.OutputLamp == "p" ? 500 : 3000;
                        Thread.Sleep(delay);
                        device.Write("0");
                        Thread.Sleep(100);
                        device.Close();
                    }
                }));
                thrlamp.IsBackground = true;
                thrlamp.Start();

                return(true);
            }
            catch {
                return(false);
            }
        }