Some device communicate with both the
nine bit protocol as well as standard "8 bit / no parity
/ 1 stop bit" communications. The best way to accomplish
this is to open the port as indicated in the
documentation for nine-bit communication and create a
function similar to the following to send the 8 bit
data.
int WCSCVxDPutPacket8Bit(int VxDPID,int Count, char *Pkt)
{
int OldLCR;
int OldLSR;
int Cnt=Count;
int Idx=0;
//Save the UART's line status register
WCSCVxDGetRegister(VxDPID,LCR,&OldLCR);
//Write new UART's line status register to enable N/8/1
WCSCVxDPutRegister(VxDPID,LCR,0x3);
//Output the data
while(Cnt-- > 0)
{
while(1)
{
WCSCVxDGetRegister(VxDPID,LSR,&OldLSR);
if (OldLSR & LSR_THRE)
{
WCSCVxDPutRegister(VxDPID,DATABUF,Pkt[Idx++]);
Cnt--;
break;
}
else
Sleep(1);
}
}
//Restore the UART's line status register
WCSCVxDPutRegister(VxDPID,LCR,OldLCR);
return(Count);
}
|