How to get faster serial port data transfer on windows forms
-
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
-
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
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
-
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
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
-
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
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.
-
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
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