Write() public static method

Send data to the serial port.
public static Write ( string message ) : void
message string
return void
Exemplo n.º 1
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (!serial.IsOpen || textBoxTx.Text == string.Empty)
            {
                return;
            }

            //定义一个变量,记录发送了几个字节
            int n = 0;

            //16进制发送
            if (checkBoxHexSend.Checked)
            {
                //我们不管规则了。如果写错了一些,我们允许的,只用正则得到有效的十六进制数
                MatchCollection mc  = Regex.Matches(textBoxTx.Text, @"(?i)[\da-f]{2}");
                List <byte>     buf = new List <byte>();//填充到这个临时列表中
                //依次添加到列表中
                foreach (Match m in mc)
                {
                    buf.Add(byte.Parse(m.Value, System.Globalization.NumberStyles.HexNumber));
                }

                if (checkBoxNewline.Checked)
                {
                    buf.Add((byte)'\r');
                    buf.Add((byte)'\n');
                }
                //转换列表为数组后发送
                serial.Write(buf.ToArray(), 0, buf.Count);
                //记录发送的字节数
                n = buf.Count;
            }
            else//ascii编码直接发送
            {
                Encoding encoding = serial.Encoding;
                byte[]   gb       = encoding.GetBytes(textBoxTx.Text);

                serial.Write(gb, 0, gb.Length);
                n = gb.Length;

                if (checkBoxNewline.Checked)
                {
                    serial.Write("\r\n");
                    n += 2;
                }
            }
            tx_bytes += n;//累加发送字节数
            UpdateSendCount();
        }
Exemplo n.º 2
0
        private void tmrApp_Tick(object sender, EventArgs e)
        {
            dataList.Add(Convert.ToString(count) + "," + txt_List); //armazena o tempo do experimento de acordo com a variável count e tamabém
                                                                    //as informações recebidas do arduino e armazenada na string txt_List
            //Serial.Write(dataList[qtde_data]);

            qtde_data++;                              //indica a quantidade de linhas que serão salvas no arquivo

            count += Convert.ToDouble(timeAquisicao); //incrementa a contagem do tempo para um novo ciclo

            //termina o experimento se o tempo do experimento for igual ou maior que a tempo estabelecido pel usuário
            if (((count * 1000) - count) >= duracao)
            {
                Serial.Write("FN000000\r");    //envia a mensagem de finalização para o arduino
                tmrApp.Enabled = false;        //para a contagem do tempo do timer
                timeAquisicao  = string.Empty; //limpa a variável que informa o intervalo de tempo do timer

                Serial.Close();                //termina a comunicação serial
                btnOpen.Enabled      = true;
                btnClose.Enabled     = false;
                btnExit.Enabled      = true;
                btnIniciar.Enabled   = false;
                btnFinalizar.Enabled = false;

                lblSolar.Text         = "0000";
                lblTempInicial.Text   = "0000";
                lblTempFinal.Text     = "0000";
                lblTempAmb.Text       = "0000";
                lblUmidade.Text       = "0000";
                lblSetPointTemp.Text  = "0000";
                lblSetPointVazao.Text = "0000";
            }
        }
        private void SetMode(IMode mode)
        {
            SetModeFlag = false;
            var i = 0;

            foreach (var light in mode.Lights)
            {
                var data = new byte[2 + 3 + 2 * light.Pixels.Count];
                data[0] = (i == 0) ? (byte)0xFE : (byte)0xFF;
                data[1] = (byte)(3 + 2 * light.Pixels.Count);
                data[2] = light.Color.R;
                data[3] = light.Color.G;
                data[4] = light.Color.B;

                var index = 5;

                foreach (var pixelInfo in light.Pixels)
                {
                    data[index]     = pixelInfo[0];
                    data[index + 1] = pixelInfo[1];
                    index          += 2;
                }

                foreach (var b in data)
                {
                    Serial?.Write(new[] { b }, 0, 1);
                    Thread.Sleep(20);
                }
                i++;
            }
        }
