Link to home
Start Free TrialLog in
Avatar of jstephe1
jstephe1

asked on

RS-485 Serial Communications

I'm trying to communicate with a digital board via RS-485.  I can talk to it via RS-422 and RS-232, however, when I try to talk via RS-485, I can not read.  I have a thread running that monitors the port for a character received, using WaitCommEvent.  I saw a bug reported by Microsoft saying that the RTS_CONTROL_TOGGLE parameter in the DCB structure really didn't toggle and that you had to control RTS manually.  So I tried to use the EscapeCommFunction with the SETRTS parameter prior to the WriteFile and then use the CLRRTS parameter immediately after the WriteFile.  For some reason I can only write to the device and I never receive a response back.  I know the device is responding because I tapped into the wire and redirected the output.  There seems to be a timing problem with setting my computer to RTS and then clearing and reading what is coming back.  Any help would be greatly appreciated.  Code examples are definitely needed.
Avatar of Gus012498
Gus012498

How did you interface your PC to the RS-485 line? Can you recevie data if you try to loopback?

Regards,
Gus
Avatar of jstephe1

ASKER

Actually, I've somewhat figured it out.  Before I do the WriteFile, I set the RTS with the EscapeCommFunction.  After the WriteFile, I clear the RTS.  What I did is to add a Sleep(20) after the WriteFile.  It seems as if the code is just too fast and is clearing the RTS before the write is complete.  Is there a way to make sure the output buffer is empty before I clear the RTS?  I would rather not use a Sleep function.
ASKER CERTIFIED SOLUTION
Avatar of Gus012498
Gus012498

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial