corrected bad specified timeouts (ms versus us) M.Z.
This commit is contained in:
@ -123,10 +123,10 @@ int writeRS232(prs232 self, void *data, int dataLen)
|
||||
iRet = NETWrite(self->pSock,data,dataLen);
|
||||
if(self->debug > 0)
|
||||
{
|
||||
printf("RS232 OUT: %s",(char *)data);
|
||||
printf("RS232 OUT : %s",(char *)data);
|
||||
if(strchr((char *)data,'\n') == NULL)
|
||||
{
|
||||
puts("\n");
|
||||
puts("");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
@ -175,10 +175,10 @@ int readRS232(prs232 self, void *data, int *dataLen)
|
||||
{
|
||||
if(self->debug > 0)
|
||||
{
|
||||
printf("RS232 IN: %s",(char *)data);
|
||||
printf("RS232 IN : %s",(char *)data);
|
||||
if(strchr((char *)data,'\n') == NULL)
|
||||
{
|
||||
puts("\n");
|
||||
puts("");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
@ -211,14 +211,14 @@ int readRS232TillTerm(prs232 self, void *data, int *datalen){
|
||||
|
||||
memset(data,0,*datalen);
|
||||
replylen = *datalen;
|
||||
iRet = NETReadTillTerm(self->pSock,self->timeout,self->replyTerminator,
|
||||
iRet = NETReadTillTermNew(self->pSock,self->timeout,self->replyTerminator,
|
||||
(char *)data, replylen);
|
||||
if(self->debug > 0)
|
||||
{
|
||||
printf("RS232 IN/TERM: %s",(char *)data);
|
||||
printf("RS232 IN/TERM : %s",(char *)data);
|
||||
if(strchr((char *)data,'\n') == NULL)
|
||||
{
|
||||
puts("\n");
|
||||
puts("");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
@ -231,6 +231,10 @@ int readRS232TillTerm(prs232 self, void *data, int *datalen){
|
||||
printf("Incomplete read: %s\n", (char *)data);
|
||||
return INCOMPLETE;
|
||||
}
|
||||
else if (iRet < 0)
|
||||
{
|
||||
return iRet;
|
||||
}
|
||||
*datalen = strlen((char *)data);
|
||||
return 1;
|
||||
}
|
||||
@ -247,7 +251,7 @@ int availableRS232(prs232 self)
|
||||
return NOTCONNECTED;
|
||||
}
|
||||
|
||||
return NETAvailable(self->pSock,3);
|
||||
return NETAvailable(self->pSock,0);
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int availableNetRS232(prs232 self)
|
||||
@ -312,14 +316,14 @@ int transactRS232(prs232 self, void *send, int sendLen,
|
||||
read
|
||||
*/
|
||||
memset(reply,0,replyLen);
|
||||
iRet = NETReadTillTerm(self->pSock,self->timeout,self->replyTerminator,
|
||||
iRet = NETReadTillTermNew(self->pSock,self->timeout,self->replyTerminator,
|
||||
reply, replyLen);
|
||||
if(self->debug > 0)
|
||||
{
|
||||
printf("RS232 IN/TRANS: %s",(char *)reply);
|
||||
if(strchr((char *)reply,'\n') == NULL)
|
||||
{
|
||||
puts("\n");
|
||||
puts("");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
@ -389,6 +393,7 @@ int initRS232(prs232 self)
|
||||
NetReadRemoveUserSocket(pServ->pReader,self->pSock->sockid);
|
||||
}
|
||||
NETClosePort(self->pSock);
|
||||
free(self->pSock);
|
||||
self->pSock = NULL;
|
||||
}
|
||||
self->pSock = NETConnect(self->pHost, self->iPort);
|
||||
@ -422,6 +427,7 @@ prs232 createRS232(char *host, int iPort)
|
||||
pNew->sendTerminator = strdup("\r");
|
||||
pNew->replyTerminator = strdup("\n");
|
||||
pNew->timeout = 1000;
|
||||
pNew->debug = 0;
|
||||
pNew->pDes = CreateDescriptor("RS232 Controller");
|
||||
if(!pNew->pDes || !pNew->pHost ||
|
||||
!pNew->replyTerminator || !pNew->sendTerminator)
|
||||
@ -457,6 +463,7 @@ prs232 createRS232(char *host, int iPort)
|
||||
NetReadRemoveUserSocket(pServ->pReader,self->pSock->sockid);
|
||||
}
|
||||
NETClosePort(self->pSock);
|
||||
free(self->pSock);
|
||||
}
|
||||
if(self->pHost)
|
||||
{
|
||||
@ -761,26 +768,14 @@ int RS232Factory(SConnection *pCon, SicsInterp *pSics,
|
||||
/*
|
||||
create data structure and open port
|
||||
*/
|
||||
pNew = (prs232)malloc(sizeof(rs232));
|
||||
pNew = createRS232(argv[2], atoi(argv[3]));
|
||||
|
||||
if(!pNew)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory in RS232Factory",eError);
|
||||
return 0;
|
||||
}
|
||||
memset(pNew, 0, sizeof(rs232));
|
||||
|
||||
pNew->pHost = strdup(argv[2]);
|
||||
pNew->iPort = atoi(argv[3]);
|
||||
pNew->sendTerminator = strdup("\r");
|
||||
pNew->replyTerminator = strdup("\n");
|
||||
pNew->timeout = 1000;
|
||||
pNew->pDes = CreateDescriptor("RS232 Controller");
|
||||
if(!pNew->pDes || !pNew->pHost ||
|
||||
!pNew->replyTerminator || !pNew->sendTerminator)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory in RS232Factory",eError);
|
||||
return 0;
|
||||
}
|
||||
status = initRS232(pNew);
|
||||
if(status != 1)
|
||||
{
|
||||
|
Reference in New Issue
Block a user