Exemplo n.º 4
0
 private static string WriteReadInternal(string Text, int TimeoutMilliseconds, bool Wait = false)
 {
     lock (LEDStrahlerSerial.InterfaceLock)
     {
         if (LEDStrahlerSerial.Serial.IsOpen == true)
         {
             //Flush input buffer
             Serial.DiscardInBuffer();
             //Send data
             var Data = Encoding.ASCII.GetBytes(Text + "\n");
             Serial.Write(Data, 0, Data.Length);
             //Receive data
             if (Wait == true)
             {
                 Thread.Sleep(TimeoutMilliseconds);
                 Text = Serial.ReadExisting();
             }
             else
             {
                 Serial.ReadTimeout = TimeoutMilliseconds;
                 try
                 {
                     Text = Serial.ReadLine();
                 }
                 catch
                 {
                     return(""); //Timeout
                 }
             }
             return(Text);
         }
         return("");
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Exécute une action en fonciton de la donnée "num"
        /// </summary>
        /// <param name="num"></param>
        private void Action(int num)//Lance l'action en fcontion de la donnée
        {
            switch (actionMemory)
            {
            case "sensibiliter effessaire":
                if (!start)
                {
                    numericSensitivity.Value     = num;
                    checkBoxPersonnalisé.Checked = true;
                }
                break;

            case "angle":
            {
                if (checkBoxControl.Checked && num <= 120 && num >= 0)
                {
                    if (Serial.IsOpen)
                    {
                        //On envoie la donnée
                        Serial.Write("#FSRS" + num + "\n");
                        labelDegre.Text     = num.ToString();
                        trackBarDegre.Value = num;
                    }
                }
            }
            break;
            }
            actionMemory = null;
        }
Exemplo n.º 6
0
 private void OnMessageReceived(object sender, TypedRequestReceivedEventArgs <MyRequest> e)
 {
     if (e.RequestMessage.Ack == false)
     {
         MyResponse resp = SendWeatherInfo(e.RequestMessage.TimeUnit, e.RequestMessage.numberOfTimeUnitsBack);
         // Send message to client which is selected in the listbox.
         if (resp != null)
         {
             myReceiver.SendResponseMessage(e.ResponseReceiverId, resp);
         }
     }
     else
     {
         if (Serial.IsOpen)
         {
             if (clients.IndexOf(GetClient(e.ResponseReceiverId)) != null)
             {
                 int clientNumver = clients.IndexOf(GetClient(e.ResponseReceiverId));
                 Serial.Write((clientNumver + 1).ToString() + "#");
                 LedSerialArgs led = new LedSerialArgs(clientNumver + 1);
                 SendLedInfo?.Invoke(null, led);
             }
             else
             {
                 return;
             }
         }
     }
 }
Exemplo n.º 7
0
        private static void Send(Serial serial, string[] chunks)
        {
            isSending = true;
            var i = 0;

            while (isSending)
            {
                serial.Write(chunks[i]);

                while (true)
                {
                    if (serial.MessageReceived.Contains("next chunk"))
                    {
                        i++;
                        serial.ClearMessage();
                        break;
                    }
                    if (serial.MessageReceived.Contains("message received"))
                    {
                        isSending = false;
                        serial.ClearMessage();
                        break;
                    }
                }
            }
        }
Exemplo n.º 8
0
 public void SendMessage(string message)
 {
     if (Serial != null)
     {
         Serial.Write(message);
     }
 }
Exemplo n.º 9
0
 public static void WriteLine(StringBuffer msg)
 {
     for (var i = 0; i < msg.Length; i++)
     {
         Serial.Write(Serial.COM1, (byte)msg[i]);
     }
     Serial.Write(Serial.COM1, (byte)'\n');
 }
Exemplo n.º 10
0
 private void btnEnviar_Click_1(object sender, EventArgs e)
 {
     if (Serial.IsOpen)
     {
         Serial.Write(txtTransmite.Text + "\r\n");
         txtTransmite.Text = "";
     }
 }
Exemplo n.º 11
0
 public bool Write(String str)
 {
     if (Serial != null && Serial.IsOpen)
     {
         Serial.Write(str);
         return(true);
     }
     return(false);
 }
Exemplo n.º 12
0
        public unsafe SSize Write(byte *buf, USize count)
        {
            for (var i = 0; i < count; i++)
            {
                Serial.Write(COM, buf[i]);
            }

            return((uint)count);
        }
Exemplo n.º 13
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     for (var i = 0; i < count; i++)
     {
         Serial.Write(Serial.COM1, buf[i]);
         Screen.Write((char)buf[i]);
     }
     return((uint)count);
 }
Exemplo n.º 14
0
        public void Send(Message m)
        {
            m.seq(Sequence());
            m.is_activity(true);

            byte[] b = m.serialize();

            Serial.Write(b, 0, b.Length);
        }
Exemplo n.º 15
0
        private void SetBrightness()
        {
            int sliderValue = hScrollBar1.Value;

            usedBrightness = sliderValue;
            byte[] b = BitConverter.GetBytes(sliderValue);
            Serial.Write("b");
            Serial.Write(b, 0, 1);
        }
Exemplo n.º 16
0
        public static void Log(string message)
        {
            if (!initialized)
            {
                Serial.SetupPort(Serial.COM1);
            }

            Serial.Write(Serial.COM1, message);
            Serial.Write(Serial.COM1, "\n");
        }
Exemplo n.º 17
0
 /// <summary>
 /// Pour contrôle manuel : Event sur le changement de valeur de la Trackbar
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void trackBar1_Scroll(object sender, EventArgs e)
 {
     //On vérifie que le port soit ouvert sinon ça crash
     if (Serial.IsOpen)
     {
         //On envoie la donnée
         Serial.Write("#FSRS" + trackBarDegre.Value.ToString() + "\n");
         labelDegre.Text = trackBarDegre.Value.ToString();
     }
 }
    private void OnTriggerEnter(Collider col)
    {
        triggerPosition = GameObject.Find("Trigger").transform.position;
        triggerRadius   = Vector3.Distance(triggerPosition, col.transform.position);

        string cmdVentil = cmdStart + convertVentileInputToString() + Massendurchflussregler1 + Massendurchflussregler2;

        Debug.Log(cmdVentil);
        Serial.Write(cmdVentil);
    }
Exemplo n.º 19
0
        private void SendPacket(MavlinkMessage m)
        {
            MavlinkPacket p = new MavlinkPacket();

            p.Message        = m;
            p.SequenceNumber = (byte)Sequence;
            p.SystemId       = 255;
            p.ComponentId    = (byte)MAV_COMPONENT.MAV_COMP_ID_MISSIONPLANNER;
            byte[] b = Mv.Send(p);
            Serial.Write(b, 0, b.Length);
        }
Exemplo n.º 20
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            byte[] SendTmp    = System.Text.Encoding.Default.GetBytes(textBox2.Text + NewLineStr);
            int    SengLenght = SendTmp.Length;

            SentBytes.Value += SengLenght;
            Thread SendData = new Thread(() => {
                thisSerialPort.Write(SendTmp, 0, SengLenght);
                this.Invoke(new Action(() =>
                {
                    btnSend.Enabled = true;
                    btnSend.Text    = "发送";
                    WorkToolStripStatusLabel.Text = "";
                }));
            });

            WorkToolStripStatusLabel.Text = "正在运行……";
            btnSend.Enabled = false;
            btnSend.Text    = "发送中……";
            SendData.Start();
        }
    private void OnTriggerEnter(Collider col)
    {
        Debug.Log("ENTER");


        triggerPosition = GameObject.Find("Trigger").transform.position;
        triggerRadius   = Vector3.Distance(triggerPosition, col.transform.position);



        Serial.Write(openVentile());
    }
