-
March 20th, 2013, 09:13 AM
#27
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)
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
|