예제 #1
0
        private async void btn_addPort_Click(object sender, EventArgs e)
        {
            if (IPSelected == null)
            {
                MessageBox.Show("Chưa chọn IP!");
                return;
            }
            if (txt_portNumber.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa nhập port!");
                return;
            }
            if (txt_language.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa nhập language!");
                return;
            }

            this.Enabled = false;
            bool success = false;
            int  loop    = 0;

            do
            {
                if (loop == 10)
                {
                    break;
                }
                try
                {
                    Port port = new Port();
                    port.portNumber = txt_portNumber.Text;
                    port.active     = rb_active_true.Checked;
                    port.data       = rb_data_true.Checked;
                    port.die        = rb_die_true.Checked;
                    port.port       = rb_port_true.Checked;
                    port.language   = Int32.Parse(txt_language.Text);

                    PortConnection portConn = new PortConnection(IPSelected.ipAddress);
                    await portConn.Insert(port);

                    success = true;

                    loadPortWithWaitForm();
                    resetInputPort();
                }
                catch
                {
                    loop++;
                    Thread.Sleep(2000);
                }
            } while (!success);

            if (!success)
            {
                MessageBox.Show("Đã thử " + loop + " lần mà *** đc :))");
                this.Enabled = true;
            }
            this.Enabled = true;
        }
예제 #2
0
        private void loadPort(string portNumberSelected)
        {
            lv_port.Items.Clear();
            lv_link.Items.Clear();

            if (ip == null)
            {
                return;
            }

            PortConnection            portConn = new PortConnection(ip.ipAddress);
            Dictionary <string, Port> lst      = new Dictionary <string, Port>();

            lst = Task.Run(() => portConn.GetAll()).Result;

            foreach (Port port in lst.Values)
            {
                ListViewItem item = new ListViewItem(ip.ipAddress.Replace("_", "."));
                item.SubItems.Add(port.portNumber);
                item.SubItems.Add(port.active.ToString());
                item.SubItems.Add(port.data.ToString());
                item.SubItems.Add(port.die.ToString());
                item.SubItems.Add(port.port.ToString());

                if (portNumberSelected != null && port.portNumber == portNumberSelected)
                {
                    item.BackColor = Color.Blue;
                }
                lv_port.Items.Add(item);
            }
        }
예제 #3
0
        public void SwitchConnections(int a, int b)
        {
            PortConnection c = connections[a];

            connections[a] = connections[b];
            connections[b] = c;
        }
예제 #4
0
        private async Task Run()
        {
            PortConnection portConn = new PortConnection(ip.ipAddress);
            Port           port     = Task.Run(() => portConn.GetNextPort(previousPortNumber)).Result;

            if (port == null)
            {
                addLog(true, ip.ipAddress, null, "not found next port!");
                return;
            }

            loadPort(port.portNumber);
            if (port.links != null && port.links.Count > 0)
            {
                loadLink(port.portNumber, 0);
            }

            //Set để chạy port kế tiếp khi làm xong
            previousPortNumber = port.portNumber;
            //Chạy port
            string ipAddress = ip.ipAddress, portNumber = port.portNumber;

            addLog(true, ipAddress, portNumber, "run port!");

            if (!port.active || !port.data || !port.die || !port.port)
            {
                addLog(true, ipAddress, portNumber, "port not active!");
                return;
            }

            //Lay link dau tien cua port
            LinkConnection linkConn = new LinkConnection(ipAddress, portNumber);
            Link           link     = Task.Run(() => linkConn.GetFirstElement()).Result;

            addLog(true, ipAddress, portNumber, "run link: " + link.link);
            addLog(true, ipAddress, portNumber, "\tdelete link on database!");

            //Xoa link
            await linkConn.Delete(link.key);

            //Update port
            link = Task.Run(() => linkConn.GetFirstElement()).Result;
            if (link == null)
            {
                port        = Task.Run(() => portConn.GetWithKey(portNumber)).Result;
                port.data   = false;
                port.active = false;
                //update port
                await portConn.Update(port);
            }

            //Thit
            //.....
            addLog(true, ipAddress, portNumber, "\tstep 1!");
            addLog(true, ipAddress, portNumber, "\tstep 2!");
            addLog(true, ipAddress, portNumber, "\tstep ...!");
            addLog(true, ipAddress, portNumber, "\tstep n!");
        }
