Пример #1
0
    private void btn_send_serial_Click(object sender, EventArgs e)
    {
        int index = (int)nud_con_serial_index.Value;
        int value = (int)nud_con_serial_value.Value;

        CommHandler.Send(new KeyValuePair <int, int>(index, value));
    }
Пример #2
0
    //tick sends heartbeat to monitor bus connection
    private void tim_heartBeat_Tick(object sender, EventArgs e)
    {
        pulse = false;
        heartBeatTimer.Start();
        heartBeat_prev = heartBeat;
        sendHeartbeat  = true;

        try
        {
            if (CommHandler.connectionType == CommHandler.ConnectionType.CANbus)             //TEMP disable heartbet for Ægir
            {
                return;
            }

            KeyValuePair <int, int> kvp;

            if (st.status[0] == 0)
            {
                kvp = new KeyValuePair <int, int>(0, 1);
            }

            else
            {
                kvp = new KeyValuePair <int, int>(0, 0);
            }

            CommHandler.Send(kvp);
        }
        catch
        {
            Console.Write("No connection for heartbeat");
        }
    }
Пример #3
0
    private static void _bgrSendCommands(object sender, DoWorkEventArgs e)
    {
        // Ignore this call if the port has not been assigned yet
        if (CommHandler.connection == null)
        {
            commands.ResetArray();
            Program.windowStatus.tim_SendCommandsDelay.Interval = (int)Program.windowStatus.nud_comm_transfreq.Value;
            Program.windowStatus.tim_SendCommandsDelay.Start();
            return;
        }

        ST_Array.arrelement[] data = commands.GetAllValuesAndReset();

        // Return if there are no elements to send
        if (data.Length == 0)
        {
            Program.windowStatus.tim_SendCommandsDelay.Interval = (int)Program.windowStatus.nud_comm_transfreq.Value;
            Program.windowStatus.tim_SendCommandsDelay.Start();
            return;
        }

        // Stop the timer for next update, to start again when finished with sending these commands
        stopwatch.Restart();

        // Send commands
        KeyValuePair <int, int>[] tosend = new KeyValuePair <int, int> [data.Length];
        for (int i = 0, j = data.Length; i < j; i++)
        {
            tosend[i] = new KeyValuePair <int, int>(data[i].index, data[i].value);
        }
        CommHandler.Send(tosend);

        // Set the delay to the next send of commands, based on time elapsed sending current commands and time till next frame
        stopwatch.Stop();
        int tick = (int)Program.windowStatus.nud_comm_transfreq.Value - (int)stopwatch.ElapsedMilliseconds;

        tick = tick < 1 ? 1 : tick;
        Program.windowStatus.tim_SendCommandsDelay.Interval = tick;
        Program.windowStatus.tim_SendCommandsDelay.Start();
    }