|
I am trying to transmit about 75Kbytes of image data at 115200 baud. Ideally it should take about 5 secs. But this code seems to loop forever. Am I missing something obvious here?
#define rows 288
#define cols 352
for (j=rows-2; j>=0; j-=2)
{
for (i = (j*cols); i<((j*cols)+cols); i++)
{
cam_output = ram_read(i*4);
SendBuffer[0] = (cam_output >> 24) & 0xff;
SendBuffer[1] = (cam_output >> 16) & 0xff;
SendBuffer[2] = (cam_output >> 8) & 0xff;
uart_send(&SendBuffer, 3);
}
}
void uart_send(u8 *DataBufferPtr, unsigned int NumBytes)
{
int i;
for (i=0; i<NumBytes; i++)
{
XUartLite_SendByte(XPAR_UARTLITE_0_BASEADDR, *(DataBufferPtr+i));
}
}
Regards,
Karthik
|
|
|
|
|
Hi,
that is not C# code, so you're in the wrong forum.
your code does not look good
I'm not going to study it in any detail, unless you put it inside PRE tags (you can still edit your message)
is the other side receiving anything? how much?
does your code ever finish (say within calculated time * 10)?
|
|
|
|
|
@Luc: On the other side, my image file keeps growing > 1.8MB. The code never finishes.
|
|
|
|
|
so look at what is in the file; there should be 288/2 * 352 * 3 = about 150KB:
- are the first 150KB what you expect? if not, is there a pattern in the differences?
- what's there after 150KB?
this is call debugging: observe, observe closer, when something isn't what it seems, look at an earlier point, bring the last good point and the first bad point closer together, until you know where it goes wrong, then fix it.
|
|
|
|
|
Yes, I did check the image. It was garbled. Then I realized my mistake in the calculation of rows and cols... it should be 144 x 176.
But that didnt solve the infinite loop until i was able to debug on hardware. I noticed j decreased to 0 and then increased back to the highest (32bit) value. Realized the mistake of making j unsigned int .
Loop ends now
Thank you!
|
|
|
|
|
Some compilers warn when a test is bound to always result in the same value; apparently yours didn't then.
I always use my compiler at the highest warning level, and massage the code until it emits zero warnings!
|
|
|
|
|
True. I am compiling this in the Xilinx SDK.
|
|
|
|
|
Starting with the fact that your code does not compile as it stands, I have got it to run through in a couple of minutes; obviously without the data transfer. I guess you should check that the data is actually getting transmitted OK.
[edit]Also note this is C++ so should be in that forum[/edit]
|
|
|
|
|
hi,
Simple question. I'm trying to get the xml in an XmlDocument variable into a string. Seems like its a tough thing and I tried the OuterText property but it gives me encoded text like : >< So, does anybody have a decent solution to this.
Thanks
Gideon
|
|
|
|
|
Try this:
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
xmlDoc.WriteTo(xw);
return sw.ToString();
where xmlDoc is your xml doc
Let me know if it works
|
|
|
|
|
|
nope, both solutions have encoded text!
|
|
|
|
|
Hi,
Quick and simple question
Is there a simple way to sync a sql2005 db with a sqlCe database on a mobile device.
Is there a default path on a windows mobile device where i can connect to (c:\....) ?
I need a fixed path on the mobile device to push the updates to.
Thanks for the advice.
grtz
Wouter
|
|
|
|
|
Let's say you define this class (at the namespace level; i.e., outside
a form or whatever)
public class anyDamnList<T> : List<T>
{
public anyDamnList() { }
}
And you declare and use it ... in a form's code ... with no problems :
anyDamnList<int> aYIntList = new anyDamnList<int>();
aYIntList.Add(100);
aYIntList.Add(200);
Console.WriteLine(aYIntList[1]);
List<int> intList3 = new List<int> { 9, 19, 22, 44 };
aYIntList.Clear();
aYIntList.AddRange(intList3);
Console.WriteLine(aYIntList[3]);
Here's the question : is there any other way than using 'Clear() and then 'AddRange
to replace the "virtual inner list" <T> "embodied" via inheritance in the class ?
1. you cannot assign to an instance of the class : aYIntList = intList3;
You get this error : "Error Cannot implicitly convert type
'System.Collections.Generic.List<int>' to
'WindowsFormsApplication1.anyDamnList<int>'. An explicit conversion
exists (are you missing a cast?_
2. you can't cast like this : aYIntList = (anyDamnList<int>) intList3
: that will NOT give you a compile time error but at run-time you get
: ""Unable to cast object of type
'System.Collections.Generic.List`1[System.Int32]' to type
'WindowsFormsApplication1.anyDamnList`1[System.Int32]'."}
3. I played around with Linq's OfType<> and Cast<> operators
aYIntList = intList3.OfType<int>();
aYIntList = intList3.Cast<int>();
Both of those will throw compile time errors like so : "Cannot
implicitly convert type 'System.Collections.Generic.IEnumerable<int>'
to 'WindowsFormsApplication1.anyDamnList<int>'. An explicit conversion
exists (are you missing a cast?)"
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
You could write an implicit (or explicit) conversion operator.
Or write a ClearAndAddRange method.
Edit:
OK, a conversion operator won't work:
user-defined conversions to or from a base class are not allowed
and
user-defined conversions to or from an interface are not allowed
But a copy constructor will work:
public anyDamnList
(
System.Collections.Generic.IEnumerable<T> Source
)
{
this.AddRange ( Source ) ;
return ;
}
anyDamnList<int> ai = new anyDamnList<int> ( intList3 ) ;
modified on Sunday, December 13, 2009 10:54 AM
|
|
|
|
|
Hi PieBaldConsult,
Well, I thought I was writing 'implicit and/or 'explicit conversion operators in the attempts I documented in the question that result in compile-time and run-time errors.
And, while, yes, I could write a ClearAndAddRange method : the whole purpose of the question is part of my "self-education" in Linq which (for me) is best done by posing problems and then trying to solve them.
I have the feeling that somewhere there's a way to use some of the Linq commands like ConvertAll, Cast, OfType that will do the "right thing" easily. to get from one List<int> instance into a form that can be assigned to an instance of 'anyDamnList.
After all, if you build the example and type instanceOfAnyDamnList. ... you get the intellisense you expect including methods like 'Count.
This is the kind of question that Jon Skeet could answer in his sleep
Thanks for responding !
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
|
Please don't bother to respond further; wasting your time is one thing; wasting my time is another.
Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
|
If you add a constructor that takes an IEnumerable and call the base constructor then you can just assign the List as a new instance. It doesn't exactly answer your question but gives you a workaround...
public class AnyDamnList<T> : List<T>
{
public AnyDamnList()
: base()
{ }
public AnyDamnList(int capacity)
: base(capacity)
{ }
public AnyDamnList(IEnumerable<T> collection)
: base(collection)
{ }
}
AnyDamnList<int> anyDamnList = new AnyDamnList<int>((new List<int>() { 1, 2, 3 }));
List<int> list = new List<int>() { 1, 2, 3 };
anyDamnList = new AnyDamnList<int>(list);
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Dave,
Thanks for the responsible answer. I am using C#4, by the way.
I'm familiar with using automatic properties, and automtatic property initializers.
What I am curious about here is that :
1. once you've defined an instance of AnyDamnList<sometype> : you can type in the instance name followed by a dot and get all the intellisense you'd expect for an instance of List<sometype> including "non-generic" properties like 'Count. You've got access to methods like 'Add, 'AddRange, GetRange, indexing with [] : in other words your instance "embodies" a List<t>.
2. using your class definition above you still cannot assign another List<int> to an instance of AnyDamnList<int> directly :
anyDamnList2<int> aYIntList = new anyDamnList2<int>();
aYIntList.Add(100);
aYIntList.Add(200);
Console.WriteLine(aYIntList[1]);
List<int> intList3 = new List<int> { 9, 19, 22, 44 };
aYIntList = intList3;
Console.WriteLine(aYIntList[3]);
When you get the error at compile time : "Cannot implicitly convert type 'System.Collections.Generic.List<int>' to 'WindowsFormsApplication1.anyDamnList2<int>'. An explicit conversion exists (are you missing a cast?)"
The fact that the error output indicates "an explicit conversion exists."
Leads me to think that somewhere in the "galaxy" of Linq's many operators/extensions that do conversions ( OfType, Cast, ConvertAll, ToList, and so forth ), or just in the typical ways we now do casting, is a way to get this done without, as in your, much appreciated example :
anyDamnList = new AnyDamnList<int>(list);
Which is essentially discarding the current instance (of 'anyDamnList ) and replacing it with a new instance.
A friend of mine has suggested : "look at implementing the IEnumarable<T> interface instead of inheriting from List<T>."
So maybe that's the next step. And, of course, going back to study Skeet's book more
thanks, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
BillWoodruff wrote: I am using C#4
Then it should either work as is or you need an implicit conversion operator.
|
|
|
|
|
There's nothing new or LINQish about the explicit cast its talking about. That is just the standard cast to derived. It's not implicit for the same reason you could not assign a Mammal varaible into a Cat variable even if the Mammal variable is holding a Cat.
|
|
|
|
|
Gideon Engelberth wrote: There's nothing new or LINQish about the explicit cast its talking about. That is just the standard cast to derived. It's not implicit for the same reason you could not assign a Mammal varaible into a Cat variable even if the Mammal variable is holding a Cat.
Here we are talking about strongly typed generic class templates, not specific instances of specific classes.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
BillWoodruff wrote: Here's the question : is there any other way than using 'Clear() and then 'AddRange
to replace the "virtual inner list" <t> "embodied" via inheritance in the class ?
No. anyDamnList "is a" List<int> -> the particular List is an inherent part of a particular instance of anyDamnList -> you cannot replace just the "List part" of an anyDamnList.
That's just the way inheritance works.
LINQ won't help either. LINQ mostly knows about interfaces: IEnumerable and IQueryable; and a little about List and Array. It knows nothing about anyDamnList.
If you want to be able to plug in a new List part into an anyDamnList, you would have to use composition:
public class anyDamnList
{
private List<int> _InnerList;
public void ReplaceInnerList( List<int> newList )
{
_InnerList = newList;
}
}
If you also want anyDamnList to behave like a List<int>, so you can do this:
int count = myAnyDamnList.Count;
Then you can implement the same interfaces as List<int>:
public class anyDamnList : IList<int>
Unfortunately, you have to implement the interfaces yourself:
int Count { get { return _InnerList.Count; } }
This is a pain, but is do-able. Since C# doesn't support multiple inheritance, which means you end up using composition a lot, it would be nice IMHO if there was an implementedBy keyword:
public class anyDamnList : IList<int>
{
IList<int> implementedBy _InnerList;
}
But I've never heard anyone else even suggest this.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|