예제 #5
0
        public void Viewport_MouseDown(MouseButtonEventArgs e, Point sceneCursorPosition)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                /* Add Connection Line command started */
                if (this.AddConnectionLineActive == true)
                {
                    Object selectedObject = null;

                    bool clicked;


                    clicked = AutosarApplication.GetInstance().ActiveComposition.GetClickedObject(sceneCursorPosition, out selectedObject);

                    /* if we check in main composition */
                    if (!clicked)
                    {
                        CompositionInstance mainComposition = AutosarApplication.GetInstance().Compositions.GetMainComposition();
                        foreach (CompositionInstance composition in AutosarApplication.GetInstance().Compositions)
                        {
                            if (!composition.Equals(mainComposition))
                            {
                                clicked = composition.IsClicked(sceneCursorPosition, out selectedObject);
                                if (clicked == true)
                                {
                                    break;
                                }
                            }
                        }
                    }



                    if (clicked == true)
                    {
                        /* Check that PortPainter has been selected  first */
                        if (selectedObject is PortPainter)
                        {
                            firstPort                     = selectedObject as PortPainter;
                            connectionPainter             = PortConnectionFabric.GetInstance().CreatePortConnection();
                            connectionPainter.Port1       = firstPort;
                            connectionPainter.SecondPoint = sceneCursorPosition;
                            leftMouseDown                 = true;
                            return;
                        }
                        else
                        {
                            AddConnectionLineActive = false;
                        }
                    }
                    else
                    {
                        AddConnectionLineActive = false;
                    }
                }
            }
        }
예제 #6
0
        public FormEditPort(string ipAddress, string portNumber)
        {
            this.ipAddress  = ipAddress;
            this.portNumber = portNumber;
            portConn        = new PortConnection(ipAddress.Replace(".", "_"));
            port            = Task.Run(() => portConn.GetWithKey(portNumber)).Result;

            InitializeComponent();
        }
예제 #7
0
        /// <summary> Copy all connections pointing to a node and add them to this one </summary>
        public void AddConnections(NodePort targetPort)
        {
            int connectionCount = targetPort.ConnectionCount;

            for (int i = 0; i < connectionCount; i++)
            {
                PortConnection connection = targetPort.connections[i];
                NodePort       otherPort  = connection.Port;
                Connect(otherPort);
            }
        }
 public static void CloseConnection()
 {
     if (IsRS232)
     {
         PortConnection.ClosePortIfOpened();
         Instance.ComunicationStatus = RoundBoolLed.IDLE;
     }
     else if (IsCAN)
     {
         //todo
     }
 }
예제 #9
0
        private void loadPort()
        {
            bool success = false;
            int  loop    = 0;

            do
            {
                if (loop == 10)
                {
                    break;
                }
                try
                {
                    lv_port.Items.Clear();
                    lv_link.Items.Clear();
                    lbl_portSelected.Text = "Port Selected: ";

                    if (IPSelected == null)
                    {
                        return;
                    }

                    PortConnection            portConn = new PortConnection(IPSelected.ipAddress);
                    Dictionary <string, Port> lst      = new Dictionary <string, Port>();
                    lst = Task.Run(() => portConn.GetAll()).Result;

                    foreach (Port port in lst.Values)
                    {
                        ListViewItem item = new ListViewItem(IPSelected.ipAddress.Replace("_", "."));
                        item.SubItems.Add(port.portNumber);
                        item.SubItems.Add(port.active.ToString());
                        item.SubItems.Add(port.data.ToString());
                        item.SubItems.Add(port.die.ToString());
                        item.SubItems.Add(port.port.ToString());
                        item.SubItems.Add(port.language.ToString());

                        lv_port.Items.Add(item);
                    }
                    success = true;
                }
                catch
                {
                    loop++;
                    Thread.Sleep(1000);
                }
            } while (!success);

            if (!success)
            {
                MessageBox.Show("Đã thử load " + loop + " lần mà *** đc :))");
            }
        }
