|
-
Sep 2nd, 2000, 05:12 AM
#1
Thread Starter
New Member
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.
-
Sep 2nd, 2000, 08:35 AM
#2
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|