473,326 Members | 2,111 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,326 software developers and data experts.

Serial Comm Problem

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 while, the serial port seems corrupted because when
my data is sent, it doesn't go through the serial port, so as same to
receive process. In order to fix this, I have to close the port and reopen
the port again.

Why?!! Is there any way to fix this problem or I have to check for
corruption port, then I reopen the serial port again?

Thanks!

Michael
Nov 21 '05 #1
3 1814
DO You have handshaking on>? i guess we need to know settings because if
your are doing some settings it should take care of this problem for you.

Such as your device is ready to send but your computer is not ready to
recceive you need to have RTS enabled if your device can handle it.
lots more settings what are yours
"Michael Chong" <mi*****@cyob.com.my> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
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 while, the serial port seems corrupted because
when
my data is sent, it doesn't go through the serial port, so as same to
receive process. In order to fix this, I have to close the port and reopen
the port again.

Why?!! Is there any way to fix this problem or I have to check for
corruption port, then I reopen the serial port again?

Thanks!

Michael

Nov 21 '05 #2
DO You have handshaking on>? i guess we need to know settings because if
your are doing some settings it should take care of this problem for you.

Such as your device is ready to send but your computer is not ready to
recceive you need to have RTS enabled if your device can handle it.
lots more settings what are yours
"Michael Chong" <mi*****@cyob.com.my> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
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 while, the serial port seems corrupted because
when
my data is sent, it doesn't go through the serial port, so as same to
receive process. In order to fix this, I have to close the port and reopen
the port again.

Why?!! Is there any way to fix this problem or I have to check for
corruption port, then I reopen the serial port again?

Thanks!

Michael

Nov 21 '05 #3
I am not very good in C++ problem and this is my codes below. I do not know
whether I got handshaking involve in my code. Could you guys let me know?
HANDLE OpenComm(char *lpszPort, int nBaud, char *nParity, int nData, int
nStop)
{
HANDLE hCom;
LPDCB lpDcb;

char szCom[10];
memset(szCom, 0, sizeof(szCom));
strcpy(szCom, "\\.\\COM");
strcat(szCom, lpszPort);
strcat(szCom, ":");

lpDcb = new(DCB);

//create port handle
hCom =
CreateFile(szCom,GENERIC_READ|GENERIC_WRITE,0,NULL ,OPEN_EXISTING,FILE_FLAG_O
VERLAPPED,NULL);

//failed coz invalid handle provided
if (hCom == INVALID_HANDLE_VALUE)
{
hCom = NULL;
}

//fail to get port state
if (!GetCommState(hCom,lpDcb))
{
hCom = NULL;
}

//set setting [COM1: baud=9600 parity=N data=8 stop=1]
char strTemp[50];
memset(strTemp, 0, sizeof(strTemp));
sprintf(strTemp, "baud=%d parity=%s data=%d stop=%d", nBaud, nParity,
nData, nStop);

if (!BuildCommDCB(strTemp,lpDcb))
{
hCom = NULL;
}

if (!SetCommState(hCom,lpDcb))
{
hCom = NULL;
}

// set communication timeouts
// get default values
BOOL bPort;
COMMTIMEOUTS CommTimeouts;

bPort = GetCommTimeouts(hCom, &CommTimeouts);
// set new values
CommTimeouts.ReadIntervalTimeout = 15;
CommTimeouts.ReadTotalTimeoutConstant = 250;
CommTimeouts.ReadTotalTimeoutMultiplier = 1;
CommTimeouts.WriteTotalTimeoutConstant = 250;
CommTimeouts.WriteTotalTimeoutMultiplier = 1;
bPort = SetCommTimeouts(hCom, &CommTimeouts);

return hCom;
}


"Chris Calzaretta" <cc*********@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP14.phx.gbl...
DO You have handshaking on>? i guess we need to know settings because if
your are doing some settings it should take care of this problem for you.

Such as your device is ready to send but your computer is not ready to
recceive you need to have RTS enabled if your device can handle it.
lots more settings what are yours
"Michael Chong" <mi*****@cyob.com.my> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
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 while, the serial port seems corrupted because
when
my data is sent, it doesn't go through the serial port, so as same to
receive process. In order to fix this, I have to close the port and reopen the port again.

Why?!! Is there any way to fix this problem or I have to check for
corruption port, then I reopen the serial port again?

Thanks!

Michael


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bray_stenovations | last post by:
Hello, I am experiencing some strange problems while using a usb to serial adapter vs. a real comm port. The problems started with getting a blue screen at random times. Changing usb to serial...
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...
6
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
3
by: Amjad | last post by:
Hi, I'm working on an application that sends and receives data over the serial port using the MSComm control. How do I empty the buffer of the received data and how do I set its size? Are there...
0
by: Michael Chong | last post by:
I am not very good in C++ problem and this is my codes below. I do not know whether I got handshaking involve in my code. Could you guys let me know? HANDLE OpenComm(char *lpszPort, int nBaud,...
0
by: herbert | last post by:
I have to develop a serial protocol to communicate with a device. The messages contain fields of bit groups, hex numbers, ascii, floating point numbers. in VB.NET, what is the best way 1) to...
0
by: alnsaisrinivas | last post by:
Hi I've a problem with I/O blocking on my serial port at this particular scenario... 1.I've developed a driver to communicate with some device using Serial Comm (overlapped I/O). 2.I'm able to...
0
by: joaquimfpinto | last post by:
Hi All, I've an application that write and read from different serial ports. I made a class with an object from Charon Communications. On the main form I create several instances of that...
3
by: fidamon | last post by:
hi if any body can help me with that question i will be thankfull How to open a cash drawer connected to serial comm it has no name no user manual and nothing but a serial port connection and a...
0
by: alvatar | last post by:
I am doing a project on microcontrollers and want to be able to send and receive data via RS232 serial cable. Right now, my PIC microcontroller code is able to send string data to the computer and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.