예제 #10
0
        /// <summary> Move all connections pointing to this node, to another node </summary>
        public void MoveConnections(NodePort targetPort)
        {
            int connectionCount = connections.Count;

            // Add connections to target port
            for (int i = 0; i < connectionCount; i++)
            {
                PortConnection connection = targetPort.connections[i];
                NodePort       otherPort  = connection.Port;
                Connect(otherPort);
            }
            ClearConnections();
        }
 /// <summary> Checks all connections for invalid references, and removes them. </summary>
 public void VerifyConnections()
 {
     for (int i = connections.Count - 1; i >= 0; i--)
     {
         PortConnection connection = connections[i];
         INode          castedNode = connection.node as INode;
         if (castedNode != null && !string.IsNullOrEmpty(connection.fieldName) && castedNode.GetPort(connection.fieldName) != null)
         {
             continue;
         }
         connections.RemoveAt(i);
     }
 }
예제 #12
0
        public void Viewport_MouseLeftButtonUp(Point sceneCoordinates)
        {
            /* Add Connection Line command started */
            if (this.AddConnectionLineActive == true)
            {
                Object newSelectedObject;
                bool   clicked = AutosarApplication.GetInstance().ActiveComposition.GetClickedObject(sceneCoordinates, out newSelectedObject);

                /* if we check in main composition */
                if (!clicked)
                {
                    CompositionInstance mainComposition = AutosarApplication.GetInstance().Compositions.GetMainComposition();
                    foreach (CompositionInstance composition in AutosarApplication.GetInstance().Compositions)
                    {
                        if (!composition.Equals(mainComposition))
                        {
                            clicked = composition.IsClicked(sceneCoordinates, out newSelectedObject);
                            if (clicked)
                            {
                                break;
                            }
                        }
                    }
                }

                if (newSelectedObject is PortPainter)
                {
                    PortPainter startPort = connectionPainter.Port1;
                    PortPainter endPort   = newSelectedObject as PortPainter;

                    /* Check that we can assign another port to this */
                    if (CouldPortsBeAssigned(startPort, endPort))
                    {
                        connectionPainter.Port2 = endPort;
                        connectionPainter.UpdateLines();
                        connectionPainter.UpdateName();
                        CompositionInstance currentComposition = AutosarApplication.GetInstance().ActiveComposition;
                        currentComposition.Connections.AddConnection(connectionPainter);
                        connectionPainter = null;
                        treeView.UpdateAutosarTreeView(null);
                    }
                }
                AddConnectionLineActive = false;
            }
            leftMouseDown = false;
        }
예제 #13
0
        private void lv_port_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.lv_port.SelectedItems.Count == 0 || IPSelected == null)
            {
                return;
            }

            string         portNumber = this.lv_port.SelectedItems[0].SubItems[1].Text;
            PortConnection portConn   = new PortConnection(IPSelected.ipAddress);

            PortSelected = Task.Run(() => portConn.GetWithKey(portNumber)).Result;

            if (PortSelected == null)
            {
                return;
            }
            lbl_portSelected.Text = "Port Selected: " + portNumber;

            loadLinkWithWaitForm();
        }
 public static void OpenConnection()
 {
     if (IsRS232)
     {
         if (PortConnection.OpenPort())
         {
             Instance.ComunicationStatus = RoundBoolLed.PASSED;
         }
         else
         {
             Instance.ComunicationStatus = RoundBoolLed.FAILED;
             Task.Run(() => {
                 Thread.Sleep(700);
                 Instance.ComunicationStatus = RoundBoolLed.IDLE;
             });
         }
     }
     else if (IsCAN)
     {
         Instance.CAN_OpenAllConnection();
     }
 }
        private void TransmitAndReceiveRS232()
        {
            if (!PortConnection.IsOpen())
            {
                Thread.Sleep(100);
                return;
            }

            if (_writePackageQueue.Count > 0 &&
                sw.ElapsedMilliseconds >= Properties.Settings.Default.sleepForRefresh &&
                _writePackageQueue.TryDequeue(out writePckt))
            {
                PortConnection.writeToPort(writePckt);
                sw = Stopwatch.StartNew();
            }
            if (PortConnection.Port.BytesToRead >= 11)
            {
                var msgReceive = new Byte[11];
                PortConnection.Port.Read(msgReceive, 0, 11);
                innerTransmitRS232(msgReceive);
            }
        }
