logo
Tags down

shadow

Using SerialPort variable through MainWindow


By : Ryan Schaffner
Date : August 02 2020, 11:00 AM
I hope this helps . return an instance of SerialPort from method and store it in a window field instead of local variable:
code :
private SerialPort CheckPort()
{
    string[] listPort = SerialPort.GetPortNames();
    foreach(string namePort in listPort)
    {
        SerialPort port = new SerialPort(namePort, 9600);
        if (!port.IsOpen)
        {
            port.Open();
            string data = port.ReadTo("\r\n");
            if (data == "A")
            {
                port.Write("777"); // to make it stop sending "A"
                return port;
            }
        }
    }
    return null;
}

SerialPort port;

public MainWindow()
{
    port = CheckPort();
    InitializeComponent();
}

private void Button_ClickClose(object sender, RoutedEventArgs e)
{
    if (port == null) return;
    port.ReadTo("\r\n");
    port.Write("hey");
}


Share : facebook icon twitter icon

how to acces SerialPort.Flush() and SerialPort.Finalize() functions


By : Sorin Stan
Date : March 29 2020, 07:55 AM
I wish this helpful for you http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx : no Flush. You are looking at the .Net Micro Framework, which apparently does have a Flush
Finalizers are called by GC at the end of garbage collection. They aren't externally accessible by user code, nor should they be explicitly called.

node serialport not displaying serialport data in raspberryPI


By : rewol
Date : March 29 2020, 07:55 AM
Hope this helps You could see if it is a linux permission thing.
Have you installed it on you linux machine?
code :
nmp install serialport

SerialPort visible in device manager but SerialPort.Open() reports that it cannot be found


By : CenturyX476
Date : March 29 2020, 07:55 AM
I hope this helps you . Try Disable serial port from and then reenable. Also check whether problem with hardware. You can check it by inserting usb device in serial port. If works proper. Use debugger to check code.

DataBinding C# ObservableCollection SerialPort to Combobox (SerialPort.getPortNames=>Method that return array of stri


By : Kate Penrose
Date : March 29 2020, 07:55 AM
should help you out initalize the ObservableCollection of string and give the list of ports.
code :
public ObservableCollection<String> ListOfAvaliablePorts { get; set; }


 ListOfAvaliablePorts = new ObservableCollection<String>(SerialPort.GetPortNames());

.NET CORE(on windows), DataReceived called frequency of one serialPort effected by other serialPort


By : John Hanson
Date : March 29 2020, 07:55 AM
hope this fix your issue After some testing and post from web, I confirmed this behavior on .NET CORE, that multiple SerialPort write&receive could delay the firing of the DataReceived, so rather than wait, I've added a code to actively pull
code :
    public void Start()
    {
        this.comPort.DataReceived += (_,__)=>{this.PullPortDataBuffer();};
        //for very fast time accurate call(my app send&receive data every 200ms), use dedicated thread rather than timer.
        this.pullingSerialPortBufferLoop = new Thread(() =>
        {
            while (true)
            {                
                Thread.Sleep(200);
                this.PullPortDataBuffer();
            }
        });
        this.pullingSerialPortBufferLoop.Start();
    };
    var buffer = new List<byte>();
    private void PullPortDataBuffer()
    {
        if (0 == Interlocked.CompareExchange(ref this.onPullingComPortBuffer, 1, 0))
            try
            {

                while (this.comPort.BytesToRead > 0)
                {                        
                    this.buffer.Add((byte)b);
                }

                this.ConsumeBufferIfFull(this.buffer);
            }
            catch (Exception ex)
            {}
            finally
            {
                this.onPullingComPortBuffer = 0;
            }
        else
        {
            if (logger.IsDebugEnabled)
                logger.Debug(this.comPort.PortName + " concurrent enter Port_DataReceived");
        }
    }
Related Posts Related Posts :
  • Access properties of a virtual class in partial class
  • Does calling multiple times save() method of hibernate with same object insert new record in DB?
  • how to give multiple runtime permissions in android Q programmatically
  • Rules for top-level function definitions order in Racket and Common Lisp
  • API to insert data to array of objects in mongoDB
  • String parsing in ruby
  • How to close this modal
  • Validate a input dict schema
  • Allow user to copy text from a password field
  • is there something wrong with this JavaScript if statement?
  • How to perform edit action in ASP.net Core?
  • Filtering on Keys inside an array of objects
  • Docker installation on Windows 10 Home
  • How to modify a list value in a nested custom datatype?
  • How to post a message to google chat room using C#? (**Error**: Request had insufficient authentication scopes)
  • Difference between Account-level and User-Level Network Policies
  • Single Number solving by Haspmap, return always be a "@"
  • How to get all USA timezone IDs using nodatime
  • How to check if a user is already created, if not, create, else show an error message that a user is created Laravel
  • create strings using combinations of list items
  • Concat values in postgresql without null values
  • multiple usage of ggplot
  • Create a loop to label dates base on month without the use of many multiple 'case', 'between'
  • Change color of leaflet map
  • Polymer/Lit-element, child component doesn't re-render when the property is modified by the parent
  • Why is static_cast used in QT's official document
  • How to pass object of unknown type to function
  • Size of picture in background repeat?
  • Angular 8 - How to handle error response?
  • store strings in stable memory in c++
  • how to convert HAC flexible query to DAO query
  • Cannot refresh UI if update in ItemView
  • iterator .end() from std::list returns "0xcdcdcdcdcdcdcdcd" but .begin() as expected
  • How to make a function to use dict keys as variables to a class?
  • Using disabledDate in Antd Datepicker in table
  • Best approach to remove cassandra-topology.properties file in running cluster nodes
  • Replace values in XML file with values of a vector
  • Convert old SQL Database in compatibility mode
  • plsql store procedure loop compare value
  • Sum same property object by group
  • Is std::sqrt the same as sqrt in C++
  • What do you do about the JLabel classes? It says, "JLabel not a statement" for the error
  • How to add a CSS to this JavaScript or HTML on click buttons?
  • Iterate through std::initializer_list
  • Functional Interface call for a new Instance
  • Is it OK to inherit an empty Interface?
  • Why does the overidden run method in java.lang.Thread produce a bizarre output?
  • Typescript: type one parameter based on the other
  • changing background image of div using javascript
  • Microsoft Bot Framework: Smilies in MS Teams
  • Codeblocks c++ code doesn't run in VS 19 (vector subscript out of range)
  • How to convert two arrays of strings to the array of objects like key and value with particular keys in javascript?
  • What is the fastest way to find if a column has at least one NULL value in ORACLE database?
  • Rename headers - 'list' object is not callable
  • Authorize with both ASP.NET core MVC/Razor site AND a WebAPI
  • When I tried to add ArrayList into ArrayList second ArrayList is repeating
  • If I implement IEquatable<T>, will I lose the option to compare by reference?
  • Is it possible to pass data from an angular7 component or service to index.html file?
  • Passing res.send value from node.js backend to react.js
  • Vim shortcuts to select and copy the current line without the next line
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org