Page 1 of 1

MVCOM, help!

Posted: Fri Jun 03, 2005 11:08 am
by RichardL
Code updated For 5.20+ (same As SerialPort Libary)

I have used MVCOM very successfully on several projects, but today it appears to have stopped working. I cut my code down and still could not find the bug. I then tried one of the examples and still cannot get my remote hardware to respond. Pasting in lots of debug stuff shows that CommInput() is returning zero, even when ComInputBufferCount() shows there are 235 characters in the buffer.

Hyper terminal set up the same way makes the hardware respond OK and I get the expected response strings.

Code: Select all

port$       = "COM1:38400,n,8,1"
Handshake.l = 0
Buffer.l    = 4096
hComm.l     = ComOpen(port$,Handshake,Buffer,Buffer)
If hComm.l = 0
  MessageRequester("Decimation Utility","Cannot open serial port") :  End
EndIf

ComOutput(hComm,"H"+Chr(13))      ; Send request for HELP
Delay(1000)                       ; Wait for reply
Chaine$ = ""

n.w =  ComInputBufferCount(hComm) ; Number of chars in buffer 
While n > 0                       ; While <> 0
  Debug n                         ;
  n = ComInput(hComm,k$)          ; Receive string
  Debug n                         ; Show status
  If n                            ; If > 0
    Chaine$ = Chaine$ + k$        ; Build result
  EndIf                           
  n =  ComInputBufferCount(hComm) ; Any more characters? 
Wend

Debug "Done <"+Chaine$+">"        ; 
ComClose(hComm)                   ; Close port
Has anyone had any problems, or have I done something really stupid?
HELP... much appreciated.

Posted: Fri Jun 03, 2005 12:02 pm
by gnozal
I used MVCOM some time ago and it worked.
I used it like this :

Code: Select all

        While ComInputBufferCount(HCom) > 0
          If ComReadByte(HCom, @Buffer, 1)
            MessageRecu = 1
            If Buffer < 32
              ChaineRecue = ChaineRecue + " $" + RSet(Hex(Buffer), 2, "0") + " "
              If Buffer = 9 ; Fin communication
                Break
              EndIf
            Else
              ChaineRecue = ChaineRecue + Chr(Buffer)
            EndIf
          EndIf
        Wend

Posted: Fri Jun 03, 2005 1:54 pm
by ABBKlaus
here is what i used to get the serial port read :

Code: Select all

hCom=ComOpen("COM1:9600,N,8,1",0,1024,1024)
If hCom>0
  Debug "COM1 Opened Succesfull"
  While ComInputBufferCount(hCom)>0
    rd.b=0
    ComReadByte(hComScanner,@rd,1)
    If rd>0
      If rd=13
        Debug ("SCAN COMPLETE : "+String$)
        String$=""
      Else
        If rd>31
          String$+Chr(rd)
        EndIf
      EndIf
    EndIf
  Wend
  ComClose(hCom)
Else
  Debug "COM1 Failed to open"
EndIf

Posted: Fri Jun 03, 2005 1:56 pm
by Bonne_den_kule
Tricks 'n' Tips??????

Posted: Fri Jun 03, 2005 10:57 pm
by NoahPhense
Bonne_den_kule wrote:Tricks 'n' Tips??????
I have some good news and some bad news. The bad news is that --
that is not a trick. The good news is that I just saved a bundle on my
car insurance!!

- np

Posted: Sat Jun 04, 2005 10:01 am
by RichardL
The answer to my problem is that the string variable that receives the output from ComInput() must exist before making the call... simple!

Thanks to Marc Vitry for helping.

Also, sorry for posting in the wrong forum... :(

Posted: Sat Jun 04, 2005 12:19 pm
by NoahPhense
Sorry Richard, we were just looking for a place to type while being
intoxicated. And this thread looked like a good place to start. ;)

Glad everything is ok now.

- np

Posted: Fri Jul 15, 2005 9:01 pm
by Marc
Message to Richard L

In your code you have to initialise k$ to a space charracter before calling ComInput function (See the sample in the help file)

k$ = " "

As it's the result buffer and must be initialise

Regards