Not reading in ReadFile function through COM port #2

Hello,
   I try to transfer file(in .txt format) from my test PC to my
working PC through serial port(COM port).
   One pc I open hyper terminal and set a connection in
9600(baud)-8(data bit)-none(parity)-1(stop bit)-none(flow control).In
another PC I write the code below in vc++ 6.0.
   I select Transfer->Send Text File and open a text file in my test
PC. Then I run this code in my working PC. Altough ReadFile function
doesn't get error message. dwBytesRead shows 0 during reading and text
in text file does not transfer to MyBuffer.
   My code is :

///////////////////////////////////////////////////
      DWORD m_dwError;
      HANDLE hPort = CreateFile("COM2", GENERIC_READ, 0, 0,
OPEN_EXISTING, 0, 0);
      if(hPort == INVALID_HANDLE_VALUE) {
	m_dwError = GetLastError();
	AfxMessageBox("CreateFile error occured");
      }
      DCB m_DCB;
      if(GetCommState(hPort, &m_DCB) == FALSE){
	m_dwError = GetLastError();
	AfxMessageBox("GetCommState error occured");
      }
      m_DCB.BaudRate = CBR_9600;
      m_DCB.ByteSize = 8;
      m_DCB.StopBits = ONESTOPBIT;
      m_DCB.Parity = NOPARITY;
      m_DCB.fRtsControl = RTS_CONTROL_DISABLE;
      m_DCB.fDtrControl = DTR_CONTROL_DISABLE;
      m_DCB.fOutxCtsFlow = FALSE;    
      m_DCB.fBinary = TRUE;
      m_DCB.fDsrSensitivity = FALSE;
      m_DCB.fInX = FALSE;
      m_DCB.fOutX = FALSE;
      m_DCB.fNull = FALSE;
      m_DCB.fAbortOnError = TRUE;
      m_DCB.fOutxDsrFlow = FALSE;
      m_DCB.fParity = 0;
      if(SetCommState(hPort, &m_DCB) == FALSE){	
	m_dwError = GetLastError();
	AfxMessageBox("SetCommState error occured");
      }
      COMMTIMEOUTS cto;
      cto.ReadIntervalTimeout = 5;   
      cto.ReadTotalTimeoutConstant = 300; 
      cto.ReadTotalTimeoutMultiplier = 1;
      if(SetCommTimeouts(hPort, &cto) == FALSE) {
	m_dwError = GetLastError();
	AfxMessageBox("SetCommTimeouts error occured");
      }
      
      DWORD dwBytesRead = 0;	
      char myBuffer[60];
	
      SetFilePointer(hPort, 0, NULL, FILE_BEGIN);
      for(int i =0; i < 10; i++) 
      {
	if(ReadFile(hPort, &myBuffer, 1, &dwBytesRead, 
                    NULL) == FALSE) 
	    AfxMessageBox("Error occured while reading to 
                           the serial port!!!"); 
      }
////////////////////////////////////   

how can I see the text in myBuffer? What is my error?

best regards
0
pera323 (3)
12/12/2003 2:31:37 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
418 Views

Similar Articles

[PageSpeed] 8

>-----Original Message-----
>Hello,
>   I try to transfer file(in .txt format) from my test PC 
to my
>working PC through serial port(COM port).
>   One pc I open hyper terminal and set a connection in
>9600(baud)-8(data bit)-none(parity)-1(stop bit)-none(flow 
control).In
>another PC I write the code below in vc++ 6.0.
>   I select Transfer->Send Text File and open a text file 
in my test
>PC. Then I run this code in my working PC. Altough 
ReadFile function
>doesn't get error message. dwBytesRead shows 0 during 
reading and text
>in text file does not transfer to MyBuffer.
>   My code is :
>
>///////////////////////////////////////////////////
>      DWORD m_dwError;
>      HANDLE hPort = CreateFile("COM2", GENERIC_READ, 0, 
0,
>OPEN_EXISTING, 0, 0);
>      if(hPort == INVALID_HANDLE_VALUE) {
>	m_dwError = GetLastError();
>	AfxMessageBox("CreateFile error occured");
>      }
>      DCB m_DCB;
>      if(GetCommState(hPort, &m_DCB) == FALSE){
>	m_dwError = GetLastError();
>	AfxMessageBox("GetCommState error occured");
>      }
>      m_DCB.BaudRate = CBR_9600;
>      m_DCB.ByteSize = 8;
>      m_DCB.StopBits = ONESTOPBIT;
>      m_DCB.Parity = NOPARITY;
>      m_DCB.fRtsControl = RTS_CONTROL_DISABLE;
>      m_DCB.fDtrControl = DTR_CONTROL_DISABLE;
>      m_DCB.fOutxCtsFlow = FALSE;    
>      m_DCB.fBinary = TRUE;
>      m_DCB.fDsrSensitivity = FALSE;
>      m_DCB.fInX = FALSE;
>      m_DCB.fOutX = FALSE;
>      m_DCB.fNull = FALSE;
>      m_DCB.fAbortOnError = TRUE;
>      m_DCB.fOutxDsrFlow = FALSE;
>      m_DCB.fParity = 0;
>      if(SetCommState(hPort, &m_DCB) == FALSE){	
>	m_dwError = GetLastError();
>	AfxMessageBox("SetCommState error occured");
>      }
>      COMMTIMEOUTS cto;
>      cto.ReadIntervalTimeout = 5;   
>      cto.ReadTotalTimeoutConstant = 300; 
>      cto.ReadTotalTimeoutMultiplier = 1;
>      if(SetCommTimeouts(hPort, &cto) == FALSE) {
>	m_dwError = GetLastError();
>	AfxMessageBox("SetCommTimeouts error occured");
>      }
>      
>      DWORD dwBytesRead = 0;	
>      char myBuffer[60];
>	
>      SetFilePointer(hPort, 0, NULL, FILE_BEGIN);
>      for(int i =0; i < 10; i++) 
>      {
>	if(ReadFile(hPort, &myBuffer, 1, &dwBytesRead, 
>                    NULL) == FALSE) 
>	    AfxMessageBox("Error occured while reading to 
>                           the serial port!!!"); 
>      }
>////////////////////////////////////   
>
>how can I see the text in myBuffer? What is my error?
>
>best regards
>.
>
Hi,

You cannot use the 'SetFilePointer()' function with a 
handle to a nonseeking device, such as a communications 
device. I don't know whether it's concerned of.

And More, serial-programming could be done with BLOCK or 
NONBLOCK mode. BLOCK would be easier. So it's be a good 
choice if being satisfied of you. Using CFile:Read() will 
be OK, it defaults to BLOCK.

Good luck,

Geoff

0
anonymous (74725)
12/15/2003 6:59:04 AM
Reply:

Similar Artilces:

Cannot open port 25 in Exhange 2007
I keep on getting 'stealth' when I scan port 25 from the internet. My router forwards 25 correctly to the exchange server, and no other firewall is present. The receive connector of Exchange is on port 25, and I tried different kinds of authentication but without success, port keeps invisible. I have been struggling a day with this, please help! Thanks Can you telnet to the server on port 25 from the lan? Telnet localservername 25? who is your ISP? Do you have a business account with them? Josh "Prem" <premmetje@zonnet.nl> wrote in message news:1166068608.579454...

help with datedif function please
I have names and dates in columns , every time the name changes I need the difference from that date untill to day's date. With the same name I need the difference between the dates eg: A b c 1 vit 05/12/2009 datedif untill TODAY() 2 vit 20/11/2009 datedif between A1-A2 3 vit 04/07/2009 " " A2-A3 4 vit 24/06/2009 " " A3-A4 5 vit 15/06/2009 " " A4-A5 6 tom 21/11/2009 d...

How do I make 2 pages into 1 page?
I've used WP and it had a 'make it fit' that would change fonts and bring the page down. How can I do this on Word 07 Use the Shrink One Page facility in the Print Preview Screen. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "kangaroo" <kangaroo@discussions.microsoft.com> wrote in message news:7C0C8587-DACE-4F65-AD16-1D90EB2BABE3@microsoft.com... > I've used WP and it had a 'make it fi...

Reading .wks file
Greetings...according to the Excel "help" file, as well as the file extension listing, I *should* be able to read an *.wks file, but Excel insists that it cannot. I am pretty sure the file was created in Microsoft Works. Is there a converter somewhere that I can download/install? Cheers - S2 Excel can read Works 2.0, not later. You have to save them in Works as excel files or Works 2.0 or get a commercial converter. -- Regards, Peo Sjoblom "Skip Stocks" <anonymous@discussions.microsoft.com> wrote in message news:AFC110E0-641D-4D87-9464-B930CC41CF02@microsoft....

How expensive are gdi drawing functions?
I am trying to improve the performance of a chart control.. lets say I am graphing data roughly 500 points per second and I have a 10 second window. So thats about 5000 points being represented in a control thats about 500 pixels wide. As of now, the chart tries to draw every single point. I am thinking that an algorithm that turns the 5000 points to 500 points might improve performance. lets say the chart is 100 pixels across, and the min(first window value) and max(last window value) of the xaxis is 0,100, so each pixel represents a unit. data is coming in at 10 points per unit(assu...

RMS 2.0 to POS2009 database conversion
I am trying to create a database in POS2009 from a .bck from RMS 2.0. It keeps bailing out during the create process. What am I missing? I have installed the Serv pck for POS2009. -- ce-thompson@ca.rr.com That can't be done directly. You need to follow the upgrade/migration process outlined in the Rapid Implementation Tools found on Partner Source. Robert Armstrong RMS Systems Inc. www.retail-pos.com "Curt Thompson" <cthompson@adctech.com.nospam> wrote in message news:91BDC244-B472-44B8-AE99-B43B94E29142@microsoft.com... >I am trying to create a da...

File won't open as read only
I have a file that is in use, but another person opens it and it doeasn't display the "file is in use" message. Is there a setting or fix? Hi have you shared this file? -- Regards Frank Kabel Frankfurt, Germany John wrote: > I have a file that is in use, but another person opens it > and it doeasn't display the "file is in use" message. Is > there a setting or fix? The file is on a network share. The share has all the appropriate permissions. >-----Original Message----- >Hi >have you shared this file? > >-- >Regards >Frank Ka...

Enter/Tab not functioning
We have a customer who recently upgraded to GP v 10.0. They are having random issues with the User Preferences for the Tab/Enter key. On certain instances when the User logs into GP, he is unable to use either Tab or Enter to move through fields - he has to go into User Preferences and click OK - it lasts as long as he is logged in but on the next day, he has to repeat the process. Has anyone else experienced this type of issue? He reports that it is random and has happened to several users in GP. Thank you! ...

Move system attendant mailbox <1174912412.216002.244450@y80g2000hsf.googlegroups.com>
The solution is here http://www.mcse.ms/archive/index.php/t-828566.html EggHeadCafe.com - .NET Developer Portal of Choice http://www.eggheadcafe.com ...

Read mail arn't marked as read anymore
After an SP upgrade of my Office 2000 the priviewed mail doesnt get marked as read anymore. I have tried to change the time (Tools->Options->Priview pane) from 2 -> 3 -> 4 seconds but nothing works. The only way to mark a mail as read is either to open it or right click it and chose Mark as read. Since I only use the priview pane this is very anoying for me. Is this a bug or has some setting changed with the SP? ...

How to give other users read-only access to Calendar
I want to allow the group Everyone to have read-only access to a calendar in a certain mailbox. I can do this by granting the permission 'Full mailbox access' (under 'Mailbox rights', under 'Exchange Advanced', for the particular user). However this also allows people to to do everything (ie: they become read-write users). I notice that every mailbox in the system has 'Read permissions' granted to group Everyone. This does not allow other people to open items in the mailbox, but as I understand it, permits Exchange Server and Outlook to do shared meetin...

reading confirmation
Good day, I have a problem with outlook. When they send a message to me that demands the shipment of a reading confirmation, even if I accept, the reading confirmation does not come received from the sender. Someone knows from what depends and in which way I can resolve the problem? Thanks for the eventual answers. Niki In news:eht7fo$251$1@fata.cs.interbusiness.it, Niki <nicola.pantaleo@yahoo.it> typed: > Good day, > > I have a problem with outlook. When they send a message to me that > demands the shipment of a reading confirmation, even if I accept, the > read...

PostMessage #2
I have a Dialog based application . I want to post message from this dialog to another class which is alos part of the same application. Say When I click a button,this dialog posts a message to another class. How should I achieve this? how should I know about the class recieve that particular message? Pls guide me with sample code. Regards YKUT First off, you're going to be posting to a window not a class even though it kind of looks that way since the class/object has the code that handles the message. You can do this by using the CWnd PostMessage() or SendMessage() funcitons. Yo...

Owa login problem #2
Initialy there was an error ASP 0115 Errors in IIS This what I 've done ; Click Start, point to Programs, click Windows NT 4.0 Option Pack, click Microsoft Internet Information Server, and then click Internet Service Manager. Expand Internet Information Server. Right-click the computer name, and then click Properties. In the Master Properties drop-down list box, click WWW Service, and then click Edit. Click the Home Directory tab, and then click Configuration. On the Process Options tab, click to clear the Enable Debug Exception Catching check box. Click OK to close the Application C...

Multiple IF function 03-23-10
Any assistance will be greatly appreciated. I have a worksheet that contains employee information, another worksheet that contains current team structure. I need the formula to look at the month and sine on the 'employee information' against the month and sine on the 'current team structure' and return the Product. If false, then return 'Other'. The logic is to lookup the sine on the employee information and return the applicable Product from the current team structure based their sine and month If they are not on the current team structure then refl...

"Unblock" feature should be optional when reading e-mail in CRM
When viewing e-mail messages in CRM, a line appears saying "Unblock" to allow the full message content to be read. Can this be made a configurable server or security setting? We are trying to reduce "clicks" as much as possible. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agre...

The memory could not be "read".
I'm at work yesterday afternoon responding to e-mail on my desktop, and Adobe pops up from the toolbar with a notice that there is an update available for Acrobat. I accept the download, keep plugging away at my e-mail, and install it when it's done. It runs through the install, tells me that I should restart, but I ignore it and keep working. It's near the end of the day and I'm going to be going home soon anyways. I forgot to turn it off when I left. Came in this morning, restarted it through the Start menu, and rebooted. Upon reaching the "Ctrl+Alt+Del" ...

Restricting access to Export to Excel functionality.
Hi all I am aware that the answer is likely to be 'no', but is anybody aware of a way in which I can disable the Export to Excel functionality on the various screens (accounts, contacts, etc.) - either on a user by user basis or globally. A customer of mine believes this functionality makes it too easy for a user to do a complete dump of the central CRM data to Excel. (Obviously we have given them access to the data and we want them to be able to view it, but we do not want them to easily be able to do a complete dump). Any help appreciated. Cheers Andrew Andrew Volz Senior Consu...

Port is Closed for VPN Connection
I Receveied the following message when trying to connect VPN Connection: http://img444.imageshack.us/img444/6861/hqclienterror2ge6.jpg Can any1 tell me how to open back the port or anyway to prevent this to happen again? ...

AutoFilter and Frequency Function #2
I am trying to see if I can create a frequency function that will change as I autofilter different criteria. I have a file with over 15,000 rows returning data on sales opportunities including key fields I want to filter on: organization, product line, geography and status (Won, Lost, Open). In each case I want to see the change in distribution of "days in funnel" whether I am looking at all the data or just one geography or just one product line. It appears that the Frequency function does not recognize the filtered out data and continues to return values for the entire data set....

Factory-Reconditioned Ridgid 3-1/2" Round Head Framing Nailer ZRR350RHA
Price:$159.99 Image: http://megadiscountguru.info/image.php?id=B001LTZ8W4 Best deal: http://megadiscountguru.info/index.php?id=B001LTZ8W4 This is a factory reconditioned power tool. Reconditioned generally means that the tool has been returned to the manufacturer, who brings the tool back to like new condition. Some tools may contain cosmetic blemishes. Includes 3-1/2" Round Head Framing Nailer - ZRR350RHA, Wrench, Eye Protection, Carrying Bag With Shoulder Strap, Oil ...

Unable to Read Japanese Email
I correspond with several Japanese users and can read emails from some of them without a problem, but emails from others are nothing but a series of ?????. In one case, I can read one email but not another from the same sender. Changing the Encoding doesn't help. Sending emails in Japanese to them without a problem...they can read it fine. Would appreciate any suggestions/solutions as I'm stumped. I'm using Outlook 2003 on a Windows XP Home operating system. Japanese language support is installed. ...

Valentine Gift
Valentine Gift - www.shopndiscount.com ...

how can i copy a document to a CD without making it read only?
HOW CAN I COPY A DOCUMENT TO A CD WITHOUT MAKING IN READ ONLY? You can't. It is not the file, but the media, that is read only. Even CD-RW media does not allow editing a file on the CD. Copy te file from CD to HD, mak edits and if a CD-RW you should be able to burn the edited file back to the CD. hth "DON" wrote: > HOW CAN I COPY A DOCUMENT TO A CD WITHOUT MAKING IN READ ONLY? ...

Price List #2
I created a profile for an Inventory person, when she goes into price list and clicks on 'currency id' it says she does not have enough priviliges. Does she have access to the 'Currencies' window? "rcr" wrote: > I created a profile for an Inventory person, when she goes into price list > and clicks on 'currency id' it says she does not have enough priviliges. > > ...