Beispiel #1
0
        private void button40_Click(object sender, EventArgs e)//Send
        {
            CommandFrame cmd = new CommandFrame();

            cmd.CommandWord1 = define.W108_CAR_CONSOLE_SEND_COMMAND;//0XEE
            List <byte> temArray = new List <byte>();

            if (textBox19.Text != "")
            {
                byte[] command = Encoding.Default.GetBytes(textBox19.Text);
                foreach (byte c in command)
                {
                    temArray.Add(c);
                }
            }
            //temArray.Add((byte)((id & 0xff00) >> 0x08));
            //cmd.DataLength1 = (byte)temArray.Count;
            cmd.Data1 = temArray.ToArray();
            byte[] t = cmd.GetFrameToBytes();
            try
            {
                //SendMsgTorSerialPort(cmd);
                serialPort1.Write(t, 0, t.Length);
            }
            catch (TimeoutException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        public void sendData(List <byte> byteList)
        {
            CommandFrame cmd = new CommandFrame();

            cmd.CommandWord1 = define.W108_CAR_CONSOLE_SEND_COMMAND;
            cmd.Data1        = byteList.ToArray();
            //cmd.DataLength1 = (byte)byteList.Count;
            cmd.CalSumCheck();
            if (serialPort1.IsOpen)
            {
                byte[] t = cmd.GetFrameToBytes();
                serialPort1.Write(t, 0, t.Length);
            }
        }
Beispiel #3
0
        public void SendData(List <Track> shortPath, byte CarNum, byte EndStation)
        {
            i = 0;
            CommandFrame cmd = new CommandFrame();

            cmd.CommandWord1 = define.W108_CAR_CONSOLE_SEND_COMMAND;
            List <byte> strSP = new List <byte>();

            strSP.Add(CarNum);
            i = Check(shortPath, strSP);
            if (i <= 28)
            {
                strSP.Insert(1, 0xFF);
            }
            else
            {
                strSP.Insert(1, 1);
            }
            //cmd.DataLength1 = (byte)(i + 4);
            strSP.Add(EndStation);
            strSP.Add(0x04);
            cmd.SumCheck1 = cmd.CalSumCheckFunction();
            #region
            if (i <= 28)
            {
                cmd.Data1 = strSP.ToArray();
                byte[] t = cmd.GetFrameToBytes();
                try
                {
                    serialPort1.Write(t, 0, t.Length);
                }
                catch (TimeoutException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                #region
                List <byte> zhen1 = strSP.GetRange(0, 32);
                cmd.Data1     = zhen1.ToArray();
                cmd.SumCheck1 = cmd.CalSumCheckFunction();
                byte[] t = cmd.GetFrameToBytes();
                try
                {
                    serialPort1.Write(t, 0, t.Length);
                }
                catch (TimeoutException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                #endregion
                #region
                List <byte> zhen2 = new List <byte>();
                zhen2.Insert(0, CarNum);
                zhen2.Insert(1, 0xFF);
                zhen2.AddRange(strSP.GetRange(32, i - 28));
                //zhen2 = strSP.GetRange(32, i - 28);
                cmd.Data1     = zhen2.ToArray();
                cmd.SumCheck1 = cmd.CalSumCheckFunction();
                t             = cmd.GetFrameToBytes();
                try
                {
                    serialPort1.Write(t, 0, t.Length);
                }
                catch (TimeoutException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            #endregion
            #endregion
            i = 0;
        }