Exemplo n.º 22
0
 private static void WriteInternal(string Text)
 {
     lock (LEDStrahlerSerial.InterfaceLock)
     {
         if (LEDStrahlerSerial.Serial.IsOpen == true)
         {
             //Send data
             var Data = Encoding.ASCII.GetBytes(Text + "\n");
             Serial.Write(Data, 0, Data.Length);
         }
     }
 }
Exemplo n.º 23
0
        private void button2_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = Image.FromFile("C:\\imagens\\bomba_desliga.png");

            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

            if (Serial.IsOpen)
            {
                Serial.Write("FN000000\r");
                tmrApp.Enabled = false;
            }
        }
Exemplo n.º 24
0
        /// <summary>异步发送数据</summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public virtual Boolean SendAsync(Byte[] buffer)
        {
            if (!Open())
            {
                return(false);
            }

            WriteLog("SendAsync:{0}", BitConverter.ToString(buffer));

            Task.Factory.StartNew(() => Serial.Write(buffer, 0, buffer.Length));

            return(true);
        }
Exemplo n.º 25
0
        /* ----------------------------------------------------------------------- *
        * ---------------------------                ---------------------------- *
        * ---------------------------  INTERRUPTION  ---------------------------- *
        * ---------------------------                ---------------------------- *
        * ----------------------------------------------------------------------- */

        /// <summary>
        /// Envoie à l'Arduino le changement d'état de l'interruption si faite via l'interface
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkBoxInterruption_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxInterruption.Checked == true)
            {
                Serial.Write("#INTE1\n");
                interruption = true;
            }
            else
            {
                Serial.Write("#INTE0\n");
                interruption = false;
            }
        }
