-
March 20th, 2013, 09:13 AM
#61
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 27th, 2013, 04:43 AM
#62
Re: Sending Byte to serial port
Thank you very much 2kaud! now it works correctly!
-
April 4th, 2013, 07:33 AM
#63
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
-
April 4th, 2013, 08:24 AM
#64
Re: Sending Byte to serial port
If you know the algorithm then what is the problem to code it with C++?
Victor Nijegorodov
-
April 4th, 2013, 08:31 AM
#65
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.
-
April 4th, 2013, 08:42 AM
#66
Re: Sending Byte to serial port
Then start with learning the algorithm: Wiki
Victor Nijegorodov
-
April 4th, 2013, 08:55 AM
#67
Re: Sending Byte to serial port
I'd need the algorithm of matlab FIR.
-
April 4th, 2013, 08:58 AM
#68
Re: Sending Byte to serial port
Victor Nijegorodov
-
April 4th, 2013, 09:02 AM
#69
Re: Sending Byte to serial port
Originally Posted by Bfrancesco
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
-
April 4th, 2013, 09:50 AM
#70
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++?
-
April 4th, 2013, 09:56 AM
#71
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
-
April 6th, 2013, 03:58 AM
#72
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
-
April 6th, 2013, 04:21 AM
#73
Re: Sending Byte to serial port
Originally Posted by anasfuad33eng
hi,sir what is the code that send byte of binary data from matlab via serial port
thanks in advance
- Please define "from matlab"
- About how"send byte of binary data... via serial port" / please read this thread from the very begin!
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|