-
12. RS485 communication
12.1. Why RS485?
RS485 is a special implementation of the serial standard. It requires two lines total, with transmit and receive
sharing a wire physically. RS485 provides several benefits over standard RS232 communication in terms of
the distance data can travel without corruption, and the wide voltage range supported. Since RS485
signaling is differential (difference between the two wires is what defines the signal) it's immunity to
electromagnetic interference is relatively high (interference will affect both equally.) This makes RS485 a
good choice for many sensor or motor control applications as the distance between the sensor and the
control unit may be far and have a high amount of interference. For more information see the standard
overview linked below:
http://focus.ti.com/lit/an/slla070c/slla070c.pdf
12.2. Windows APIs Used
Support for RS485 in Windows CE is defined the Winbase.h header file, and is analog to that for RS232
serial port support. The Com port is opened like a data file and can be ‘written to’ and ‘read’ with WriteFile
and ReadFile. Com port parameters are set with a data structure labeled "DCB" also defined in Winbase.h.
For more info see the MSDN page:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/dcb_str.asp
12.3. Sample code
Please refer to RS485demo folder from sample program
12.3.1.
Opening the Com Port
Function Description:
Com port needs to be opened to grant the application access to its data stream. This is done by
creating a virtual file and defining the access permissions for that file. See line 122 of the sample
program.
Function call:
BOOL CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDispostion, DWORD
dwFlagsAndAttributes, HANDLE hTemplateFile);
Parameters(Input):
lpFileName:
LPCTSTR
:
Static
string defining the name of the file.
For the RS485 port use TEXT("COM5:")
dwDesiredAccess:
DWORD
:
Specifies the access your application
needs over the opened file. For a com port you need uninhibited read and write access defined as
"GENERIC_READ | GENERIC_WRITE"
lpSecurityAttributes: LPSECURITY_ATTRIBUTES : Ignored; set to NULL
dwCreationDispostion:
DWORD
:
How
to proceed if the file already exists.
For com port (which does already exist) use "OPEN_EXISTING"
dwFlagsAndAttributes: DWORD
: Not used, set to 0.
hTemplateFile:
HANDLE
: Not Used, Set to Null.
Return code:
Function returns a handle for the com port that will be used in all remaining functions.
Содержание MR650
Страница 1: ...MR650 Programming Manual V 1 12 1 16 2008 ...
Страница 7: ... 7 13 FUNCTION KEY SETTING ON REGISTRY 65 14 UPDATE NOTES 66 ...
Страница 16: ... it is for internal use send messages ...
Страница 33: ... Be aware to release handles when program ends ...