Exemplo n.º 26
0
    private void ThreadLoop()
    {
        int ms = (int)(periodSec * 1000);

        while (true)
        {
            Thread.Sleep(ms);
            if (outputQueue.Count != 0)
            {
                Serial.Write((byte[])outputQueue.Dequeue());
            }
        }
    }
Exemplo n.º 27
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            Serial.Write("FN000000\r");    //envia a mensagem de finalização para o arduino
            tmrApp.Enabled = false;        //para a contagem do tempo do timer
            timeAquisicao  = string.Empty; //limpa a variável que informa o intervalo de tempo do timer

            Serial.Close();
            btnOpen.Enabled      = true;
            btnClose.Enabled     = false;
            btnExit.Enabled      = true;
            btnIniciar.Enabled   = false;
            btnFinalizar.Enabled = false;
        }
Exemplo n.º 28
0
        /// <summary>收到数据时触发</summary>
        /// <param name="buf"></param>
        protected virtual void OnReceive(Byte[] buf)
        {
            if (Received != null)
            {
                var e = new ReceivedEventArgs(buf);
                Received(this, e);

                // 数据发回去
                if (e.Feedback)
                {
                    Serial.Write(buf, 0, buf.Length);
                }
            }
        }
    void SmellStrenghtUpdate(Collider col)
    {
        if (distanceOdorStrength == true)
        {
            fieldOfViewStrength(col);
            strengthDistanceRatio(getColliderPos(col));
        }
        if (fieldOfView == true)
        {
            fieldOfViewStrength(col);
        }

        Serial.Write(openVentile());
    }
Exemplo n.º 30
0
        /* ----------------------------------------------------------------------- *
        * --------------------------                   -------------------------- *
        * --------------------------  CONTROLE MANUEL  -------------------------- *
        * --------------------------                   -------------------------- *
        * ----------------------------------------------------------------------- */

        /// <summary>
        /// Active/Desactive le controle manuel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkBoxControl_CheckedChanged(object sender, EventArgs e)
        {
            //Rend utilisable ou non le control manuel en fontion de la checkBox
            labelMax.Enabled = labelMin.Enabled = trackBarDegre.Enabled = numericMin.Enabled = numericMax.Enabled = labelDegre.Enabled = checkBoxControl.Checked;
            if (checkBoxControl.Checked)
            {
                Serial.WriteLine("#CMDM1");
            }
            else
            {
                Serial.WriteLine("#CMDM0");
                Serial.Write("#FSRS" + numericSensitivity.Value.ToString() + "\n");
            }
        }