Data Receive/Transmit through Bluetooth Virtual COM Port

Hello everyone,
I want to data receive/transmit through Bluetooth Virtual COM Port by changing Baud Rate.

Are there any idea for how I will do this?

Best Answer

  • gokhangocmengokhangocmen TR ✭✭
    Accepted Answer

    I can Receive/Transmit datas anymore.

    private void writeData(Java.Lang.String data)
    {
    try
    {
    outStream = btSocket.OutputStream;
    }
    catch (System.Exception e)
    {
    System.Console.WriteLine("Send Error" + e.Message);
    }

            Java.Lang.String message = data;
    
            byte[] msgBuffer = message.GetBytes();
    
            try
            {
                outStream.Write(msgBuffer, 0, msgBuffer.Length);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("Send Error" + e.Message);
            }
        }
    
        public void beginListenForData()
        {
            try
            {
                inStream = btSocket.InputStream;
            }
            catch (System.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Task.Factory.StartNew(() => {
                byte[] buffer = new byte[1024];
                int bytes;
                while (true)
                {
                    try
                    {
                        bytes = inStream.Read(buffer, 0, buffer.Length);
                        byte[] readBuf = (byte[])buffer;
                        var readMessage = new Java.Lang.String(readBuf, 0, bytes);
                        if (readMessage != null)
                            RunOnUiThread(() => {
                                Result.Append(readMessage);
                                scrollView.SmoothScrollTo(0, Result.Bottom);
                            });
                    }
                    catch
                    {
                        RunOnUiThread(() => {
                            Result.Text = string.Empty;
                        });
                        break;
                    }
                }
            });
        }
    

Answers

  • gokhangocmengokhangocmen TRMember ✭✭
    Accepted Answer

    I can Receive/Transmit datas anymore.

    private void writeData(Java.Lang.String data)
    {
    try
    {
    outStream = btSocket.OutputStream;
    }
    catch (System.Exception e)
    {
    System.Console.WriteLine("Send Error" + e.Message);
    }

            Java.Lang.String message = data;
    
            byte[] msgBuffer = message.GetBytes();
    
            try
            {
                outStream.Write(msgBuffer, 0, msgBuffer.Length);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("Send Error" + e.Message);
            }
        }
    
        public void beginListenForData()
        {
            try
            {
                inStream = btSocket.InputStream;
            }
            catch (System.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Task.Factory.StartNew(() => {
                byte[] buffer = new byte[1024];
                int bytes;
                while (true)
                {
                    try
                    {
                        bytes = inStream.Read(buffer, 0, buffer.Length);
                        byte[] readBuf = (byte[])buffer;
                        var readMessage = new Java.Lang.String(readBuf, 0, bytes);
                        if (readMessage != null)
                            RunOnUiThread(() => {
                                Result.Append(readMessage);
                                scrollView.SmoothScrollTo(0, Result.Bottom);
                            });
                    }
                    catch
                    {
                        RunOnUiThread(() => {
                            Result.Text = string.Empty;
                        });
                        break;
                    }
                }
            });
        }
    
Sign In or Register to comment.