GithubHelp home page GithubHelp logo

Comments (2)

dwilches avatar dwilches commented on August 27, 2024 1

Attempting to print an unprintable character (like 128) can yield weird outputs (because they are unprintable). Normally what you do with those characters is to print their ASCII value, not the character itself.

from ardity.

guiglass avatar guiglass commented on August 27, 2024

Well, I created a solution... Turns out it was to do with serialPort.ReadLine() and the way it converts to string. Not sure why it was adding question marks (completely ridiculous actually). But what I threw together reads in a line of bytes directly instead of using Readline()

SerialThreadLines.cs

    /*OLD WAY
    protected override object ReadFromWire(SerialPort serialPort)
    {
        return serialPort.ReadLine();
    }
    */

    /*NEW WAY*/
    private List<byte> buffer = new List<byte>();
    protected override object ReadFromWire(SerialPort serialPort)
    {
        buffer.Add( (byte)serialPort.ReadByte() );

        // Search for the separator in the buffer
        int index = System.Array.FindIndex<byte>(buffer.ToArray(), 0, buffer.Count, IsSeparator);
        if (index == -1)
            return null;

        buffer.RemoveAt (buffer.Count - 1); //remove CR
	buffer.RemoveAt (buffer.Count - 1); //remove LF

        var output = buffer.ToArray ();
        buffer.Clear ();

        return output;
    }

    private bool IsSeparator(byte aByte)
    {
        return aByte == '\n';
    }

Above could really use some optimization but it's simply conceptual.

from ardity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.