Beispiel #1
0
        // Method to send the buffer to Hexabitz modules.
        public void SendMessage(byte Destination, byte Source, int Code, byte[] Payload)
        {
            string optionsString = Opt8_Next_Message +
                                   Opt67_Response_Options +
                                   Opt5_Reserved +
                                   Opt34_Trace_Options +
                                   Opt2_16_BIT_Code +
                                   Opt1_Extended_Flag;
            byte Options = GetBytes(optionsString)[0];  // 00100010 // 0x22

            Start();
            Message _Message = new Message(Destination, Source, Options, Code, Payload);

            AllMessage = _Message.GetAll();  // We get the whole buffer bytes to be sent to the Hexabitz modules.
            try { Port.Write(AllMessage, 0, AllMessage.Length); } catch (Exception exp) { Console.WriteLine("Connection Error"); }
            End();
        }
        private void ZeroBTN_Click(object sender, EventArgs e)
        {
            Port.Dispose();
            Port = new SerialPort("COM" + COM.Value, int.Parse(baudRateCB.SelectedItem.ToString()), Parity.None, 8, StopBits.One);
            Code = (int)HexaInterface.Message_Codes.CODE_H26R0_ZEROCAL;

            //HexaInterface HexInter = new HexaInterface(COM.Value.ToString());
            byte[] Payload = { channel };

            DOT_NET_COMS_LIB.Message Buff = new DOT_NET_COMS_LIB.Message(DestinationID, SourceID, Options, Code, Payload);
            AllBuffer = Buff.GetAll();  // We get the whole buffer bytes to be sent to the Hexabitz modules.

            try { Port.Open(); } catch { }
            try { Port.Write(AllBuffer, 0, AllBuffer.Length); } catch { MessageBox.Show("Connection Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            try { Port.Close(); } catch { }

            //HexInter.SendMessage(Destination, Source,  Options, Code, Message);
            connectionLBL.Text = "Zero Calibrated";
        }
        private void StopBTN_Click(object sender, EventArgs e)
        {
            Port.Dispose();
            Port = new SerialPort("COM" + COM.Value, int.Parse(baudRateCB.SelectedItem.ToString()), Parity.None, 8, StopBits.One);
            Code = (int)HexaInterface.Message_Codes.CODE_H26R0_STOP;

            HexaInterface HexInter = new HexaInterface(COM.Value.ToString(), int.Parse(baudRateCB.SelectedItem.ToString()));

            byte[] Payload = new byte[0];
            DOT_NET_COMS_LIB.Message Buff = new DOT_NET_COMS_LIB.Message(DestinationID, SourceID, Options, Code, Payload);
            AllBuffer = Buff.GetAll();  // We get the whole buffer bytes to be sent to the Hexabitz modules.

            // Here we call the platform sending protocol.
            // C# Example:
            try { Port.Open(); } catch { }
            try { Port.Write(AllBuffer, 0, AllBuffer.Length); } catch { MessageBox.Show("Connection Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            try { Port.Close(); } catch { }

            //HexInter.SendMessage(Destination, Source, Options, Code, Message);

            sevenSegmentArray1.Value = "STOP";
            connectionLBL.Text       = "Stopped";
        }