|
Very nice Sir, how to up vote?
Well not actually but virtually i can
1 more upvote
|
|
|
|
|
I want to do something like the look and feel of what you get in Word 2013 when you click File / Open and select Recent.
This seems to be a list box of user controls. You can scroll up and down like a list box. But the items are not simple strings. Each item has two lines of text each a different font and there is a pushpin control on each item. I have no idea what to search for so probably the answer is out somewhere and I have been searching for the wrong keywords.
Thanks In Advance
Chris
|
|
|
|
|
|
Yes the Owner Draw should work for the two lines of text in different fonts on each item!
What about the Push Pin for each item?
It seems the push pin would have to be a button, or some sort of control. I have not been able find a way to put a button or other control on each item of a list box?
|
|
|
|
|
I have been experimenting with making a roll your own list box.
I use one panel, with auto scroll = true, as the ‘frame panel’ of the list box. Then I add an array of smaller horizontal ‘item panels’ to the frame panel. Each item panel is almost the width of the frame panel and placed below the previous panel down off the normally viewable area of the frame panel. The frame panel then shows the vertical scroll bar and the look is a lot like a list box.
Next for each item panel I will have to add labels for the text and a button for the push pin.
Has anyone tried anything like this before?
Any reason why it wouldn’t work?
Please! Tell me now, is there a better way?
|
|
|
|
|
I've created a program to send data to a serial port(rs 232,sr 485) every 3 millisecond . and receiving data on the other port.
sending works fine but receiving is not logical,see results at the end of this post.
codes:
int _counter = 0;
public delegate void TimerEventHandler(UInt32 id, UInt32 msg, ref UInt32 userCtx, UInt32 rsv1, UInt32 rsv2);
[DllImport("winmm.dll", SetLastError = true, EntryPoint = "timeSetEvent")]
static extern UInt32 timeSetEvent(UInt32 msDelay, UInt32 msResolution, TimerEventHandler handler, ref UInt32 userCtx, UInt32 eventType);
[DllImport("winmm.dll", SetLastError = true)]
static extern void timeKillEvent(UInt32 uTimerID);
TimerEventHandler tim;
public void Link(UInt32 id, UInt32 msg, ref UInt32 userCtx, UInt32 rsv1, UInt32 rsv2)
{
_counter++;
if ((_counter % interval) == 0)
{
timer_Elapsed3();
}
if (_counter > 1000.0*EndTime)
{
Stop();
}
}
#endregion
public void StartSendingLocations()
{
EndIndex = setEndIndex();
if (port==null)
{
port = new SerialPort(portName, rate);
reader.port = new SerialPort("COM4", rate);
reader.port.Open();
writer.port = port;
if (!port.IsOpen)
{
port.Open();
}
reader.mythread.Start();
}
tim = new TimerEventHandler(this.Link);
uint rsv = 0;
timerId = timeSetEvent(1, 1, tim, ref rsv, 1);
}
and timerElapsed3:
void timer_Elapsed3()
{
Index++;
ConstructSignal();
CreateCommand();
writer.SendCommand(port, command);
if (IsChartEnabled)
{
SignalWriter_DataSent(writer.WSignal);
}
if (SentFileLogger==null)
{
return;
}
SentFileLogger.Write(true, writer.WSignal.PitchLocation, writer.WSignal.PitchAngularVelocity,
writer.WSignal.RollLocation, writer.WSignal.RollAngularVelocity,
writer.WSignal.YawLocation, writer.WSignal.YawAngularVelocity, DateTime.Now.ToString("h:m:s:fff"));
}
and when dataReceived is invoked:
public void DataReceived2(ReadSignal signal)
{
try
{
RecFileLogger.Write(true, signal.PitchLocation, signal.RollLocation, signal.YawLocation, DateTime.Now.ToString("h:m:s:fff"));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
result:
sending :
0.000 0.000 0.000 0.000 0.000 0.000 5:41:0:397
0.030 15.000 0.030 15.000 0.030 15.000 5:41:0:400
0.075 15.000 0.075 15.000 0.075 15.000 5:41:0:403
0.120 15.000 0.120 15.000 0.120 15.000 5:41:0:406
0.165 15.000 0.165 15.000 0.165 15.000 5:41:0:409
0.210 15.000 0.210 15.000 0.210 15.000 5:41:0:412
0.255 15.000 0.255 15.000 0.255 15.000 5:41:0:415
0.300 15.000 0.300 15.000 0.300 15.000 5:41:0:419
0.345 15.000 0.345 15.000 0.345 15.000 5:41:0:421
0.390 15.000 0.390 15.000 0.390 15.000 5:41:0:424
0.435 15.000 0.435 15.000 0.435 15.000 5:41:0:427
0.480 15.000 0.480 15.000 0.480 15.000 5:41:0:430
0.525 15.000 0.525 15.000 0.525 15.000 5:41:0:433
0.570 15.000 0.570 15.000 0.570 15.000 5:41:0:436
0.615 15.000 0.615 15.000 0.615 15.000 5:41:0:439
0.660 15.000 0.660 15.000 0.660 15.000 5:41:0:442
0.705 15.000 0.705 15.000 0.705 15.000 5:41:0:446
0.750 15.000 0.750 15.000 0.750 15.000 5:41:0:448
0.795 15.000 0.795 15.000 0.795 15.000 5:41:0:451
0.840 15.000 0.840 15.000 0.840 15.000 5:41:0:454
0.885 15.000 0.885 15.000 0.885 15.000 5:41:0:457
0.930 15.000 0.930 15.000 0.930 15.000 5:41:0:460
0.975 15.000 0.975 15.000 0.975 15.000 5:41:0:463
1.020 15.000 1.020 15.000 1.020 15.000 5:41:0:466
1.065 15.000 1.065 15.000 1.065 15.000 5:41:0:469
1.110 15.000 1.110 15.000 1.110 15.000 5:41:0:472
1.155 15.000 1.155 15.000 1.155 15.000 5:41:0:475
...
receiving:
0.000 0.000 0.000 5:41:0:469
0.029 0.029 0.029 5:41:0:469
0.074 0.074 0.074 5:41:0:470
0.119 0.119 0.119 5:41:0:470
0.165 0.165 0.165 5:41:0:471
0.209 0.209 0.209 5:41:0:472
0.254 0.254 0.254 5:41:0:472
0.299 0.299 0.299 5:41:0:473
0.345 0.345 0.345 5:41:0:554
0.389 0.389 0.389 5:41:0:555
0.434 0.434 0.434 5:41:0:556
0.479 0.479 0.479 5:41:0:557
0.525 0.525 0.525 5:41:0:558
0.570 0.570 0.570 5:41:0:559
0.614 0.614 0.614 5:41:0:559
0.659 0.659 0.659 5:41:0:560
0.704 0.704 0.704 5:41:0:561
0.750 0.750 0.750 5:41:0:562
0.794 0.794 0.794 5:41:0:563
0.839 0.839 0.839 5:41:0:564
0.884 0.884 0.884 5:41:0:564
0.930 0.930 0.930 5:41:0:565
0.974 0.974 0.974 5:41:0:565
1.019 1.019 1.019 5:41:0:566
1.064 1.064 1.064 5:41:0:567
1.110 1.110 1.110 5:41:0:568
1.155 1.155 1.155 5:41:0:569
1.199 1.199 1.199 5:41:0:569
...
you can see that I'm sending every 3 millisecond but receiving about 1 ms.why?
|
|
|
|
|
I assume you mean that the data received is what is sent on the other COM port.
The DataReceived function is invoked any time there is data available, not just when the data is complete.
So it is conceivable that it could be raised after each byte is received, hence the greater frequency.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
yes . the data received is what is sent on the other COM port.
Quote: The DataReceived function is invoked any time there is data available, not just when the data is complete.
So it is conceivable that it could be raised after each byte is received, hence the greater frequency.
so how can I change it to be raised every 3 millisecond? I want to create a match between sending and receiving. for example when I depict the chart of both send and receive in realtime, for comparison of data ,the data must be matched.
|
|
|
|
|
One thing you could try is to read from the port using the ReadLine function. This only returns after it reads a newline sequence.
Then, in your send function, use the WriteLine function, which will append a newline sequence to each packet.
If this does not suit your requirements, then you'll have to implement your own stream scheme to buffer the received data until it is complete, and only then process it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I just wanted to also mention, you can wrap the SerialPort class in a Stream [^]class to make it easier to read and write.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
another problem I've with this code and writing to port:
when I see the data which I'm sending in Comwizard ,sometimes I see an interrupt in the data received by comwizard. it is randomly and when I increase the frequency of sending(3 ms to 10ms ...) it appears in longer time and less than before. I checked all things but I cannot find any mistake in my code . is it possible to be relative to serial port class and functions of c#?can you suggest what is the mistake?
|
|
|
|
|
When you say you increase the frequency from 3ms to 10ms, I don't understand because that sounds like you are decreasing the frequency?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
yes . excuse me. I'm decreasing it.
and this is the code for reading bytes:
public void ThreadMain()
{
int i = 0;
while (port.IsOpen)
{
try
{
var b1 = port.ReadByte();
if (b1 == ReadSignal.STARTByte)
{
b1 = port.ReadByte();
...
if (b1 == ReadSignal.STOPByte)
{
RSignal.isValid = true;
}
}
if (RSignal.isValid)
{
RSignal.ExtractLocatoins();
if (DataReceived != null)
DataReceived.Invoke(RSignal);
}
}
catch (Exception ex)
{
}
}
}
and code for writing:
public void SendCommand(SerialPort port,byte[] command)
{
if (port != null && port.IsOpen)
{
port.Write(command, 0, command.Length);
}
else
{
MessageBox.Show("port is not open!");
}
}
|
|
|
|
|
Are you using the ReadLine and Writeline functions?
It may be that Comwizard is not waiting for the newline sequence to return the data it sees?
Even though there is an interrupt in the data, does the full data come through eventually?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
see above edited post. yes data comes eventually.
|
|
|
|
|
Check my comments in the code below:
public void ThreadMain()
{
int i = 0;
while (port.IsOpen)
{
try
{
var b1 = port.ReadByte();
if (b1 == ReadSignal.STARTByte)
{
b1 = port.ReadByte();
...
if (b1 == ReadSignal.STOPByte)
{
RSignal.isValid = true;
}
}
if (RSignal.isValid)
{
RSignal.ExtractLocatoins();
if (DataReceived != null)
DataReceived.Invoke(RSignal);
}
}
catch (Exception ex)
{
}
}
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
if the STOPByte is read there just poor out the data until new pack of correct data comes.(until STARTByte be found). also notice that I'm sending data in turn so if one pack of data is received then if no noise all data packs can be received in turn.
|
|
|
|
|
Yes you are right.
If the full data comes eventually, then maybe there is no problem at all.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
so what is the cause of the interrupt? is it relative to system(pc) or to serial port or my code? the interrupt (not sending data for some millisecond) can be seen by comwizard , also I must send data for a motor and also the motor shows such interrupt.
|
|
|
|
|
I'm sorry, I do not know.
Are you sure your send data is full every time?
I'm not there, so I can't see everything you see.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
yes. I' work around.
Richard Andrew x64,thanks for your attentions.
|
|
|
|
|
hello
I want to depict a chart dynamically and every 3 millisecond a point is send to the chart .
when I run my program about 8sec it will be executed very more than 8sec( about 3 mins or more).(i used wpftoolkit charting, dynamic data display , ... but none of them works well).
also when I want to depict 6000 point in offline mode(storing data in an array and at last depicting it on a chart) ,yet there is a such problem.
Matlab depicts these data very rapidly .
is there any way to depict these data in c#?
|
|
|
|
|
Matlab doesn't depict them in three milliseconds either. It may be quick, but it's not realtime. There's no realtime software under Windows, as Windows isn't a realtime OS. It's the OS that determines how many processortime you get.
khomeyni wrote: is there any way to depict these data in c#? Yes; and can be relatively quick too. Draw your graph once, and instead of redrawing when a new datapoint appears, scroll everything a single pixel and add the new point to the right.
Having a complete table in memory and charting the complete table every iteration will never be fast - not even if you use assembly.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I've this simple code but it takes about 20sec to be depicted!
private void button1_Click(object sender, RoutedEventArgs e)
{
ObservableCollection<ChartItem> InputItems = new ObservableCollection<ChartItem>();
for (int i = 0; i < 6000; i++)
{
InputItems.Add(new ChartItem(i, i));
}
InputLine.ItemsSource = InputItems;
}
}
public class ChartItem : INotifyPropertyChanged
{
public ChartItem(double t, double v)
{
time = t;
myVar = v;
}
private double time;
public double Time
{
get { return time; }
set
{
time = value;
OnPropertyChanged("Time");
}
}
private double myVar;
public double Value
{
get { return myVar; }
set
{
myVar = value;
OnPropertyChanged("Value");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
with using :
System.Windows.Controls.DataVisualization.Toolkit
and
System.Windows.Controls.DataVisualization.Toolkit
|
|
|
|
|
If you're "looking" for faster code - you won't find it. It's something that needs to be written.
You plot the graph yourself, and update the graph with new info instead of redrawing it completely.
Human eyes aren't realtime either; you'd need 24 frames/second to get it to look convincingly realtime. Although Windows might delay your app (one a single-core machine, a virusscanner and some automatic updates would do the trick), it should be doable to update a picture in a reasonable time.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|