Click here to Skip to main content
15,885,244 members
Home / Discussions / C#
   

C#

 
QuestionHow to bind a dataset to a WPF richtextbox? Pin
fsunole0329-Jan-14 9:44
fsunole0329-Jan-14 9:44 
AnswerRe: How to bind a dataset to a WPF richtextbox? Pin
Shameel29-Jan-14 20:46
professionalShameel29-Jan-14 20:46 
GeneralRe: How to bind a dataset to a WPF richtextbox? Pin
Rahul VB1-Feb-14 18:55
professionalRahul VB1-Feb-14 18:55 
QuestionReplicate Word 2013 Open Recent Documents Menu Pin
Running Fool29-Jan-14 5:16
Running Fool29-Jan-14 5:16 
AnswerRe: Replicate Word 2013 Open Recent Documents Menu Pin
Shameel29-Jan-14 20:48
professionalShameel29-Jan-14 20:48 
GeneralRe: Replicate Word 2013 Open Recent Documents Menu Pin
Running Fool30-Jan-14 4:19
Running Fool30-Jan-14 4:19 
AnswerRe: Replicate Word 2013 Open Recent Documents Menu Pin
Running Fool30-Jan-14 4:38
Running Fool30-Jan-14 4:38 
Questionserial port writing and reading Pin
khomeyni29-Jan-14 3:21
khomeyni29-Jan-14 3:21 
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;//TimerEventHandler tim = new TimerEventHandler(this.Link);
        public void Link(UInt32 id, UInt32 msg, ref UInt32 userCtx, UInt32 rsv1, UInt32 rsv2)
        {
            _counter++;
            if ((_counter % interval) == 0) //if ((_counter % 10) == 0)
            {
                timer_Elapsed3();
            }
            if (_counter > 1000.0*EndTime)//if (_counter>EndTime / interval)
            {
                Stop();//timekillevent must be called in Stop
            }
        }
        #endregion 
        public void StartSendingLocations()
        {
            EndIndex = setEndIndex();
            if (port==null)
            {
                port = new SerialPort(portName, rate);
                reader.port = new SerialPort("COM4", rate);//rate is 115200
                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:


C#
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:


C#
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());
    }

}



CSS
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?
AnswerRe: serial port writing and reading Pin
Richard Andrew x6429-Jan-14 6:23
professionalRichard Andrew x6429-Jan-14 6:23 
GeneralRe: serial port writing and reading Pin
khomeyni29-Jan-14 6:37
khomeyni29-Jan-14 6:37 
AnswerRe: serial port writing and reading Pin
Richard Andrew x6429-Jan-14 6:44
professionalRichard Andrew x6429-Jan-14 6:44 
AnswerRe: serial port writing and reading Pin
Richard Andrew x6429-Jan-14 7:00
professionalRichard Andrew x6429-Jan-14 7:00 
GeneralRe: serial port writing and reading Pin
khomeyni30-Jan-14 4:34
khomeyni30-Jan-14 4:34 
GeneralRe: serial port writing and reading Pin
Richard Andrew x6430-Jan-14 7:59
professionalRichard Andrew x6430-Jan-14 7:59 
GeneralRe: serial port writing and reading Pin
khomeyni30-Jan-14 8:17
khomeyni30-Jan-14 8:17 
GeneralRe: serial port writing and reading Pin
Richard Andrew x6430-Jan-14 8:23
professionalRichard Andrew x6430-Jan-14 8:23 
GeneralRe: serial port writing and reading Pin
khomeyni30-Jan-14 8:26
khomeyni30-Jan-14 8:26 
AnswerRe: serial port writing and reading Pin
Richard Andrew x6430-Jan-14 8:34
professionalRichard Andrew x6430-Jan-14 8:34 
GeneralRe: serial port writing and reading Pin
khomeyni30-Jan-14 8:50
khomeyni30-Jan-14 8:50 
AnswerRe: serial port writing and reading Pin
Richard Andrew x6430-Jan-14 8:52
professionalRichard Andrew x6430-Jan-14 8:52 
GeneralRe: serial port writing and reading Pin
khomeyni30-Jan-14 8:59
khomeyni30-Jan-14 8:59 
AnswerRe: serial port writing and reading Pin
Richard Andrew x6430-Jan-14 9:06
professionalRichard Andrew x6430-Jan-14 9:06 
GeneralRe: serial port writing and reading Pin
khomeyni30-Jan-14 9:06
khomeyni30-Jan-14 9:06 
Questiondepicting data in c# in realtime Pin
khomeyni29-Jan-14 2:38
khomeyni29-Jan-14 2:38 
AnswerRe: depicting data in c# in realtime Pin
Eddy Vluggen29-Jan-14 2:59
professionalEddy Vluggen29-Jan-14 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.