MVCOM, help!

Share your advanced PureBasic knowledge/code with the community.
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

MVCOM, help!

Post 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.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post 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
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

Tricks 'n' Tips??????
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post 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
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post 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... :(
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post 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
Marc
User
User
Posts: 28
Joined: Mon Jun 16, 2003 9:02 pm
Location: Paris - Villemer
Contact:

Post 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
Marc from PARIS - MVCOM Library
Post Reply