Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

khomeyni

@khomeyni
About
Posts
73
Topics
20
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • serial port writing and reading
    K khomeyni

    yes. I' work around. Richard Andrew x64,thanks for your attentions.

    C# database

  • serial port writing and reading
    K khomeyni

    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.

    C# database

  • serial port writing and reading
    K khomeyni

    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.

    C# database

  • serial port writing and reading
    K khomeyni

    see above edited post. yes data comes eventually.

    C# database

  • serial port writing and reading
    K khomeyni

    yes . excuse me. I'm decreasing it. and this is the code for reading bytes:

    public void ThreadMain()
    {
    int i = 0;
    while (port.IsOpen)//while (port != null && port.IsOpen)
    {
    try
    {
    var b1 = port.ReadByte();

                    if (b1 == ReadSignal.STARTByte)
                    {
                        //read  location 
                        b1 = port.ReadByte();
                        ...
                        if (b1 == ReadSignal.STOPByte)
                        {
    
                                RSignal.isValid = true;
                        }
    
                    }
                    if (RSignal.isValid)
                    {
                        RSignal.ExtractLocatoins();
                        if (DataReceived != null)
                            DataReceived.Invoke(RSignal);
                    }
                }
                catch (Exception ex)
                {
                    //MessageBox.Show("1:"+ex.ToString()); 
                }
            }
        }
    

    and code for writing:

    public void SendCommand(SerialPort port,byte[] command)//public void SendCommand(byte[] command)
    {

            if (port != null && port.IsOpen)
            {
               port.Write(command, 0, command.Length);
            }
            else
            {
                MessageBox.Show("port is not open!");
            }
        }
    
    C# database

  • serial port writing and reading
    K khomeyni

    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?

    C# database

  • depicting data in c# in realtime
    K khomeyni

    there is one another question: why can Matlab depict these charts so faster than c# ?

    C# csharp data-structures help question

  • depicting data in c# in realtime
    K khomeyni

    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

    C# csharp data-structures help question

  • serial port writing and reading
    K khomeyni

    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.

    C# database

  • serial port writing and reading
    K khomeyni

    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:

    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.Ro
    
    C# database

  • depicting data in c# in realtime
    K khomeyni

    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#?

    C# csharp data-structures help question

  • vs 11 wpf New Widgets Added Old Widgets Disappear
    K khomeyni

    In visual studio 2012 wpf , when I add new widget to wpf , old widgets disappear!!! for example when I add a label , then I push a button on the grid label will be removed. how I can fix it? thnx.

    Visual Studio 2015 & .NET 4.6 csharp visual-studio css wpf help

  • fast division algoirthm
    K khomeyni

    actually I don't know anymore about it's implementation , my project manager say's something to me and I must do the desired algorithm. also I don't study anything about fpga and hardware implementations. some thing that I know is that he wants to speed up his program by writing it in C , for example 6*6 inversion program which in it there is some 1/d where d is float(we can convert it to integer by multiplying it with 2^n) . he has wrote his code in labveiw and wants to convert it to C language. then it will be implemented on fpga.

    Algorithms question algorithms

  • fast division algoirthm
    K khomeyni

    thanks harold for your complete and good reply I cannot add a hardware to the FPGA (the program will be complicated) and don't have any reciprocal support. I wrote some algorithms as follows( from the pages you send to me and from others):

    void test1(){
    const long MAX_Iter=10000000;//10^7
    int *ar1=new int [MAX_Iter];/// array of integers to find the reciprocal
    double *R=new double [MAX_Iter];//array of double for saving the regular division 1/x
    double *R2=new double [MAX_Iter];//array of double for saving the algorithms division 1/x
    double *ERROR=new double [MAX_Iter];
    double max_error=pow(10,-100.0);;

    /\*
    \*  generate some number bigger than 2
    \*/
    for(int i=0;i
    
    Algorithms question algorithms

  • fast division algoirthm
    K khomeyni

    I,m writing a bit of a large programme and within it there is some divisions, the programme must be implemented on fpga and in fpga there is no division.so I must write a fast algorithm for all divisions , I don't have any access to hardware and I must implement it on software level. I have read some algorithm from here , but I don't know which one to use.

    Algorithms question algorithms

  • fast division algoirthm
    K khomeyni

    hello I want to find a fast algorithm for computing 1/d , where d is double ( albeit it can be converted to integer) what is the best algorithm for this case of many algorithms(SRT , goldschmith,newton raphson, ...)?I'm writing my program in c language. thanks in advance.

    Algorithms question algorithms

  • compression
    K khomeyni

    hello i have a file with only entry of 0..9 (numbers only) without any other thing even space , what is the most efficient algorithm to compress it? thanks in advance.

    Algorithms question algorithms

  • renaming files
    K khomeyni

    thanks a lot.

    ATL / WTL / STL c++ question

  • renaming files
    K khomeyni

    can you write the code of it here?

    ATL / WTL / STL c++ question

  • renaming files
    K khomeyni

    hello i want to see all files in directory dir that have .txt and rename them to directory dir2 with suffix .cpp how i can do this??

    ATL / WTL / STL c++ question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups