日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

UNIX下用C寫MODEM傳輸程序


首先要打開串口,然后通過串口來向modem發(fā)at指令來進(jìn)行通訊,編程的時候要特別注意要用適當(dāng)?shù)姆绞酱蜷_串口,其實對TTY的操作跟一般的文件操作沒有特別的區(qū)別,區(qū)別就是在于串口通訊需要設(shè)置串口屬性.
/**************************************************************
Function : open serial comport
Param In :
pszDevName : comport device name, eg."/dev/tty1a"
uiBaud : baudrate. 50 -- 9600
bParity : parity. NOPRAITY, ODDPARITY, EVENPARITY
bByteSize : size of a byte. 5 - 8
bStopBits : stop bits. 1 - 2
bFlowControl : flow control. NOFLOW, CTSRTS, XONXOFF
uiOutQueueLen : length of output buffer queue
uiInQueueLen : length of input buffer queue
iDefTimeOut : default timeout
bOperFlag : OP_READ , OP_WRITE
Param Out : none
Return Code
>=0 : success, handle of this comport
<0 : serOpenMany
serAllocMem
serOpenInFp
serOpenOutFp
serFlowCtrlBad
serBaudBad
serByteSizeBad
serStopBitsBad
serParityBad
serSetInBuffer
serSetOutBuffer
***************************************************************/
int serOpen(char *pszDevName, uint uiBaud, uchar bParity, uchar bByteSize,
uchar bStopBits, uchar bFlowControl, uint uiOutQueueLen,
uint uiInQueueLen, int iDefTimeOut, uchar bOperFlag )
{
struct serialDef *pSer;
struct termio termioNew;
int i, fdIn, fdOut;
int serHandle;
if( iSerNum == -1 ) // initial struct pSerial
{
for( i=0; ipSerial[i] = NULL;
iSerNum = 0;
}if( iSerNum >= MAXSERIALNUM ) return (serOpenMany);i = 0;
while( iif( i >= MAXSERIALNUM ) return (serOpenMany);
pSerial[i] = (struct serialDef *)malloc(sizeof(struct serialDef));
if( pSerial[i] == NULL ) return (serAllocMem);pSer = pSerial[i];
pSer->pusInBuffer = (uchar *)malloc(uiInQueueLen);
if( pSer->pusInBuffer==NULL )
{
free(pSer);
return (serAllocMem);
}
pSer->pusOutBuffer = (uchar *)malloc(uiOutQueueLen);
if( pSer->pusOutBuffer==NULL )
{
free(pSer->pusInBuffer);
free(pSer);
return (serAllocMem);
}
pSer->uiInQueueLen = uiInQueueLen;
pSer->uiOutQueueLen = uiOutQueueLen;serHandle = i;if( bOperFlag & OP_READ )
{
if( (pSer->fpIn=fopen(pszDevName, "rb")) == NULL ) return (serOpenInFp);
fdIn = fileno(pSer->fpIn);
ioctl( fdIn, TCGETA, &termioNew );
}if( bOperFlag & OP_WRITE )
{
if( (pSer->fpOut=fopen(pszDevName, "wb")) == NULL ) return (serOpenOutFp);
fdOut = fileno(pSer->fpOut);
ioctl( fdOut, TCGETA, &termioNew );
}pSer->iDefTimeOut = iDefTimeOut;/*
termioNew.c_iflag=0;
termioNew.c_oflag=0;
termioNew.c_lflag=0;
termioNew.c_line=0;
termioNew.c_cflag = ( 0x0CBD&~CBAUD | CTSFLOW | RTSFLOW ) ;
termioNew.c_cc[VEOF]=1;
termioNew.c_cc[VEOL]=0;
*/termioNew.c_cflag = ( 0x0CBD&~CBAUD ) ;
termioNew.c_cc[VMIN] = 1; // A read operation is not satisfIEd until receive
// one character
termioNew.c_cc[VTIME] = 0; // A read operation will waitingswitch( bFlowControl )
{
case NOFLOW:
break;
case CTSRTS:
termioNew.c_cflag |= CTSFLOW | RTSFLOW;
break;
case XONXOFF:
termioNew.c_iflag |= IXON | IXOFF;
break;
default :
return (serFlowCtrlBad);
}//switch;switch( uiBaud )
{
case 50:
termioNew.c_cflag|=B50;
break;
case 75:
termioNew.c_cflag|=B75;
break;
case 110:
termioNew.c_cflag|=B110;
break;
case 134:
termioNew.c_cflag|=B134;
break;
case 150:
termioNew.c_cflag|=B150;
break;
case 200:
termioNew.c_cflag|=B200;
break;
case 300:
termioNew.c_cflag|=B300;
break;
case 600:
termioNew.c_cflag|=B600;
break;
case 1200:
termioNew.c_cflag|=B1200;
break;
case 1800:
termioNew.c_cflag|=B1800;
break;
case 2400:
termioNew.c_cflag|=B2400;
break;
case 4800:
termioNew.c_cflag|=B4800;
break;

推薦閱讀