Sending Byte to serial port - Page 5
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 5 of 5 FirstFirst ... 2345
Results 61 to 73 of 73

Thread: Sending Byte to serial port

  1. #61
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,365

    Re: Sending Byte to serial port

    1) Why are you first opening port 1, setting various configurations then closing it and opening port 6?
    2) Why are you attempting to use overlapped I/O to just send 19 bytes? Why not just write those 19 bytes to the port directly without all the complication of overlapped I/O?

    Why not just

    Code:
    CSerialPort port2;
    
        port2.Open(6, 9600, CSerialPort::NoParity, 8, CSerialPort::OneStopBit, CSerialPort::XonXoffFlowControl);
    
    const unsigned char sBuf[] = {0x01,0x02,0x04,0x01,0x02,0x09,0x0c,0x10,0x02,0x06,0x12,0x01,0x01,0x13,0x01,0x01,0x49,0xf1,0x00};
    
         port2.Write(sBuf, sizeof(sBuf) / sizeof(unsigned char));
    
         port2.Read(pBuf, 19);
    Get this working first, then if you really need to use overlapped I/O you can start at least with something that works. When trying to do something and you're not quite sure how to do it, start with something as simple as possible, get that working and then expand in small steps to what you are trying to achieve. If you start with something small and working and change it and that change doesn't work then the problem must be only in the change so there is a much narrower area for debuging. You can also undo the changes just made and revert to what was working then try changes again.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  2. #62
    Join Date
    Feb 2013
    Posts
    34

    Re: Sending Byte to serial port

    Thank you very much 2kaud! now it works correctly!

  3. #63
    Join Date
    Feb 2013
    Posts
    34

    Re: Sending Byte to serial port

    One question please: I implemented a low-pass filter FIR of 12th order and 5Hz cut-off frequency. I'd like to implement the same filter in c++. Can you suggest something?
    Thank you

  4. #64
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,388

    Re: Sending Byte to serial port

    If you know the algorithm then what is the problem to code it with C++?
    Victor Nijegorodov

  5. #65
    Join Date
    Feb 2013
    Posts
    34

    Re: Sending Byte to serial port

    I don't know the algorithm. With Matlab I use only this command: B = fir1(N,Wn) where N is the order and the Wn the cut-off frequency.

  6. #66
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,388

    Re: Sending Byte to serial port

    Then start with learning the algorithm: Wiki
    Victor Nijegorodov

  7. #67
    Join Date
    Feb 2013
    Posts
    34

    Re: Sending Byte to serial port

    I'd need the algorithm of matlab FIR.

  8. #68
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,388

    Re: Sending Byte to serial port

    Then ask matlab!
    Victor Nijegorodov

  9. #69
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,388

    Re: Sending Byte to serial port

    Quote Originally Posted by Bfrancesco View Post
    I'd need the algorithm of matlab FIR.
    Can't you use Google?
    Just try https://www.google.com/search?source...+FIR&gs_htsa=1
    and the first link will point to fir1 - Window-based finite impulse response filter design
    Victor Nijegorodov

  10. #70
    Join Date
    Feb 2013
    Posts
    34

    Re: Sending Byte to serial port

    In that link there is the equation B(z). Is it sufficient to implement the filter FIR1(N,Wn) in c++?

  11. #71
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,388

    Re: Sending Byte to serial port

    I have know idea what filter FIR1 is.
    It is up to you to find and understand its algorithm and then try to implement it using C++ code.
    And no one will do this work for you. Where to search for I already showed you.
    If you then will have some problems with C++ - ask in this Forum.
    Victor Nijegorodov

  12. #72
    Join Date
    Apr 2013
    Posts
    1

    Re: Sending Byte to serial port

    hi,sir what is the code that send byte of binary data from matlab via serial port
    thanks in advance

  13. #73
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,388

    Re: Sending Byte to serial port

    Quote Originally Posted by anasfuad33eng View Post
    hi,sir what is the code that send byte of binary data from matlab via serial port
    thanks in advance
    1. Please define "from matlab"
    2. About how"send byte of binary data... via serial port" / please read this thread from the very begin!
    Victor Nijegorodov

Page 5 of 5 FirstFirst ... 2345

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center