Error Writing Dcb
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and buildcommdcb policies of this site About Us Learn more about Stack Overflow the setcommstate example company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags setcommstate function failed Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only dcb structure takes a minute: Sign up Set DCB Fails When Attempting to Configure COM Port up vote 2 down vote favorite 2 I'm trying to write a C++ MFC application that uses the serial port (e.g. COM8). Every time I try to set the DCB it fails. If someone can point out what I'm doing wrong, I'd really appreciate it. DCB dcb
Getcommstate
= {0}; dcb.DCBlength = sizeof(DCB); port.Insert( 0, L"\\\\.\\" ); m_hComm = CreateFile( port, // Virtual COM port GENERIC_READ | GENERIC_WRITE, // Access: Read and write 0, // Share: No sharing NULL, // Security: None OPEN_EXISTING, // The COM port already exists. FILE_FLAG_OVERLAPPED, // Asynchronous I/O. NULL // No template file for COM port. ); if ( m_hComm == INVALID_HANDLE_VALUE ) { TRACE(_T("Unable to open COM port.")); ThrowException(); } if ( !::GetCommState( m_hComm, &dcb ) ) { TRACE(_T("CSerialPort : Failed to get the comm state - Error: %d"), GetLastError()); ThrowException(); } dcb.BaudRate = 38400; // Setup the baud rate. dcb.Parity = NOPARITY; // Setup the parity. dcb.ByteSize = 8; // Setup the data bits. dcb.StopBits = 1; // Setup the stop bits. if ( !::SetCommState( m_hComm, &dcb ) ) // <- Fails here. { TRACE(_T("CSerialPort : Failed to set the comm state - Error: %d"), GetLastError()); ThrowException(); } Thanks. Additional Info: The generated error code is 87: "The parameter is incorrect." Probably Microsoft's most useful error-code. j/k c++ visual-studio-2008 mfc serial-port serial-communication share|improve this question edited Feb 27 '13 at 1
SQL Server 2014 Express resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content
Setcommtimeouts
you requested has been removed. You’ll be auto redirected in 1 second. Ask a purgecomm question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: why SetCommState error 87 waitcommevent ? Smart Device Development > Visual Studio Smart Device Development - Native C++ Project Question 0 Sign in to vote Is anyone familiar with error 87 - invalid parameter from the SetCommState function ? Here's http://stackoverflow.com/questions/4188782/set-dcb-fails-when-attempting-to-configure-com-port what I have : BOOL gs2 = GetCommState(hCOM2, &dcb2); dcb2.BaudRate = 312500; dcb2.ByteSize = BIT; dcb2.Parity = PARITY; dcb2.StopBits = STOP; bStatus2 = SetCommState(hCOM2, &dcb2); DWORD dw = GetLastError(); I open the first serial port (which is a USB) & the handle is valid, GetCommState returns OK, & SetCommState returns OK. I open the second serial port hCOM2 (which is a RS232) & the handle https://social.msdn.microsoft.com/Forums/en-US/ad18e2a1-c25b-43e7-8b8d-019073db2c6f/why-setcommstate-error-87-?forum=vssmartdevicesnative is valid, GetCommState returns OK, but SetCommState returns error 87 ! I can't figure out what the problem is ! Any suggestions ? ak Tuesday, February 21, 2006 4:48 PM Reply | Quote Answers 0 Sign in to vote Hi ak It seems you might have handshaking enabled on the port and a timeout set to about 90 seconds. If timeout is set the function exits with return value 1 after the timeout period has expired, and the bytestransmitted will contain no. of bytes actually transmitted. Check if handshaking is enabled and if so make sure the device on the other end is keeping the handshaking high. otherwise disable handshaking in the DCB structure. Regards Mathew Sunday, February 26, 2006 5:49 PM Reply | Quote All replies 0 Sign in to vote I've realized that my baud rate is to high. I've switched to 115200 & now SetCommState works fine. But now I have an issue with WriteFile. The intent is to pass through data : reading it in thru one port & writing it onto another port, byte by byte : ReadFile(hCom, &cByte, 1, (LPDWORD) &iStatus, NULL); BOOL w = WriteFile(hCom2, &cByte, 1, (LPDWORD) &iStatus_write, NULL); The WriteFile function 'succeeds' (w=1),yet the number of bytes written (iStatus_write) to the port (with handle hCom2)
for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time https://www.experts-exchange.com/questions/21598746/Calling-SetCommState-on-a-DCB-results-in-Returned-1-Incorrect-function.html Job Ways to Get Help Expand Search Submit Close Search Login Join Today Products BackProducts Gigs Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange > Questions > Calling SetCommState on a http://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4751090262 DCB results in Returned (1) Incorrect function. Want to Advertise Here? Solved Calling SetCommState on a DCB results in Returned (1) Incorrect function. Posted on 2005-10-18 Visual C++.NET 1 Verified Solution 6 Comments error writing 1,708 Views Last Modified: 2010-05-18 Here is the code for SetCommState if (!SetCommState(hCom, &dcb)) { // Handle the error CloseHandle(hFile); CloseHandle(hCom); RegCloseKey(hKey); SendMessage(hDlg, LPSTATUS_END, (WPARAM)GetLastError(), (LPARAM)PRINTERR_OUT_SET); return PRINTERR_OUT_SET; } only legal values seem to have been applied to the DCB prior to this error writing dcb call, and an earlier call to GetCommState succeeds. I have hundreds of clients running fine, but one is reporting this problem on multiple pcs. GetLastError() returns Returned (1) Incorrect function. Googling this error has only turned up that it is a constant for INVALID_FUNCTION, but thats obviously worthless. Any ideas? I have additional code to post, if necessary. 0 Question by:neverrealm Facebook Twitter LinkedIn Google LVL 15 Best Solution bylakshman_ce Please check to see these.. The SetCommState function fails if the XonChar member of the DCB structure is equal to the XoffChar member. To set only a few members of the DCB structure, you should Go to Solution 6 Comments LVL 15 Overall: Level 15 Visual C++.NET 11 Message Accepted Solution by:lakshman_ce2005-10-18 Please check to see these.. The SetCommState function fails if the XonChar member of the DCB structure is equal to the XoffChar member. To set only a few members of the DCB structure, you should modify a DCB structure that has been filled in by a call to GetCommState. This ensures that the other members of the DCB structure have appropriate values. When SetCommState is used to configure the 8250, the following restrictions apply to the value
User Edition * Higher Education Technical Forum Forum Guidelines FAQ's | Best Practices | Updating your signature Do your search first | Tag your topic with keywords Contact Us Let's Get Social! | | | IB Bloggers Advanced Technical Search Focal PointFocal Point ForumsWebFOCUS/FOCUS Forum on Focal Point FOC$HOLD error FOC350 (out of space)Go New Search Notify Tools Reply Admin New PM! Personal Zone»Member DirectoryFocal Point Forums»ProfileBuddiesIgnore ListGroupsPermissionsPrivate MessagingNotificationsKarmaPreferencesFavoritesMore...DiscussionPollPrivate MessageKeyword SearchSearch current forum only Advanced SearchNew Since your Last VisitActive Topics in this CategoryAdd to My FavoritesPrinter Friendly FormatHelpManage TopicManage Content in This TopicManage MembersOnline NowControl PanelFOC$HOLD error FOC350 (out of space)Login/JoinWelcome, [Logout]RonnSilver Member posted December 17, 2007 05:01 PMI am getting the following message when creating a hold file:0 ERROR AT OR NEAR LINE 177 IN PROCEDURE OCEACCESFOCEXEC * (FOC350) ERROR WRITING OUTPUT FILE: FOC$HOLD 1 0 NUMBER OF RECORDS IN TABLE= 687347 LINES= 147744 0 I noticed that when I use a RECORDMILIT of 1000, this works fine.I run the focexec through the ff simple JCL://IBATCH1 EXEC PROC=IRUNBATT //TSCOM300.EDAPARM DD * -T //TSCOM300.EDAENV DD // DD * TRMIN=//DD:INPUT TRMOUT=//DD:OUTPUT *EDACURDIR=/U/IADMIN/IBI/SRV71/WFM/EDATEMP//TSCOM300.INPUT DD * EX OCEACCES //* //TSCOM300.OUTPUT DD SYSOUT=* // I have tried using bigger space allocation for FOCSORT, INT, and INT1 in both JCL and my PROC IRUNBATT, but it appears that it is not using those substitutions.Then I tried...DYNAM SET TEMP FOR FOC$HOLD CYLS 100,20 DSORG PS NEW REUSEDYNAM SET TEMP FOR FOCSORT SPACE CYLS 100,20 DSORG PS NEW REUSEDYNAM SET TEMP FOR HOLDMAST SPACE CYLS 100,20 DSORG PO DIR 36 NEW REUSEbut I keep getting a syntax error, even after using the exact example in the book.Please help and thanks in advance!Thanks,Ronnel CWebF