A dll is reading data from the commport. The data is sent to another process by WM_COPYDATA. The recieved data is processed in an algorithm (NMEA proc).

Sometimes I have seen the correct sentence in memory at pNMEA. After that it craches. Sometimes it craches before the whole sentence is sorted out.

I have not been able to find out why it craches. Could the reason be that a new package is arriving before the process of the previous package is finished? Here is a shorted version of my project.

DllEntry proc
invoke ReadFile,hComm,lpBuffer,lpBToRead,lpBRead,0
invoke SendMessage,hWin,WM_COPYDATA,0,lpBuffer
[color=green]; A read data package is 8 bytes long. A package takes appr
; 13 msec to read at 4800 bauds. Packages are continuously
; read for appr 1 sec. Last package could contain less than
; 8 bytes. Then there is a pause for appr 1 sec. The reading
; cycle is every 2 sec. Every package is sent as a copydata
; message to the DlgProc. The data is ascii characters.[/color]
End DllEntry

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax,hWin
mov hDlg,eax
mov eax,uMsg
.elseif eax==WM_COMMAND
.elseif eax==WM_COPYDATA
mov esi,lParam
invoke lstrlen,lParam
mov nBytes,eax
mov ecx,nBytes
mov edi,pMem
rep movsb [color=green];Sent data is copied to pMEM[/color]
[color=blue].if PauseBTN==FALSE
invoke SendMessage,hEdt1,EM_REPLACESEL,FALSE,pMem
call NMEA [color=green];Processing the data[/color]
invoke RtlZeroMemory,pMem,10
.elseif eax==WM_CLOSE
mov eax,TRUE

DlgProc endp

NMEA proc [color=blue]uses edi edx[/color]
[color=green];This algo will sort out a special sentence starting
;with "RMC" and ending with a 0Dh character.
;First thing to do is to seach for "RMC".
;"RMC" is united with each other but not
;necessarily i the same package. The flaggs
;flRMC, flRM and flR are initially false[/color]
mov edx,pMem
xor ecx,ecx
.if flRMC==TRUE
mov edi,pointer
[color=blue];dec ecx[/color]
jmp lbl_FoundRMC
.elseif flRM==TRUE
mov edi,pointer
[color=blue];dec ecx[/color]
jmp lbl_FoundRM
.elseif flR==TRUE
mov edi,pointer
[color=blue];dec ecx[/color]
jmp lbl_FoundR
mov edi,offset pNMEA
[color=green];Find R======================================[/color]
cmp byte ptr [edx+ecx],"R"
je @F
inc ecx [color=green];Next read byte[/color]
cmp ecx,nBytes
je lbl_NotFound [color=green];R not found among read bytes.[/color]
jmp @B
[color=green];R found next should be M====================[/color]
mov flR,TRUE
mov al,byte ptr [edx+ecx]
mov byte ptr [edi],al [color=green];Store R in the pNMEA[/color]
inc ecx [color=green];Next read byte[/color]
cmp ecx,nBytes
je lbl_NotFound [color=green];R was the last byte among read bytes.[/color]
[color=green];Find M======================================[/color]
cmp byte ptr [edx+ecx],"M"
jne lbl_NotFoundRM [color=green];Could not be RMC.[/color]
mov flRM,TRUE [color=green];M was found[/color]
inc edi [color=green];increase pointer in pNMEA[/color]
mov al,byte ptr [edx+ecx]
mov byte ptr [edi'#93;,al [color=green];Store M in 2nd position in the pNMEA[/color]
inc ecx [color=green];Next read byte. Should be C[/color]
cmp ecx,nBytes
je lbl_NotFound
[color=green];Find C======================================[/color]
cmp byte ptr [edx+ecx],"C"
jne lbl_NotFoundRMC [color=green];Could not be RMC. Zeroing for new seach[/color]
mov flRMC,TRUE [color=green];C was found[/color]
inc edi [color=green];increase pointer in pNMEA[/color]
mov al,byte ptr [edx+ecx]
mov byte ptr [edi],al [color=green];Store C in the pNMEA[/color]
[color=green];Following bytes is to be read
;while byte not is equal to 0Dh[/color]
inc ecx
cmp ecx,nBytes
je lbl_NotFound [color=green];Retrieve next read bytes to store in pNMEA[/color]
cmp byte ptr [edx+ecx],0Dh
je @F
inc edi [color=green];increase pointer in pNMEA[/color]
mov al,byte ptr [edx+ecx] [color=green];Store in next position in the pNMEA[/color]
mov byte ptr [edi],al [color=green];Store in next position in the pNMEA[/color]
jmp @B
[color=red]invoke SendMessage,hEdt5,WM_SETTEXT,FALSE,[/color][color=blue]addr pNMEA[/color]
[color=green];Here is the result. The RMC sentence.[/color]
mov flRM,FALSE
mov flR,FALSE
invoke RtlZeroMemory,[color=blue]addr pNMEA[/color],100
mov pointer,edi

NMEA endp

If you have the stamina to read and penetrate all this I would be grateful to suggestions why it craches and suggestions on a faster sorting out algo.

Posted on 2003-02-26 15:51:05 by minor28
I remember having programs crash when I would use the EDI register without restoring its original value before exiting the code where I was using that register. I can't remember having had similar problems with other registers.

(Maybe some internal function expect that EDI register not be tampered with.)

You may want to try saving and restoring that register and see if it helps to avoid crashes.

Posted on 2003-02-26 22:38:54 by Raymond
invoke SendMessage,hEdt1,WM_SETTEXT,FALSE, [color=blue]OFFSET pNMEA[/color]
remember this is not FASM ;)
Posted on 2003-02-26 23:25:47 by arkane
pNMEA is abit misleading, I would assume pNMEA is a pointer, yet it is not.
Posted on 2003-02-27 07:00:38 by roticv
this is the code that made me decide that pNMEA is not a pointer
mov edi,offset pNMEA
Posted on 2003-02-27 10:14:39 by arkane
I can't say that preserving edi did any improvments, possible edx did. I have edit the code above with blue text. As you can se I can write all characters in Edt1. Occasionally the RMC sentence i written in Edt5. The sentenc starts with a RMC but is not ended as it should, as if the 0Dh character not was found.

If I watch the read characters in Edt1 and the "Call NMEA" -line is commented all characters are written correctly. Uncommenting the line and several characters are missing. Occasionally "RMC" turns up.

As I am a hobby coder and have neither experience nor education in programming apart from Iczelion's excellent tutorials I would very much appreciate if you could enlighten me in denomination conventions. How should I denominate pNMEA. I know it is the address to a place were the address to the data is hold. What is the conventions in general.

Came to think of "as if the 0Dh character not was found.". I did forget to restore the flags to false. Now it works. The problem must have been exceeding the limit of pNMEA memory space.
(this is an edit of the reply)

Posted on 2003-02-27 11:43:11 by minor28