Forum Xamarin.Forms

Get the selected entry to only update this when serial scanning

ElixiumElixium Member ✭✭
edited December 2018 in Xamarin.Forms


I have been working with scanner devices, only using keyboard interfaces and i had no problems, because you only have to select the entry where you want to "paste" the value of the scanned barcode, and scan. Nothing more, the scanned value actually updates the entry value where you are pointing to.

But now that i have to use the serial interface to use COM ports, and i have a problem.

What i have succesfully done since now is:

1- open the serial port where my barcode scanner device is connected,

            serialPort = new SerialPort();


            serialPort.PortName = portName;
            serialPort.BaudRate = baudRate;
            serialPort.Parity = parity;
            serialPort.DataBits = dataBits;
            serialPort.StopBits = stopBits;

            // Set the read/write timeouts
            serialPort.ReadTimeout = 500;
            serialPort.WriteTimeout = 500;

            serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);


                this.IsOpen = true;
            catch (Exception e)
                throw new Exception(e.Message);

            return true;

2- Listen to the scan event and update the value of the "ScannedText" variable (located in BaseViewModel.cs) to show the barcode value on the xaml:

private void DataReceivedHandler(object sender, EventArgs e) //SerialDataReceivedEventArgs
            SerialPort sp = (SerialPort)sender;
            text = sp.ReadExisting();

            //Send the value to the ViewModel
            BaseViewModel.Current.ScannedText = text;


<Entry x:Name="BarcodeEntry" Text="{Binding ScannedText, Source={x:Static base:BaseViewModel.Current}}"

THIS WORKS, the value of the scanned barcode is printed on the xaml entries where the binding variable is the "ScannedText" variable.

But what if i have more than one entry on my page and i want to update ONLY the entry value where i'm actually pointing, and do nothing to the other one? I guess i don't should use variables for this and send the entry to the event, but don't know how. I'm really stucked.



  • crigintcrigint Member ✭✭

    I'm trying to send text data to serial port ("/dev/ttyS1") and I fell in this post.
    Are you used System.IO.Ports? Because it doesn't work. I receive the error message: System.IO.Ports is only supported on Windows.

    Can you help me please?

Sign In or Register to comment.