Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > WINDOWS PROGRAMMING (NNTP) > Can you help me to explain a question about serial port and resolve the problem.
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 11th July 14:30
youhow
External User
 
Posts: 1
Default Can you help me to explain a question about serial port and resolve the problem.


Can you help me to explain a question about serial port and resolve the
problem. Thanks in advance.

I'm puzzled about one thing about serial port, My software communicates
with
several chip microprocessors on serial port under win2000 platform. it
works as follow:

I,Set Markparity, II,Send Number of a chip microprocessor, III,Set
Spaceparity, IV,then send command to receive data from the chip
microprocessor.

In order to make it works, I have to insert Sleep(n ms) between II and
III, or can not receive any bytes from the chip microprocessor.

the source code is about:
.....
DCB dcb;

// get current DCB settings
if (!GetCommState(hComm, &dcb))
{
return FALSE;
}

// update DCB rate, byte size, parity, and stop bits size
dcb.BaudRate = 2400;
dcb.ByteSize = 8;
dcb.Parity = MARKPARITY;
dcb.StopBits = 1;
dcb.fParity = TRUE;

// set new state
if (!SetCommState(hComm, &dcb))
{
return FALSE;
}

//send cmd to connect to a chip microprocessor
BYTE cTbNo = 0X0A;
if (!TransmitCommChar(hComm, cTbNo))
{
return FALSE;
}

//sleep 5 ms
Sleep(5);

if (!GetCommState(hComm, &dcb))
{
return FALSE;
}

// update DCB rate, byte size, parity, and stop bits size
dcb.BaudRate = 2400;
dcb.ByteSize = 8;
dcb.Parity = SPACEPARITY;
dcb.StopBits = 1;
dcb.fParity = TRUE;

// set new state
if (!SetCommState(hComm, &dcb))
{
return FALSE;
}

//send cmd
BYTE cCmd = 0XCD;
if (!TransmitCommChar(hComm, cCmd))
{
return FALSE;
}

....

Thanks in advance.

Best Regards,
  Reply With Quote


  sponsored links


2 11th July 14:30
gary g little
External User
 
Posts: 1
Default Can you help me to explain a question about serial port and resolve the problem.


What is the settling time for the chip in those registers?

--
The personal opinion of
Gary G. Little
  Reply With Quote
3 11th July 14:30
youhow
External User
 
Posts: 1
Default Can you help me to explain a question about serial port and resolve the problem.


Thanks Gary.

I'm not good at English, hope I have explained my question clearly.

In chips side, they are identified by CHIP NUMBER and MARKPARITY
command sent from computer, the designated chip returns after 10 ms
without receiving followed CMD and SPACEPARITY command from computer.

I have to insert Sleep(n ms) between II and III, or the program can not
receive any bytes from the chip microprocessor. Although I have
inserted Sleep(n) between II and III, the program occasionally fails to
communicate with chips.

I have tried to use IOCTL_SERIAL_GET_DTRRTS to capture the change of
RTS status to detect whether serial port hardware buffer was empty, but
the communication still failed without insert Sleep(n).

I want to know the reason why I should insert Sleep(n), is it correct?
and How to make the communication 100% successful.

Thanks again.
  Reply With Quote
4 11th July 14:30
maxim s shatskih
External User
 
Posts: 1
Default Can you help me to explain a question about serial port and resolve the problem.


Sleep(5) will sleep 10ms in Windows, this is the default timer resolution.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666