ToString() public method

public ToString ( ) : string
return string
コード例 #1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                // the the message to the serias interface
                char[] aSplit = { ',' };
                string sDataBytes = txtData.Text;
                string[] asData = sDataBytes.Split(aSplit);
                EventCode chosenEvent = m_eventCodeNameToVal[cbxEventCode.SelectedItem.ToString()];
                EVENT_PRIORITY chosenPriority = m_eventPriorityToval[cbxPriority.SelectedItem.ToString()];

                if (asData.Length == 1 && asData[0].Length == 0)
                {
                    asData = new string[0];
                }
                // length: dle, stx, flags, 4 bytes header, data bytes, dle, etx
                int len = 9 + asData.Length;
                byte[] aVscpMsg = new byte[len];
                aVscpMsg[0] = message_frame.DLE;
                aVscpMsg[1] = message_frame.STX;
                int iTemp = (int)chosenPriority;
                aVscpMsg[2] = (byte) (iTemp << 5);

                iTemp = (int)chosenEvent;
                int iVal = (iTemp >> 24) & 0xFF;
                aVscpMsg[3] = (byte)iVal;

                iVal = (iTemp >> 16) & 0xFF;
                aVscpMsg[4] = (byte)iVal;

                iVal = iTemp & 0xFF;
                aVscpMsg[5] = (byte)iVal;

                // nickname is zero
                aVscpMsg[6] = 0;

                int i = 0;
                for (; i < asData.Length; i++)
                {
                    string sNumber = asData[i];
                    if (sNumber.Length > 0)
                    {
                        aVscpMsg[7 + i] = (byte)Int32.Parse(sNumber, System.Globalization.NumberStyles.HexNumber);
                    }
                    else
                    {
                        aVscpMsg[7 + i] = 0;
                    }
                }
                aVscpMsg[7 + i] = message_frame.DLE;
                i++;
                aVscpMsg[7 + i] = message_frame.ETX;

                m_serialPort.Write(aVscpMsg, 0, aVscpMsg.Length);
                message_frame generated_vscp_message = new message_frame();
                for (int j = 0; j < aVscpMsg.Length; j++)
                {
                    if (generated_vscp_message.AddByte(aVscpMsg[j]))
                    {
                        // a new serial vscp message
                        DateTime now = DateTime.Now;
                        // Create message so CRC is checked if needed
                        SerialEventMessage msg = new SerialEventMessage(generated_vscp_message);
                        string sMsg = msg.ToString();

                        string sTime = now.ToLongTimeString() + ":" + now.Millisecond;
                        if (null != m_tracer)
                        {
                            m_tracer.Write(sTime + " " + sMsg);

                            ListViewItem item = new ListViewItem(sTime, sMsg);
                            item.SubItems.Add(msg.ToString());
                            m_listView.AddItem(item);

                            string sEventName = msg.m_event.ToString();
                            byte[] dataBytes = msg.GetDataBytes();
                            string sCrack = m_msgCracker.Decode(sEventName, dataBytes);
                            if (sCrack.Length > 0)
                            {
                                ListViewItem item2 = new ListViewItem(sTime, sMsg);
                                item2.SubItems.Add(sCrack);
                                m_listView.AddItem(item2);
                            }
                        }
                    }
                }
            }
            catch (IOException ex)
            {
                Debug.WriteLine("IOException: " + ex.Message);
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private void ExtractSerialVSCPMessage(int i_length, byte[] i_data)
        {
            //lock (this)
            {
                // If Receive RS-232 m_data available
                for (int i = 0; i < i_length; i++)
                {
                    Byte c = i_data[i];
                    if (serial_vscp_message.AddByte(c))
                    {
                        // a new serial vscp message
                        DateTime now = DateTime.Now;
                        // Create message so CRC is checked if needed
                        SerialEventMessage msg = new SerialEventMessage(serial_vscp_message);
                        string sMsg = msg.ToString();

                        string sTime = now.ToLongTimeString() + ":" + now.Millisecond;
                        if (null != m_tracer)
                        {
                            m_tracer.Write(sTime + " " + sMsg);

                            ListViewItem item = new ListViewItem(sTime, sMsg);
                            item.SubItems.Add(msg.ToString());
                            m_listView.AddItem(item);

                            string sEventName = msg.m_event.ToString();
                            byte[] dataBytes = msg.GetDataBytes();
                            string sCrack = m_msgCracker.Decode(sEventName, dataBytes);
                            if (sCrack.Length > 0)
                            {
                                ListViewItem item2 = new ListViewItem(sTime, sMsg);
                                item2.SubItems.Add(sCrack);
                                m_listView.AddItem(item2);
                            }
                        }
                    }
                }
            }
        }