Ejemplo n.º 1
0
        public void sendMessage(canSendWorker item)
        {
            // send
            if (!CanTool.SendCanMessage(item.Params.Message, 1, item.Params.MessageType == canMessageType.rtr))
            {
                stopAll();
                return;
            }
            // gui update
            var row = getRow(item);

            row.Cells[m_colCount.Index].Value = item.CountSent + 1;
        }
Ejemplo n.º 2
0
        // context menu callback
        private void onContextMenuClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            string selected = e.ClickedItem.Text.ToLower();

            // hide
            contextMenu.Hide();

            if (selected == "hide backlighted")
            {
                grid.hideBacklighedMessages();
            }
            if (selected == "hide all but backlighted")
            {
                grid.hideAllButBacklighted();
            }
            if (selected == "hide selected")
            {
                grid.hideSelected();
            }
            if (selected == "hide all but selected")
            {
                grid.hideAllMessagesButSelected();
            }
            if (selected == "unhide all")
            {
                grid.unhideAll();
            }
            if (selected == "hide all")
            {
                grid.hideAll();
            }
            if (selected == "toggle checkbox for all")
            {
                grid.toggleCheckProperty();
            }
            if (selected == "toggle checkbox for selected")
            {
                grid.toggleCheckPropertySelected();
            }
            if (selected == "copy all" || selected == "copy selected")
            {
                bool   sel_only = selected.Contains("selected");
                string txt      = getMessageString(sel_only);
                Clipboard.SetText(txt);
            }
            if (selected == "save all" || selected == "save selected")
            {
                // save
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.DefaultExt      = "txt";
                dlg.AddExtension    = true;
                dlg.CheckPathExists = true;
                dlg.Filter          = "CAN Analyzer message list|*txt";
                dlg.OverwritePrompt = true;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    bool   sel_only = selected.Contains("selected");
                    string txt      = getMessageString(sel_only);
                    System.IO.File.WriteAllText(dlg.FileName, txt);
                }
            }
            if (selected == "copy all as script")
            {
                List <canMessage2> ls  = grid.getMessageList(false);
                string             txt = nsScriptParser.scriptParser.message2string(ls);
                Clipboard.SetText(txt);
            }
            if (selected == "copy selected as script")
            {
                List <canMessage2> ls  = grid.getMessageList(true);
                string             txt = nsScriptParser.scriptParser.message2string(ls);
                Clipboard.SetText(txt);
            }
            if (selected == "copy selected for remoto")
            {
                List <canMessage2> ls  = grid.getMessageList(true);
                string             txt = Tools.ConvertMessageToRemotoCmd(ls);
                Clipboard.SetText(txt);
            }
            if (selected == "send selected")
            {
                List <canMessage2> ls = grid.getMessageList(true);
                CanTool.SendCanMessage(ls);
            }
        }
Ejemplo n.º 3
0
 // send a request
 private bool sendRequest(canMessage2 req)
 {
     return(m_self_test ? true : m_can_tool.SendCanMessage(req));
 }
        private void onWorker()
        {
            // we're using this time for can sleep detection
            DateTime dtScanStarted = DateTime.Now;
            // and this one for trace only
            DateTime dtTrace = DateTime.Now;

            while (stage != scanStage.pause)
            {
                if (stage == scanStage.waitingForCanSleep)
                {
                    var diffInSeconds = (DateTime.Now - dtLastCanMsg).TotalMilliseconds;
                    if (diffInSeconds > butSleepTmo)
                    {
                        stage         = scanStage.scanning;
                        dtScanStarted = DateTime.Now;
                        continue;
                    }

                    Thread.Sleep(500);
                }
                else if (stage == scanStage.scanning)
                {
                    // send
                    CanTool.SendCanMessage(message, messageCountToSend);
                    trace(idCurrent);

                    // wait
                    Thread.Sleep(messageCountToSend + messageCountToSend / 2);

                    // check date time
                    if (dtScanStarted < dtLastCanMsg)
                    {
                        trace("A new CAN message has received");
                        trace("Waiting untill the CAN bus is sleeping again");
                        // a message has received
                        stage = scanStage.waitingForCanSleepAfterScanning;
                        continue;
                    }

                    // update
                    if (idCurrent == idStop)
                    {
                        stage = scanStage.pause;
                        trace("Failed. The low border has reached.");
                        continue;
                    }
                    else
                    {
                        idCurrent = idStart > idStop ? idCurrent - 1 : idCurrent + 1;
                        //message.Id.Id = (int)idCurrent;
                        message = new canMessage2((int)idCurrent, message.Id.Is29bit, message.Data);
                    }
                }
                else if (stage == scanStage.waitingForCanSleepAfterScanning)
                {
                    var diffInSeconds = (DateTime.Now - dtLastCanMsg).TotalMilliseconds;
                    if (diffInSeconds > butSleepTmo)
                    {
                        stage         = scanStage.checking;
                        dtScanStarted = DateTime.Now;
                        trace("Can Bus is sleeping again");
                        continue;
                    }

                    Thread.Sleep(500);
                }
                else if (stage == scanStage.checking)
                {
                    // send data in the reverse direction
                    CanTool.SendCanMessage(message, messageCountToSend);
                    trace(idCurrent);


                    // wait for idCheckTmo msec
                    trace("Waiting for " + idCheckTmo.ToString() + " msec");
                    Thread.Sleep(idCheckTmo);

                    // check date time
                    if (dtScanStarted < dtLastCanMsg)
                    {
                        // a message has received
                        trace("Done");
                        trace(string.Format("Activation ID is: {0}", message.Id.GetIdAsString()));
                        stage = scanStage.pause;
                        continue;
                    }

                    idCurrent = idStart > idStop ? idCurrent + 1 : idCurrent - 1;
                    //message.Id = (int)idCurrent;
                    message = new canMessage2((int)idCurrent, message.Id.Is29bit, message.Data);
                }
            }

            double elapsed  = (DateTime.Now - dtTrace).TotalMilliseconds / 1000.0d;;
            string sElapsed = elapsed.ToString("0.000");

            trace(string.Format("Elapsed Time: {0} sec", sElapsed));

            // end of while
            guiStartStop();
        }