Esempio n. 1
0
        /// <summary>
        /// Test whether the given connection is a link with monochromator controller
        /// </summary>
        /// <param name="connection">Connection</param>
        /// <returns>true if connection is a link with monochromator controller, false otherwise</returns>
        private static bool IsMonochromator(SerialConnection connection)
        {
            // Ping controller
            connection.Send((uint)PacketHeader.Ping);

            // Parse response
            var responseAsBytes = connection.Read(sizeof(PacketHeader));
            var response        = BitConverter.ToUInt32(responseAsBytes);

            return(response == PingResponse);
        }
    // Send a message through to the serial port
    private void btn_send_Click(object sender, EventArgs e)
    {
        string s = txt_message.Text;

        txt_message.Text = "";
        txt_message.Focus();

        switch (cmb_endline.SelectedIndex)
        {
        case (0):                 // no end
            break;

        case (1):                 // '\r'
            s += "\r";
            break;

        case (2):                 // '\n'
            s += "\n";
            break;

        case (3):                 // '\r\n'
            s += "\r\n";
            break;
        }

        // Send out through the serial port
        //txt_output.Text += s;

        if (port != null && port.IsOpen())
        {
            // Character size
            byte[] package = new byte[s.Length];
            for (int i = 0, j = s.Length; i < j; i++)
            {
                // Test if these are the correct order
                package[i + 0] = (byte)(s[i] >> 0);
            }

            port.Send(package);
        }
        else
        {
            // Tried to send through a closed port, maybe send a error message
        }
    }