예제 #16
0
        private void loadLink(string portNumber, int index)
        {
            lv_link.Items.Clear();
            PortConnection portConn     = new PortConnection(ip.ipAddress);
            Port           PortSelected = Task.Run(() => portConn.GetWithKey(portNumber)).Result;

            if (ip == null || PortSelected == null)
            {
                return;
            }

            LinkConnection            linkConn = new LinkConnection(ip.ipAddress, PortSelected.portNumber);
            Dictionary <string, Link> lst      = new Dictionary <string, Link>();

            lst = Task.Run(() => linkConn.GetAll()).Result;

            int i = 0;

            foreach (Link link in lst.Values)
            {
                ListViewItem item = new ListViewItem(PortSelected.portNumber);
                item.SubItems.Add(link.key == null ? "" : link.key);
                item.SubItems.Add(link.link == null ? "" : link.link);
                item.SubItems.Add(link.linkThumbnail == null ? "" : link.linkThumbnail);
                item.SubItems.Add(link.title == null ? "" : link.title);
                item.SubItems.Add(link.description == null ? "" : link.description);
                item.SubItems.Add(link.type == null ? "" : link.type + "");

                if (index != -1 && index == i)
                {
                    item.BackColor = Color.Blue;
                }
                i++;
                lv_link.Items.Add(item);
            }
        }
예제 #17
0
 public bool closeConnection(int canNodeId = 127)
 {
     PortConnection.ClosePortIfOpened();
     return(true);
 }
