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.
Re: Sending Byte to serial port
Thank you very much 2kaud! now it works correctly!
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
Re: Sending Byte to serial port
If you know the algorithm then what is the problem to code it with C++?
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.
Re: Sending Byte to serial port
Then start with learning the algorithm: Wiki
Re: Sending Byte to serial port
I'd need the algorithm of matlab FIR.
Re: Sending Byte to serial port
Re: Sending Byte to serial port
Quote:
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
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++?
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.
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
Re: Sending Byte to serial port
Quote:
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!