|
C-P-User-3 wrote: I have seen other apps run 921600 on this very machine right in front of my
eyes.
That baud rate has to be user defined. It's not going to be in the base Windows API or the .NET Framework. It's extremely rare to find any use for a RS232 port faster than 115200.
Frankly, with a baud rate like that, the cable would have to be sheilded in lead and a max of 3 feet long for it to work with any reliability.
|
|
|
|
|
Clarification: I'm using BlueTooth across a USB (i.e., Fake-out) UART.
This is the hardware which I've seen do 921600 Bits Per Second, with "Terminal by Br@y" and 230400 with "TERMite" and maybe Hyperterminal as well.
(Hyperterminal hates my guts; he's really got it in for me; don't know why.)
|
|
|
|
|
Total time waste. Sorry for the trail of the red herring.
I discovered the big liar in all this.
Well, not sure exactly who is lying, but I have at least dissected the lie from the truth.
The lie: the limit is 115200
The truth: If you open that port at a speed of 115200, he can, and will, and does, deliver a speed of 921600. It also works at even lower speeds.
To really grasp the magnitude of this, check out these results...
-- I opened the port at 1200 bps.
-- The other side was doing 921600.
-- It worked.
|
|
|
|
|
How can I dispatch 30 threads to do 30 things ?
How do those threads inform each other of what they are doing ?
I looked up the word "Semaphore" on the MSDN site, and here as well. Apparently, C# and embedded systems have markedly different definitions of that term.
Still newbee noclue.
I'm watching some YouTube videos on the topic, still learning, really interesting, I think that threading will do what I want it to do.
Input is welcome.
|
|
|
|
|
|
Thank you. This stuff is relevant to my interests !
|
|
|
|
|
I have found the paper very helpful. It has been updated a few time, especially with TPL. Sort of got back to it after reading up on TPL in Task Parallel Library: 1 of n[^]
|
|
|
|
|
hi ,
I got an object which is a generic, at runtime i pass the type for T and create the proper object. the generic object as follows
class parent <T>
{
string name;
T childObject;
}
I create the parent<x> in runtime using the reflection , for e.g.
Type type = x;
Dynamic response = Activator.CreateInstance(typeof(parent<>).MakeGenericType(type));
it works fine , but the problem is when I try to assign an object to response.childObject it gives me an exception saying that i'm missing cast and it cannot implicitly cast the object.
the object try to assign is also created using reflection,
ADDED LATER: I'm not sure this part will be important for this issue , but anyway , the object i'm trying to assign to response.childObject is also an object created by deserialization , means
for in order to deserialize this object i have to give the type , so that type also crated using reflection in a similar way described above.
i would really appreciate your help on this.
thanks in advance.
modified 31-Oct-12 12:43pm.
|
|
|
|
|
I dont know how it actual works if I am honest (as I found the question interesting) but my modifying your code to this
Type t = typeof(Parent<>);
int y = 1234;
Type type = y.GetType();
dynamic response = Activator.CreateInstance(t.MakeGenericType(type));
response.MyValue = 123;
public class Parent<T>
{
public string name = string.Empty;
public T MyValue;
}
I was able to assign a value to the property MyValue.
*Edit* Not sure if it helps but I've just read through this MSDN article on Type.MakeGenericType[^], I found this an interesting Question
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
thanks , I also tried the value types and it works , but the problem came when i'm trying to assign reference type.
|
|
|
|
|
Type t = typeof(Parent<>);
Type type = typeof(Data);
dynamic response = Activator.CreateInstance(t.MakeGenericType(type));
Data es = new Data() { Name = "Fred", value = 213 };
response.value = es;
public class Parent<T>
{
public string name = string.Empty;
public T value;
}
public class Data
{
public string Name = string.Empty;
public int value = 0;
}
I have also tried it with the following and it still works can you expand your problem with some sample code? or a snippet?
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Thanks again , ok then I think I have to focus on the deserialzed object , unfortunately i haven't got the code snippet right now , but I will definitely post that code snippet soon.
thanks .
|
|
|
|
|
Your welcome
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
hi ,
this is how i'm doing the deserialization
Type genericSyncObj = typeof(SyncObject<>);
Type syncObj = genericSyncObj.MakeGenericType(type);
IList customObjectList = (IList)Activator.CreateInstance((typeof(List<>).MakeGenericType(type)));
foreach (string value in pullRequest.Knowledge)
{
dynamic syncObject = JasonSerializer.Deserialize(value, syncObj, null);
customObjectList.Add(syncObject.Object);
}
and i'm getting the exception at here
dynamic responseSync = Activator.CreateInstance(typeof(SyncObject<>).MakeGenericType(type));
responseSync.Object = customObjectList[y] ;
thanks .
|
|
|
|
|
The problem is that customObject[y] is returned as an object which is why it fails.
if you then hard code a cast such as for example.
responseSync.Object = (SomeTestClass)customObject[y];
it works as you need it to do, but how to create this as a generic routine I'm not sure at the moment as (typeof(SomeTestClass))customObject[y] or even (typeof(SomeTestClass))CustomObject[y] is rejected by the compiler.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
thanks , yes this is the place where i'm stuck , need to cast in runtime , if you find a way please share it .
|
|
|
|
|
IList datalist = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(typeof(Data)));
datalist.Add(new Data {Name = "SIMON", value = 1});
datalist.Add(new Data {Name = "SIMON", value = 2});
datalist.Add(new Data {Name = "SIMON", value = 3});
Type t = typeof(Parent<>);
Type type = typeof(Data);
dynamic response = Activator.CreateInstance(t.MakeGenericType(type));
Type SingleRecordType = datalist[0].GetType();
dynamic Destination = Activator.CreateInstance(SingleRecordType);
Desintation = datalist[0];
response.value = Desintation;
have a look at this. it is a bit of a work around converting the list item from object to a specific type at runtime.
Thanks
Simon
**edit** missed a GetType()
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
modified 1-Nov-12 11:24am.
|
|
|
|
|
hi
thanks it seems to be working, though it is a workaround . thanks for the clue .
** yes i noticed that and i fixed it by calling the GetType()
thanks.
|
|
|
|
|
If you're getting a runtime exception, then it's probably because the object actually isn't of the right type. The exception message should tell you what it is and what it's trying to cast it to.
|
|
|
|
|
hi ,
yes , that's the case , I was searching for a way to solve this at runtime. anyway I got a clue a from Simon_Whale.
thanks.
|
|
|
|
|
Hi, I am a Qt C++ programmer and wish to build a Windows 8 flow chart style app where I can create rectangular rich text boxes, polygon shapes, and link any of these elements with lines and/or arrows etc.
The issue I'm having is not drawing these elements to the screen but rather working out the correct components to use in C#. For example, in the C++ Qt framework there is a concept of a QGraphicsView, a QGraphicsScene, and QGraphicsItems. The QGraphicsView acts somewhat like a C# viewport; however, I can't find anything equivalent to a QGraphicsScene in C#. A QGraphicsScene acts like a model and keeps track of all QGraphicItem elements drawn onto it (i.e. it is the parent to all these all child objects drawn onto it). It keeps track of things like collision detection and makes it very easy to enumerate over it's collection of items. QGraphicItems', too, can parent other QGraphicItems - making nesting of objects very easy to manage.
Is there anything like this in C# that I'm missing. For example, if I draw two Rich Text Boxes and then drag a line between them to link the boxes (with dozens of other Rich Text Boxes around them that I'm not linking to), how do I keep track of and detect which boxes the dragged line relates to, and do so efficiently?
Appreciate any guidance here. Thanks.
Lee
modified 31-Oct-12 1:39am.
|
|
|
|
|
Unfortunately, this functionality isn't built into .NET, but it is relatively straightforward to implement. If I were doing this, I would look to create a SceneManager class which was responsible for managing the child items. In other words, it would create the item and maintain them in some form of collection. For example:
public sealed class SceneManager
{
private List<SceneItem> children = new List<SceneItem>();
public T AddVisual<T>(T visual) where T : SceneItem
{
children.Add(visual);
}
} I would then wrap the RichTextBox and polygons up into somethnig that can be added to the list, and which knows how to position and draw itself. This wouuld then enable you to add a single point of entry to allow you to draw the scene. It would look something like this in the SceneManager class.
public void Draw()
{
foreach(SceneItem child in children)
{
child.Draw();
}
} Obviously this is all very simplistic, but it should serve to give you some idea of how to implement it. The point is - this class and the classes for the items you are going to draw on the screen simply contain the data that is needed to draw the items. By changing the data, you can change the underlying elements. Suppose, for instance, that you had a method called Offset that you wanted to use to move the children by a certain amount. It simply becomes a case of doing this:
public void Offset(int x, int y)
{
foreach (SceneItem child in children)
{
child.Top += x;
child.Left += y;
child.Draw();
}
}
|
|
|
|
|
Every so often I got a deserialization exception from my multi-threaded client/server app while attempting to read from NetworkStream - after digging around for sometime, with the help from Paulo (accidentally deleted prev thread, so this is fyi only), I found out that it's a sync issue.
From MSDN:[^]
Read and write operations can be performed simultaneously on an instance of the NetworkStream class without the need for synchronization. As long as there is one unique thread for the write operations and one unique thread for the read operations, there will be no cross-interference between read and write threads and no synchronization is required.
I just put a lock around NetworkStream.Read/Write and the problem goes away.
dev
|
|
|
|
|
Hooray, I can define an array of bytes and send it/them out the serial port; in proper order, proper speed, and everything. Thanks Dave and Gerry.
Anyway, I would imagine that this question has been answered several times before, but I couldn't figure out how to search for it.
I want to allow several different methods to use the same serial port; preferably by the same name.
What I'm observing is that opening a serial port in one method restricts the access (to that port) to that one method.
My previous knowledge and experience was on the order of, set up N-8-1, set up the speed, and then just stick in the bits when there's a space in the FIFO buffer.
Clearly, I have a few things to learn with C#
How do I do something like this...
SerialPort OurChosenSerialPort = new
SerialPort(
ThePortName,
OurChosenSerialPortSpeed,
Parity.None,
8,
StopBits.One
)
;
...and then let another method elsewhere use OurChosenSerialPort for sending and receiving ?
I know for a fact that I will be using that same port to receive a lot of data (a lot; barrels of the stuff) and I don't want to have to open the port each time; indeed, I don't think I can, logistically.
|
|
|
|
|
You've defined this as a method level variable. If you change it to a member variable then all the methods in your class will have access to it. Be aware, though, that you will have to manage synchronising access to the device yourself. In order to define the member variable, just use
SerialPort OurChosenSerialPort; Then, in your instantiation code, you can call
OurChosenSerialPort = new SerialPort(ThePortName, OurChosenSerialPortSpeed,
Parity.None, 0, StopBits.One);
|
|
|
|
|