Results 1 to 2 of 2

Thread: MSComm.input problem again...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Malaysia
    Posts
    12

    Unhappy

    Hi there, I was always surrounded by VB receiving problem. I used MSComm to do the receiving task from the PLC. But my PLC (Programmable Logic Controller) always send the signal in binary form. Once i reveived the signal and log it in notepad (*.txt), things that i received was in weird simbol, maybe it's kind of ASCII or ANSI form, i am not sure. How to convert the binary form to readable form , for example Integer? I used this kind of method:

    Private Sub MSComm1_OnComm()
    If MSComm1.CommEvent = 2 Then
    While MSComm1.InBufferCount > 0
    Temp = MSComm1.Input
    Print #1, "ErrorCode = " & CInt(AscB(Temp))
    Print #1, "Date = " & Date
    Print #1, "Time = " & Time
    Print #1, "......................"
    Wend
    MSComm1.Output = Chr$(26)
    End If
    End Sub

    Thanks for your help!!!


    Regards, Jesse.

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    82
    First of all, if your PLC outputs binary, then set your MSComm control InputMode property to comInputModeBinary. Then declare a Binary array and assign the received serial data to that array, see below.

    --OnComm Function--
    Dim SerialInputArray() As Byte
    Dim Data as string

    Select Case comSerial.CommEvent
    Case comEvReceive
    ReDim SerialInputArray(comSerial.InBufferCount - 1)
    SerialInputArray() = comSerial.Input

    Then you can use StrConv to turn the data into more readable form.
    Data = StrConv(SerialInputArray, vbUnicode)

    Then process the data as required.

    Hope this helps

    Adrian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width