예제 #18
0
        private async void btn_addLink_Click(object sender, EventArgs e)
        {
            if (PortSelected == null)
            {
                MessageBox.Show("Chua chon Port!");
                return;
            }

            this.Enabled = false;
            bool success = false;
            int  loop    = 0;

            do
            {
                if (loop == 10)
                {
                    break;
                }
                try
                {
                    Link link = new Link();
                    link.link          = txt_link.Text;
                    link.linkThumbnail = txt_linkThumbnail.Text;
                    link.title         = txt_title.Text;
                    link.tag           = txt_tag.Text;
                    link.description   = txt_description.Text;
                    link.linkAff       = txt_linkAff.Text;
                    link.type          = Int32.Parse(txt_type.Text);

                    LinkConnection linkConn = new LinkConnection(IPSelected.ipAddress, PortSelected.portNumber);
                    await linkConn.Insert(link);

                    //Update port.data
                    PortConnection portConn = new PortConnection(IPSelected.ipAddress);
                    PortSelected = Task.Run(() => portConn.GetWithKey(PortSelected.portNumber)).Result;
                    if (PortSelected.links != null && PortSelected.links.Count > 0 && !PortSelected.data)
                    {
                        PortSelected.data = true;
                        await portConn.Delete(PortSelected.portNumber);

                        await portConn.Insert(PortSelected);

                        loadPort();
                    }

                    success = true;

                    loadLinkWithWaitForm();
                    resetInputLink();
                }
                catch
                {
                    loop++;
                    Thread.Sleep(2000);
                }
            } while (!success);

            if (!success)
            {
                MessageBox.Show("Đã thử " + loop + " lần mà *** đc :))");
                this.Enabled = true;
            }
            this.Enabled = true;
        }
        public void _OpenAllConnections()
        {
            if (ActiveCanDriver == Consts.INTERFACE_RS232)
            {
                if (PortConnection.OpenPort())
                {
                    dic_CanChanels.Clear();
                    foreach (var entry in Globals.Vm_scis)
                    {
                        dic_CanChanels[entry.VM_UC_Main.NodeId] = 0;
                    }
                    Task.Factory.StartNew(() => {
                        int i = 0;
                        do
                        {
                            Globals.Vm_scis[0].HighFrequencyOn = true;
                            FrequencyManager.SendCCComand(vm_sci: Globals.Vm_scis[0]);
                            Thread.Sleep(5);
                        } while (!graphStarted && i < 500);//max 25 seconds
                    });
                }
            }
            else if (ActiveCanDriver == Consts.CAN_DRIVER_KVASER)
            {
                lock (LockCanIdsDic) {
                    hasChangeInNodesList = true;

                    Canlib.canInitializeLibrary();
                    foreach (var value in dic_CanChanels.Where(x => x.Value >= 0).Select(x => x.Value))
                    {
                        Canlib.canBusOff(value);
                        Canlib.canClose(value);
                    }
                    //lastOpenedChanel = 0;
                    dic_CanChanels.Clear();
                    foreach (var entry in Globals.Vm_scis.Where(entry => entry.VM_UC_Main != null))
                    {
                        dic_CanChanels[entry.VM_UC_Main.NodeId] = -1;
                    }
                    foreach (var key in dic_CanChanels.Select(x => x.Key).ToList())
                    {
                        int openedChanel = Canlib.canOpenChannel(lastOpenedChanel + 1, key);
                        if (openedChanel >= 0)
                        {
                            dic_CanChanels[key] = openedChanel;
                        }
                    }

                    foreach (var entry in dic_CanChanels.Where(x => x.Value >= 0))
                    {
                        Canlib.canSetBusParams(
                            handle: entry.Value,
                            freq: CANDesiredBitRate,
                            tseg2: 0,
                            tseg1: 0,
                            sjw: 0,
                            noSamp: 0,
                            syncmode: 0
                            );
                        Canlib.canBusOn(entry.Value);

                        //if (!setCanCardName() || !getCanBitRate()) {
                        //    CANStatus = Consts.BOOL_FAILED;
                        //    CANHandle = -1;
                        //}

                        //initialize the node
                        Canlib.canWrite(
                            handle: entry.Value,
                            id: 0,
                            msg: new byte[] { 1, (byte)entry.Key },
                            dlc: 2, //size of msg
                            flag: 2 //we have defined this as const
                            );
                    }
                }
                //get multiply value
                WriteToAll("AD", 0, true, true);

                //get ISR
                WriteToAll("AE", 0, true, true);
                graphStarted = false;
                //start Graph
                //todo fix for each nodeId
                Task.Factory.StartNew(() => {
                    int i = 0;
                    do
                    {
                        if (Globals.Vm_scis.Count > 0)
                        {
                            Globals.Vm_scis[0].HighFrequencyOn = true;
                            FrequencyManager.SendCCComand(1, vm_sci: Globals.Vm_scis[0]); // start graph plot with 6k frequency.
                            Thread.Sleep(5);
                        }
                        else
                        {
                            Debugger.Break();
                        }
                    } while (!graphStarted && i < 500 && Globals.Vm_scis.Count > 0);//max 25 seconds
                });
                //_can_status = RoundBoolLed.DISABLED;
            }
        }
예제 #20
0
 protected override void OnExit(ExitEventArgs e)
 {
     PortConnection.ClosePortIfOpened();
     base.OnExit(e);
 }
예제 #21
0
        public PortConnection CreatePortConnection()
        {
            PortConnection connection = new PortConnection();

            return(connection);
        }
예제 #22
0
 public bool OpenConnection(int canNodeId = 127)
 {
     return(PortConnection.OpenPort());
 }