473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Strange Serial Port Problem

3
Hey!
I have runned into a strange problem, when trying to setup a serial port. The code I use to open the port:
Expand|Select|Wrap|Line Numbers
  1. // Opening the Port "COM1"
  2. hComm = CreateFile( "COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
  3.  
  4. // DCB Settings (Baudrate, parity, numBits, stopBit)
  5. FillMemory(&dcb, sizeof(dcb), 0);
  6. dcb.DCBlength = sizeof(dcb);
  7. BuildCommDCB("57600,n,8,1", &dcb);
  8.  
  9. // Communications time-outs
  10. timeouts.ReadIntervalTimeout = MAXDWORD; 
  11. timeouts.ReadTotalTimeoutMultiplier = 0;
  12. timeouts.ReadTotalTimeoutConstant = 0;
  13. timeouts.WriteTotalTimeoutMultiplier = 0;
  14. timeouts.WriteTotalTimeoutConstant = 0;
  15. SetCommTimeouts(hComm, &timeouts);
When I execute my program i can not read or write data to the port. Then I open the serial port with PUTTY and close PUTTY. Then I execute my prpgram again, and now I can both read and write to the port. Any one that can tell me whats going on???
Jan 31 '08 #1
5 2104
weaknessforcats
9,208 Expert Mod 8TB
Is your file handle hComm valid??

You don't check it after CreateFile.
Feb 1 '08 #2
buggex
3
yes the handle is valid.
Feb 2 '08 #3
yes the handle is valid.
Hi!buggex. When I looking your code.I only find that you just opened

your COM1 port ,set up DCB structure and Timeout . I guess that you

you need another function "readfile()" and "writefile()".Then,operate

hComm handle for read or write COM port.
Feb 3 '08 #4
buggex
3
Hi!buggex. When I looking your code.I only find that you just opened

your COM1 port ,set up DCB structure and Timeout . I guess that you

you need another function "readfile()" and "writefile()".Then,operate

hComm handle for read or write COM port.
Yes i have them to.

The write command
Expand|Select|Wrap|Line Numbers
  1. WriteFile(hComm, (LPVOID)&lpBuf, 1, &dwWritten, NULL);
The read command
Expand|Select|Wrap|Line Numbers
  1. ReadFile(hComm, lpBuf, 1, &dwRead, NULL);
Feb 4 '08 #5
Yes i have them to.

The write command
Expand|Select|Wrap|Line Numbers
  1. WriteFile(hComm, (LPVOID)&lpBuf, 1, &dwWritten, NULL);
The read command
Expand|Select|Wrap|Line Numbers
  1. ReadFile(hComm, lpBuf, 1, &dwRead, NULL);

Dear:BUGGEX

I have no ideal that your problem was already solved or not.Basically,I thought on the matter was two strange points.

First,you excused your program and it had not error?? It's just not work for I/O.

Second ,you excused your program after used PUTTY.But your program It's work??

About your first strange point,As result of your codes information are not complete enough.So I can't help you.

As for second ,I got some information from MSDN document below this URL
http://msdn2.microsoft.com/en-us/library/aa363423(VS.85).aspx

Maybe,the first paragraph is what you wanna know.
Feb 22 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
2
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. ...
6
by: Rick | last post by:
Hi, Sorry, I couldn't find a better title for this post. Anyway, I got a piece of C code which only works well if I put a fprintf in it. Here's the code : unsigned int8 Port_getPortNum( char...
3
by: collinm | last post by:
hi i send a command to a led display, the led display is suppose to return me some character i write a string on a serial port void ledDisplayExist() { char msg={'\0', '\0', '\0', '\0',...
7
by: Michael Chong | last post by:
I wrote a program that communicate with SerialComm. In every 300 milliseconds, my program continuously send & receive data via the serial port once the program starts. My program is once in a...
13
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have...
5
by: Franklin M. Gauer III | last post by:
Hi All, I've written an ASP.NET application (webservice) that does simple serial communications via the .NET 2.0 SerialComm object. The application runs fine on my development machine. The...
13
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I...
6
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.