예제 #1
0
 private void TestBTN_Click(object sender, EventArgs e)
 {
     HexInter = new HexaInterface(COM.Value.ToString(), int.Parse(baudRateCB.SelectedItem.ToString()));
     Code     = (int)HexaInterface.Message_Codes.CODE_H01R0_COLOR;
     byte[] Payload = { 90 };
     HexInter.SendMessage(DestinationID, SourceID, Code, Payload);
 }
예제 #2
0
 public Form1()
 {
     InitializeComponent();
     baudRateCB.SelectedIndex = 10;
     HexInter      = new HexaInterface(COM.Value.ToString(), int.Parse(baudRateCB.SelectedItem.ToString()));
     DestinationID = (byte)destinationID_N.Value;
     SourceID      = (byte)sourceID_N.Value;
 }
예제 #3
0
 private void LedToggle_CheckedChanged(object sender, EventArgs e)
 {
     HexInter = new HexaInterface(COM.Value.ToString(), int.Parse(baudRateCB.SelectedItem.ToString()));
     Code     = (int)HexaInterface.Message_Codes.CODE_H01R0_COLOR; // Led with colors code
     HexInter.Opt2_16_BIT_Code = "0";                              // because our code is 103 (1 byte)
     if (ledToggle.Checked)
     {
         byte[] Payload = { 1, red, green, blue, intensity };
         HexInter.SendMessage(DestinationID, SourceID, Code, Payload);
     }
     else
     {
         Code = (int)HexaInterface.Message_Codes.CODE_H01R0_OFF;
         byte[] Payload = new byte[0];
         HexInter.SendMessage(DestinationID, SourceID, Code, Payload);
     }
 }
예제 #4
0
        private void RelayToggle_CheckedChanged(object sender, EventArgs e)
        {
            HexInter = new HexaInterface(COM.Value.ToString(), int.Parse(baudRateCB.SelectedItem.ToString()));
            Code     = (int)HexaInterface.Message_Codes.CODE_H0FR6_ON; // Relay on code
            HexInter.Opt2_16_BIT_Code = "1";                           // because our code is 750 (2 byte)

            if (relayToggle.Checked)
            {
                int    timeOut   = int.Parse(timeoutTB.Text);
                byte[] timeBytes = BitConverter.GetBytes(timeOut);
                byte[] Payload   = { timeBytes[3], timeBytes[2], timeBytes[1], timeBytes[0] };
                HexInter.SendMessage(DestinationID, SourceID, Code, Payload);
            }
            else
            {
                Code = (int)HexaInterface.Message_Codes.CODE_H0FR6_OFF; // Relay off code
                byte[] Payload = new byte[0];
                HexInter.SendMessage(DestinationID, SourceID, Code, Payload);
            }
        }
예제 #5
0
        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";
        }
예제 #6
0
        private void readBTN_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_STREAM_PORT_GRAM; // default is gram reading
            switch (unitCB.SelectedItem)
            {
            case "Gram":   Code = (int)HexaInterface.Message_Codes.CODE_H26R0_STREAM_PORT_GRAM; break;

            case "KG":     Code = (int)HexaInterface.Message_Codes.CODE_H26R0_STREAM_PORT_KGRAM; break;

            case "Ounces": Code = (int)HexaInterface.Message_Codes.CODE_H26R0_STREAM_PORT_OUNCE; break;

            case "Pounds": Code = (int)HexaInterface.Message_Codes.CODE_H26R0_STREAM_PORT_POUND; break;

            default: break;
            }

            try { period = uint.Parse(periodTB.Text); } catch { MetroMessageBox.Show(this, "Check period input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
            if (timeTB.Enabled)
            {
                try { time = uint.Parse(timeTB.Text); } catch { MetroMessageBox.Show(this, "Check time input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
            }
            else
            {
                time = 0xFFFFFFFF;    // infinte time code
            }
            byte[] periodBytes = BitConverter.GetBytes(period);
            byte[] timeBytes   = BitConverter.GetBytes(time);

            byte modulePort = 0x03;
            byte module     = 0x01;

            byte[] Payload =
            {
                channel,
                periodBytes[3],
                periodBytes[2],
                periodBytes[1],
                periodBytes[0],

                timeBytes[3],
                timeBytes[2],
                timeBytes[1],
                timeBytes[0],

                modulePort,
                module
            };


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

            //DOT_NET_COMS_LIB.Message Buff = new DOT_NET_COMS_LIB.Message(Destination, Source, 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(DestinationID, SourceID, Code, Payload);

            Receive();
        }
예제 #7
0
 public ActionResult Connect(string COM, int BaudRate)
 {
     Port      = new SerialPort("COM" + COM, BaudRate, Parity.None, 8, StopBits.One);
     HexaInter = new HexaInterface(COM, BaudRate);
     return(Json(new { COM, BaudRate }));
 }