thanks a lot for all
thanks very much
very goood!
Printable View
thanks a lot for all
thanks very much
very goood!
thanks a lot for all
thanks so much
verygoood
send: 1234567890ABCode:void ProcessaBuffer (unsigned char *InBuf);
.....
unsigned char *InBuf; // Buffer de Recebimento.
....
int RecebeSerial(void){
int iLenBuf, iReadReturn;
if(IsCom(iComBalanca)){
iLenBuf = DataSizeInCom (iComBalanca);
iReadReturn = ReadComn(iComBalanca, &InBuf, iLenBuf);
InBuf [iLenBuf] = '\0';
if (iReadReturn >= 0){
ProcessaBuffer (InBuf);
}
return 1;
}
return -1;
}
.....
int strrpos (unsigned char **pStrText, char pChar){ // Última ocorrência do caractere.
int iLen, iCont;
iLen = strlen (pStrText);
printCom1 ("\nSTR.: %s", pStrText);
printCom1 ("\nLEN.: %d", iLen);
if (iLen > 0){
for (iCont=iLen - 1; iCont>=0; iCont--){
if (pStrText[iCont] == pChar)
return iCont;
}
return 0; // Não houve ocorrências
}
else { return 0; } // String Nula
}
void ProcessaBuffer (unsigned char *pInBuf){
char cChar;
unsigned char *cPacote, *cPeso;
unsigned char *cStatus;
unsigned char cByte;
int iCont;
int iPosStart, iPosEnd, iPosTam;
cChar = STARTCHAR;
iPosStart = strrpos (pInBuf, cChar);
printCom1 ("STARTCHAR: %c INT: %d Posição: %d\n", cChar, cChar, iPosStart);
rECEIVED:
STR.: `1<ÿWâùHéi_
LEN.: 14STARTCHAR: INT: 2 Posição: 0
So what does ReadComm look like?
As far as I can see, the inBuf is still pointing to the wrong memory.
--
Mats
I hate to be the one to point out the obvious, but wouldn't it be a good idea to crack open a good C programming book at this point?
Somebody can show me the correct syntax ?
Sorry, but some words I dont Understand.
Without knowledge of what ReadComm actually does (or at least the correct prototype of it), we can't tell you what is the correct syntax for calling it, and I suspect that this is what all the problems stem from.
Edit: To clarify, it is not about syntax, it is about "what does it actually mean" - syntax the compiler will complain about, and as far as I understand, your code compiles and it's a question of it not doing precisely what you want that causes problems.
--
Mats
2.1.20 ReadComn
Description
This function reads ‘N’ bytes of data from the input buffer of the COM Port at one time.
For example:
"Num" is the total number of bytes in the input buffer of the COM Port.
If n < "Num", ‘N’=n. So n bytes of data are read from the input buffer of the COM Port at one time.
If n > "Num", ‘N’=Num. So "Num" bytes of data are read from the input buffer of the COM Port at one time.
Prototype
int ReadComn(int port, unsigned char *buf, int n);
Arguments
port 0-8 for COM0~COM8
buf The data buffer stores the data that is read from the input buffer of the COM Port
n The maximum number of bytes that can be read from the input buffer of the COM port (if n < "Num"). The n value must be less than or equal to the size of buf.
Return Value
Non-negative - The specified amount of data that has been read from the input buffer.
-1 (PortError) - port is not valid (0-8).
Okay. So the second argument is supposed to be an unsigned char *. However, &inBuf is not an unsigned char *, so that can't be the second argument. Presumably you just want inBuf instead (since inBuf is, indeed, a pointer to the data buffer).
And for this particular use, I'd say you are expecting too much from ReadComm - it does not allocate a buffer for you. You need to supply a buffer. As it stands, it doesn't appear that you are allocating a buffer. You can dynamically allocate with a call to malloc, or you could just declare inbuf as a array of N elements, and pass N as the argument 'n' in the ReadComm.
--
Mats