| ||||
|
Look RS232
Download Order Support Testimonials FAQ Online help Modem Programming Serial port RS232 Hardware
Interface RS232C
ProgrammingHistory RS232C Likely problems Hardware
Hardware Properties
Interfacing devicesBit Rates DTE/DCE Speeds Flow control The UART Types of UARTs Null modems Loop Back Plug Registers |
|
||||||||
The port setting is carried out with the help of the DCB (Device-Control Block) structure.By filling this structure with needed values you can change the connection parameters to those needed at the moment. To initially create the DCB structure with necessary general settings (baud rates, patity, number of bits, number of stop bits and flow control) is carried out by the BuildCommDCB function. Function syntax: BOOL BuildCommDCB (LPCTSTR lpDef, LPDCB lpDCB);
This function is very useful as it sets the parameters of DCB structure which can be transmitted to the port just like *mode* command. If you remember MS DOS, null modem cable and connection between two computers: sending a string returns the DCB structure. String example: baud=1200 parity=N data=8 stop=1 Function example: DCB dcb; ZeroMemory(&dcb,sizeof(DCB)); char buffer[100]; strcpy(buffer,"baud=1200 parity=N data=8 stop=1"); if (BuildCommDCB((char*)&buffer,&dcb)) { if (dcb.BaudRate == CBR_1200) cout << "Yes " << endl; } else cout << " error config DCB"; In case of successful termination BuildCommDCB() returns any value but zero, otherwize zero. This function replaces only explicit members with some exceptions. For 9600,n,8,1strings (not ending in x or p characters):
For 9600,n,8,1,x strings (ending in � character):
For 9600,n,8,1,x strings (ending in p character):
After creating the DCB structure we must write it into the open port, it is done with the help of GetCommState function. When the structure is written into the port it may be needed to change the port parameters. The SetCommState function may be used to evade creating the structure anew . Function syntax: BOOL GetCommState (HANDLE hFile, LPDCB lpDCB); BOOL SetCommState (HANDLE hFile, LPDCB lpDCB); Parameters specifications: HANDLE hFile, // descriptor of the communications device LPDCB lpDCB // initial address of the structure Functions example: if(GetCommState(hCom, &dcb)) { dcb.BaudRate = CBR_9600; dcb.ByteSize = 7; dcb.Parity = 2; dcb.StopBits = 0; SetCommState(hCom, &dcb); } Note The SetCommState function configures the device according to its specification in the device-control block (a DCB structure). This function initializes the hardware and managing settings parameters again but doesn't clear in and out buffers. The SetCommState function returns an error if XonChar = XoffChar in the DCB structure. When using SetCommState to configure a 8250 chip port there are the following limits of ByteSize and StopBits values:
| |||||||||
Contact us © fCoder SIA |