Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. How to get faster serial port data transfer on windows forms

How to get faster serial port data transfer on windows forms

Scheduled Pinned Locked Moved Algorithms
csharpwinformsadobeperformancetutorial
5 Posts 3 Posters 14 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14809996
    wrote on last edited by
    #1

    Hi all, I have been working on uploading a .bin file to a micro with basically a hello world project inside. Although i find that it could definitely be faster when uploading the contents of the file to the micros ram, where it then copies it to flash. Where this data is transferred is located in the code below: for (int i = 0; i < Page.numPages; i++) { Write2Ram("536871680", "512"); ComPort.Write(code, start_Address_Code, 512); Write2Ram("536872192", "512"); ComPort.Write(code, start_Address_Code + Page.ram_Size, 512); copy2Flash(flash_Address, "536871680", "1024"); int_Address = int.Parse(flash_Address); flash_Address = (int_Address + Page.flash_Size).ToString(); start_Address_Code += Page.flash_Size; backgroundWorker1.ReportProgress(0); } Is there anything that sticks out that could be improved for speed? Increasing the baud rate increases the speed for sure, but not as quickly as some other applications are capable of and i dont really understand why. This is my first windows forms project and i am a little new to C#. @ 460800 baud rate it currently takes 60 seconds to upload a roughly 500kb file. Many thanks, Blair

    K L 2 Replies Last reply
    0
    • M Member_14809996

      Hi all, I have been working on uploading a .bin file to a micro with basically a hello world project inside. Although i find that it could definitely be faster when uploading the contents of the file to the micros ram, where it then copies it to flash. Where this data is transferred is located in the code below: for (int i = 0; i < Page.numPages; i++) { Write2Ram("536871680", "512"); ComPort.Write(code, start_Address_Code, 512); Write2Ram("536872192", "512"); ComPort.Write(code, start_Address_Code + Page.ram_Size, 512); copy2Flash(flash_Address, "536871680", "1024"); int_Address = int.Parse(flash_Address); flash_Address = (int_Address + Page.flash_Size).ToString(); start_Address_Code += Page.flash_Size; backgroundWorker1.ReportProgress(0); } Is there anything that sticks out that could be improved for speed? Increasing the baud rate increases the speed for sure, but not as quickly as some other applications are capable of and i dont really understand why. This is my first windows forms project and i am a little new to C#. @ 460800 baud rate it currently takes 60 seconds to upload a roughly 500kb file. Many thanks, Blair

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      Short of having a serial break-out box so you can monitor the signals, its difficult to know what to suggest. At 460800 baud it should take less than 15 seconds to transfer a 500kb file. What we don't know is how large a receive buffer is on the micro, and how fast it can process the data arriving there. Probably what is going on is that the micro's receive buffer gets filled, so it signals the PC to stop sending, the micro processes some data from the receive buffer and then signals the PC to start sending again. There are software breakout boxes available if you google for it. I'd think I would grab one and take a look at the signals being generated and see if that's where your problem is.

      Keep Calm and Carry On

      M 1 Reply Last reply
      0
      • M Member_14809996

        Hi all, I have been working on uploading a .bin file to a micro with basically a hello world project inside. Although i find that it could definitely be faster when uploading the contents of the file to the micros ram, where it then copies it to flash. Where this data is transferred is located in the code below: for (int i = 0; i < Page.numPages; i++) { Write2Ram("536871680", "512"); ComPort.Write(code, start_Address_Code, 512); Write2Ram("536872192", "512"); ComPort.Write(code, start_Address_Code + Page.ram_Size, 512); copy2Flash(flash_Address, "536871680", "1024"); int_Address = int.Parse(flash_Address); flash_Address = (int_Address + Page.flash_Size).ToString(); start_Address_Code += Page.flash_Size; backgroundWorker1.ReportProgress(0); } Is there anything that sticks out that could be improved for speed? Increasing the baud rate increases the speed for sure, but not as quickly as some other applications are capable of and i dont really understand why. This is my first windows forms project and i am a little new to C#. @ 460800 baud rate it currently takes 60 seconds to upload a roughly 500kb file. Many thanks, Blair

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You're copying to 2 devices in series; consider using 2 threads / tasks in parallel. And use Stopwatch to identify the bottlenecks.

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

        M 1 Reply Last reply
        0
        • L Lost User

          You're copying to 2 devices in series; consider using 2 threads / tasks in parallel. And use Stopwatch to identify the bottlenecks.

          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

          M Offline
          M Offline
          Member_14809996
          wrote on last edited by
          #4

          So I've replaced the two write to RAM functions with just one that writes all 1024 bytes of RAM instead which has saved some time, although i'm still way off where i should be with my timing.

          1 Reply Last reply
          0
          • K k5054

            Short of having a serial break-out box so you can monitor the signals, its difficult to know what to suggest. At 460800 baud it should take less than 15 seconds to transfer a 500kb file. What we don't know is how large a receive buffer is on the micro, and how fast it can process the data arriving there. Probably what is going on is that the micro's receive buffer gets filled, so it signals the PC to stop sending, the micro processes some data from the receive buffer and then signals the PC to start sending again. There are software breakout boxes available if you google for it. I'd think I would grab one and take a look at the signals being generated and see if that's where your problem is.

            Keep Calm and Carry On

            M Offline
            M Offline
            Member_14809996
            wrote on last edited by
            #5

            So i think you are right, i downloaded a serial port sniffer and have determined the data from a 1024 buffer needs to be written in a queue of 45 bytes at a time to allow the micro to process it. Any idea how i would begin to do this? or a link to an example? Many thanks, Blair

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups