Bugfix Arduino.cs

If you're having trouble with your LattePanda, here's the place to get help.
Forum rules
    Post technical issues here.

    - Discussion tone should be kept polite and focused on facts
    - Vulgar language or flaming constitutes an instant ban
    - Please note we cannot support PM requests for help
    - Members are asked to post in English only so that posts can be well received and properly monitored
    - You can find the RMA guide [here]
    - Please check if your question has already been answered before opening a new thread. If it has not, please verify the following:

    - Have you tried a hard reset?
    - Are you using a 5V@2A+ power supply and a high quality USB cable?
    - Have you tried powering the board through the CN2 headers?
    - Have you tried a cooling solution such as a fan or heatsink?
    - Have you tried reinstalling drivers?
    - Have you tried reloading the operating system?
    - Have you tried flashing the BIOS?
    - Are you able to flash the BIOS at the hardware level?

    If you have not found a solution, post a new issue. To speed up the process please let us know:
    - Have you tried the solutions listed above?
    - What board are you using? Standard (2GB RAM/32GB eMMC) or Enhanced (4GB RAM/64GB eMMC)?
    - Have you tried any other solutions?
    - How long have you had your board for?
    - When did you first boot your board?
    - Did it work ok before the issue occurred or has the issue always been there?
    - Use images and videos to help us understand the issue where possible

    If you are seeking RMA:
    - Please open a new topic rather than hijacking someone else's thread
    - Mark RMA posts with [DEFECTIVE] + <helpful description of issue>. We can then approve/disapprove each request
    - Completed RMA cases will be marked with [CLOSED]
    You can find the RMA guide [here]

    Resolved Issues
    - If you manage to fix an issue, please share your solution for the good of the community. It could help someone else in future.
    - If an issue is resolved the thread should be marked as [RESOLVED]. We can then sticky the thread to help people in future.

    What does troubleshooting support?
    - Hardware queries
    - Hardware issues that weren’t caused by you, e.g DOA board
    - Windows 10 specific issues
    Post Reply
    User avatar
    Posts: 2
    Joined: Tue Mar 14, 2017 8:28 am

    Tue Mar 14, 2017 8:45 am

    I have build up an Project for controlling an Fan for the LP cooling. All works fine but ...

    During the Programming i saw that my Programm did not closed correctly AND had an CPU Usage from about 30% Oo. That was huge for only one 10 second timer ;)

    After several debuging i found the Problem.

    We declare in C# an new Arduino like " Ardunio arduino = new Arduino();" Ok what now. This class generates in Background an new Thread with the name "processInput()". All fine ^^
    But when i looked at this Thread i saw the Problem. Inside we have no Sleeps for the Taskswitching. Thats why we have over 30% CPU Usage.

    Here the Fix:

    Goto the end of "while (_serialPort.IsOpen)" and insert "Thread.Sleep(10);" inside the while.

    Now my Program use 0% of the CPU ;) because we give Windows Time for Taskswitching xD

    if any one is interested in an Software controlled FAN based on the CPU Temperatures let me know i can upload all the sources. Currently i plan to include the whole OpenHardware lib.


    User avatar
    Posts: 4
    Joined: Mon Mar 13, 2017 10:53 am

    Tue Mar 14, 2017 2:04 pm

    You should not use Thread.sleep() because it ruined the performance so much

    I prefer CancellationTokenSource , it can reduce the resource usage a lot. But please concern about memory leak because of this class too.

    How to replace it

    Code: Select all

    CancellationTokenSource cancelsource = new CancellationTokenSource();
    http://stackoverflow.com/questions/8815 ... so-harmful
    http://stackoverflow.com/questions/1871 ... ed-in-c4-0

    User avatar
    Posts: 2
    Joined: Tue Mar 14, 2017 8:28 am

    Wed Mar 15, 2017 6:23 am

    Hi Castiel,

    this sounds OK, too.

    But,Im thinking about to change the communication way interrupt based with an serial data receive handler. This should remove the problem too.

    P.s.:Yesterday, i have include the openhardwaremonitor lib and all works like an charm.Now i clean up the GUI.

    Have a nice Day, Denaru

    User avatar
    Posts: 4
    Joined: Mon Mar 13, 2017 10:53 am

    Wed Mar 15, 2017 1:06 pm

    If you are using Firmata, I do apologize as first because I ever used before.

    In my project I wrote a sketch code and make it return line-by-line manually. This way is better than use Arduino.cs a lot. (My project really needs EEPROM access but....forget it :D )

    Why a lot C# programmers had a headache with Serial Communication?
    because C# must passing by many layers (Framework > OS > Hardware) that's why you see the data corrupt at High latency. And RS232 has an instant error at high baud rate.

    In short
    1. if you use around 9600 baud - no problem for C#
    2. if you use more than 115200 baud(with large data) - I really recommend to use C++ DLL (because it is a native language and very easy to access to hardware layer) then include to C# project and call it later.

    http://arduino.stackexchange.com/questi ... out-errors
    http://stackoverflow.com/questions/2256 ... 115200-bps


    User avatar
    Site Admin
    Posts: 2553
    Joined: Wed Jan 20, 2016 9:09 am

    Wed Mar 29, 2017 5:49 am

    Thanks for your feedback
    Enjoy Tinkering with LattePanda ! :lol:

    Post Reply