|
Ok, this is your homework.
Do you have a problem or a question.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Hi,
Im currently making an app on windows forms trying to program a micro over UART. I can achieve it, although it is taking a long time to carry out the program. I have used stopwatches to determine it is my read function taking up the majority of the time. When i try to read the micros response from each command I have to wait for all of it, which is why im using a while loop in the code below, if the returned message size is not what i expect. What im wondering is, if there is any way to speed up this process. The response from the micro should be pretty fast, its running at a baudrate of 115200, meaning the whole 512 kb file should in theory take just over 30 seconds to complete, at the moment it is more than double that, at 80 seconds.
private string CheckResponse(int mSize)
{
string response;
int intBuffer;
intBuffer = ComPort.BytesToRead;
byte[] byteBuffer = new byte[intBuffer];
ComPort.Read(byteBuffer, 0, intBuffer);
response = Encoding.ASCII.GetString(byteBuffer);
while(response.Length != mSize)
{
intBuffer = ComPort.BytesToRead;
byteBuffer = new byte[intBuffer];
ComPort.Read(byteBuffer, 0, intBuffer);
response += Encoding.ASCII.GetString(byteBuffer);
}
return response;
}
Any help greatly appreciated.
Blair
|
|
|
|
|
You might want to post this under Hardware & Devices[^], though I imagine someone who can help will find it nonetheless.
|
|
|
|
|
There is no point "reading" when the "BytesToRead" equals 0. If you're expecting data, and BytesToRead == 0, you need to "wait" until the count > 0 and "time out" after a certain time if it doesn't.
A loop of synchronous reads with no data may be your problem.
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
|
|
|
|
|
All pair shortest path (FLOYDE Algorithm) who is interesting in learning it
|
|
|
|
|
This forum is for questions, not instruction. Feel free to write an article on it. I'd probably read it because I found graph theory to be the most useful area of mathematics when I was studying comp sci.
|
|
|
|
|
|
Hi,
I remember I used to do such algorithms in the university time... but that was 20 years ago lol
instead of inventing the wheel, I'm sure there is an efficient algorithm to do the following:
I have an array of values. size is not a matter... usually it is no more than 30-40 in size.
I need to split the array into sub groups, in a way that each subgroup is most efficiently close to value X (in our case 20). i.e smallest amount of groups with the highest value closest to X=20.
(in real world - we have a roll of material, length is 20 meter... and customers asking for material cutted in sized a,b,c,d.... and we want to cut it efficiently without losing material)
Appreciate any reference!
Thanks,
f.c.b.
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
Hello! I'm implementing a virus simulation where nodes (people) in a network infect neighbor nodes, and I want to define the average number of neighbors in the network generation settings. Now I'm generating a hex grid (with avg. 6 neighbors per node), but the nodes can have a link to any other node. I thought I could start with the hex grid and then remove and add links to other nodes by some method until I reach the average (being something between 3 and 16), but my attempts have led to a biased grid / fail. As this is a quite specific problem, I couldn't find any help from any articles etc.
So, if you have any ideas how to solve or approach this problem, I would appreciate 
modified 10-Apr-20 1:52am.
|
|
|
|
|
People and the virus don't live in a "grid"; it's a network.
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
|
|
|
|
|
"Nodes can have a link to any other node" means it's a network. I just initialize like a grid.
|
|
|
|
|
|
This is my first post 
|
|
|
|
|
Please don't spam the forums, they are for serious technical questions.
|
|
|
|
|
I have a a tree
Root
/ | \
V R M
/ | \ | \
L1 L2 Sub L6 MCon
/\
L3 L4 \
L7
class Container {
Id getUid()
leafList getLeafs() { return leafs; }
leafs
}
class Leave {
Id getUid()
}
Where in the above Tree is N Ary tree
Root ,V,R,C,Sub,RLcon,MCon are Containers
L1,L2,L3,L4,L6,L7 are leaf nodes
I have following data
1) root container pointer
2) root.getContainers - return list of sub containers - for example
root.getContainers will return here V,R,and M
V.getContainers will return Sub
V.getLeafs will return L1,L2,
I have a Create a Yaml Dump from Nested Ordered Dictionary
The dump of output nested dictionaries is as follows
V:
UidOfL1:
Name :L1
type : leafOfV
UidOfL2:
Name :L2
type : leafOfV
UidOfSub:
Name :Sub
type : Container
R:
UidOfL6:
Name :L6
type : leafOfR
MCon:
UidOfL7:
Name :L7
type : leafOfM
The algorithm has to be designed using OrederedDict of python
Can someone help me to write the correct and optimized algorithm in python
|
|
|
|
|
|
Ttt
modified 28-Mar-20 5:14am.
|
|
|
|
|
Something like:
let pos1 = first_of(str)
let pos2 = last_of(str)
while ( pos1 < pos2 )
do
while ( isdigit(str[pos1]) AND pos1 < pos2 )
do
incr pos1
done
while ( isdigit(str[pos2]) and pos1 < pos2 )
do
decr pos2
done
# having got here, we know that either
# pos1 and pos2 are non-digits, so we can swap them
# or pos2 < pos1, which means we are done (while loop will terminate)
if ( pos1 < pos2)
then
swap(str[pos1], str[pos2])
incr pos1
decr pos2
endif
done
Keep Calm and Carry On
|
|
|
|
|
Editing your message to remove your question after it has been answered is extremely rude.
If you think it's going to stop your teacher / boss from finding out that you're cheating on your homework / work, you're sadly mistaken.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|