Serial Communication - ReadFile returns WriteFile buffer

Started by georgek01, June 10, 2009, 11:51:45 AM

Previous topic - Next topic

georgek01

Hello!

I've successfully developed an application that sends text messages via my GSM phone connected to my computer (USB).

What I'm unable to do though is read responses from the modem. After I issue a WriteFile, I wait two seconds then issue a ReadFile. All I get back is the WriteFile buffer contents. How do I read the response from the port directly after a WriteFile?

I'm communicating with the modem synchronously.
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)


Farabi

I had a CDMA Haier c 6000 can I use that library too?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"


georgek01

My question was less around sending and receiving text messages and more around using ReadFile after a WriteFile.

Lets take SMS & GSM out of the question....  :P

I'm using WriteFile to send an AT command. After that I want to read the response from the modem e.g. ERROR, OK etc.

When I issue the ReadFile after a WriteFile I get the contents of the WriteFile buffer back, even if I delay the read for a few seconds.

How do I read the port after a write without reading in the write buffer?
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

dedndave

ReadFile should work
show us a small snippet of code

georgek01

I start by setting the SIM PIN. Once the PIN command is sent i want to pick up on the response from the modem i.e. ERROR or OK.


szConfig1 db 'at+cpin=%s',13,10,0
szConfig2 db 'at+cmgf=1',13,10,0
szSend1 db 'at+cmgs="%s"',13,10,0
szSend2 db '%s',26,0

; get the SIM PIN from the text box
invoke GetDlgItemText,hDlg,1008,addr buffer1,sizeof buffer1
invoke wsprintf,addr buffer2,addr szConfig1, addr buffer1

; write the pin to the file handle
invoke WriteFile,hConn,addr buffer2,sizeof buffer2,addr bytes,NULL

; write was successful if not 0
.if eax == 0
   invoke ErrMsg,hDlg,16,0,addr szAppName
   xor eax,eax
   ret
.endif

; at this point I send a ReadFile to pick up the ERROR or OK response from the modem, but
; the read just returns the contents of the buffer from the write operation

invoke RtlZeroMemory,addr buffer3,sizeof buffer3

; get response from the modem
invoke ReadFile,hConn,addr buffer3,sizeof buffer3,addr dwBytes,NULL
   .if eax != 0
      .if dwBytes != 0

         ; [** problem **] buffer3 contains the data from the previous write operation
         invoke MessageBox,hDlg,addr buffer3,addr buffer3,0

      .else
         invoke ErrMsg,hDlg,27,0,addr szAppName
         invoke LocalFree,hMem
         ret
      .endif
  .else
      invoke ErrMsg,hDlg,37,0,addr szAppName
      invoke LocalFree,hMem
      ret
.endif

What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

dedndave

maybe it has to do with how the port is configured
http://msdn.microsoft.com/en-us/library/aa450602.aspx

i don't mess with my own phone, but i have had to play with some of this in the past for a contract
i was using 16-bit code, though - all this i/o stuff was easier under win98 - lol