Receiving data from comport !!

You don't mention which version of VB you are using? The MSCOMM control was standard through VB 6.0 but if you are using VB.NET I suggest you start by reading this link. The actual code will differ between VB.NET and earlier versions of VB.

Ron
 
You will need to parse the data that is returned. I looked at the linked to .pdf yesterday. Unfortunately today at work that file is blocked by websense. Hopefully this evening I can look at it again. But if I recall what I read, you will want to parse the data. I knew I should have downloaded thet .pdf file and emailed it to myself at work. Oh well, looking at a busy day anyway.

As to VB I see it all the same. VB for DOS through the last version of VB.NET 2010.

Ron
 
Ok Ron

i am waiting you

Thank you

Hi,
I have cut down down a bigger program for this clip, it does work as the image shows.

It receives in binary format so that you can get control codes if required.

Delete & "." after the data print, that was for the test.
 

Attachments

  • 000esp05.gif
    36 KB · Views: 200
Last edited:
mmm thats didn't work

i tried many ways similar to ur code and nothings happened

But i got data in the textbox like " w~￾?￾.??.?￾?￾.ÿ?ÿ.?ÿ?.ÿ?.ÿ¸ÿ?.ÿ?.ÿ¸ÿ.?ÿ?ÿ.¸ÿ.?ÿ¸.ÿ?ÿ.￾ÿ￾ÿ.?ÿ.?ÿ?.ÿ?ÿ￾.ÿ?ÿ.?ÿ￾.ÿ?ÿ.?ÿ¸.ÿ?ÿ.￾ÿ?.ÿ￾ÿ.?ÿ?.ÿ?ÿ.¸ÿ?.ÿ?ÿ.?ÿ?.ÿ¸ÿ.?ÿ¸ÿ."

i tried many times with no luck at all

as i read in PDF file it support baud rate = 4800 and odd

i trid to changes the setting of the comport as well

 

hi,
I will change the code to suit 4800 baud and Odd parity.
Get back to you.

EDIT:
It works OK for me, I will recheck your earlier pdf.


EDIT2:
Checking that pdf shows that the data is not in ASCII format, so any characters printed will be nonsense.

Of the 5 bytes of data from the module, the individual bits of each byte have a 'meaning' assigned to them.
So you will have to capture the 5 bytes and then test each bit/s in turn and decode their meaning.

Can you do that OK.?

NOTE: Bit #7 of Byte #1 is the synchronisation bit, so you must test that bit in order to determine which byte is which.
 

Attachments

  • 000esp07.gif
    34 KB · Views: 189
Last edited:
i did that already with no luck ,,,

But as i understand from the PDF file i have to send a command to the device to get the data back ,,, may i am wrong

 
i did that already with no luck ,,,

But as i understand from the PDF file i have to send a command to the device to get the data back ,,, may i am wrong


hi,
According to the pdf, the data output is continuous,
60 packets of 5 bytes/sec
 
hi,
This program will display the output in HEX bytes with a 'comma' in between each byte. It does work.
You will then have to sample each bit as I stated earlier.

Code:
Option Explicit
Dim X

Private Sub Form_Load()


MSComm1.CommPort = "2"

MSComm1.Settings = "4800,O,8,1"

MSComm1.InputLen = 0

MSComm1.PortOpen = True

End Sub


Private Static Sub MSComm1_OnComm()
Dim Data
Dim Xchr As String
Dim strlen As Byte

   Select Case MSComm1.CommEvent
        
        Case comEvReceive
            Dim Buffer As Variant
            Buffer = MSComm1.Input
        
            Data = (StrConv(Buffer, vbUnicode))
                    strlen = Len(Data)
 
            For X = 1 To strlen
            Xchr = Mid$(Data, X, 1)
            Xchr = Hex$(Asc(Xchr))
            Xchr = Right$("00" + Xchr, 2)
            Text1.SelStart = Len(Text1.Text)
           
            Text1.SelText = Xchr & "."
              
            Next X
                    
    End Select
        
End Sub
 

Attachments

  • 000esp09.gif
    7.8 KB · Views: 189
Last edited:
Thank u Eric so much

yeah it works fine

and i got the input data

but its like = "B8.F2.B8.F2.B8.F2.B8.F2.B8.F2.B8.F2.B8.F2.B8.F2.B8.F2.B8.F2.B8.F2.B8.F2." etc

mmm is this fine according to the pdf file ?

as i imagined its not the data we should get

but we almost get the solution for this issue

many thanks

let me know if u have any idea for getting the exact data

Thanks again more than before
 

hi,
I will set up a PC to transmit that string of hex bytes you have posted and in another PC try to decode the bytes into bits.
See if we can match what the pdf says. , let you know.
 
hi,
Added a simple subroutine to convert the received binary values to a Bit pattern.
You will have to test for Bit #7 in the string to determine the sync byte.

Image shows a test string print out,, data sent from another PC via the UARTs

Code:
Option Explicit
Dim X
Dim BitStr, BitStr2 As Variant
 

Private Sub Form_Load()

MSComm1.CommPort = "2"

MSComm1.Settings = "4800,O,8,1"

MSComm1.InputLen = 0

MSComm1.PortOpen = True

End Sub

 
Private Static Sub MSComm1_OnComm()
Dim Data
Dim strchr As String
Dim strlen, valchr As Byte

   Select Case MSComm1.CommEvent
        
        Case comEvReceive
            Dim Buffer As Variant
            Buffer = MSComm1.Input
         
         Data = (StrConv(Buffer, vbUnicode))
            strlen = Len(Data)
              
            For X = 1 To strlen
            strchr = Mid$(Data, X, 2)
            valchr = Asc(strchr)
            Text1.SelText = Format(valchr, "000") & " > "
            Next X
            
 'convert from 'decimal' byte value to 8 bit pattern
            Bin2BinStr Str(valchr)
            
              Text1.SelText = BitStr & vbCrLf
    End Select
        
End Sub

Static Function Bin2BinStr(PrtVal As Integer)
'converts a 8 bit string value to 8 bits

Dim binmask, p As Integer

BitStr = String(8, "0")

 If PrtVal > 127 Then
    Mid$(BitStr, 1, 1) = "1"
    Else
    Mid$(BitStr, 1, 1) = "0"
 End If
 
    If PrtVal < 0 Then
     Mid$(BitStr, 1, 1) = "1"
    End If
 
 binmask = &H40
 
 For p = 2 To 8
    If PrtVal And binmask Then
    Mid$(BitStr, p, 1) = "1"
    End If
    
    binmask = binmask \ 2
 
 Next p
 
BitStr2 = BitStr

End Function

EDIT:
Added 2nd image showing how to get the sync byte

Edit the code to.
Code:
'convert from 'decimal' byte value to 8 bit pattern
            Bin2BinStr Str(valchr)
            
              Text1.SelText = BitStr
              
              If Left$(BitStr, 1) = "1" Then
              Text1.SelText = " sync"
              End If
              
              Text1.SelText = vbCrLf
 

Attachments

  • 000esp05.gif
    7.5 KB · Views: 183
  • 000esp06.gif
    8.1 KB · Views: 198
Last edited:
Thank you sooo much for giving me time to help

i really appreciate it

now i corrected the code and gave results like this ( see the image )

mmm i don't have a good experience with that

see what u can help me with

is this correct data we should get according to the PDF ?

Thanks again
 

Attachments

  • 000.jpg
    86.1 KB · Views: 188

hi,
Making some progress.

Exactly what is the unit that sends that data supposed to do.???
From your answer I may be able to help you.

BTW: I know its an Oximeter.! but I need to the meaning of the UART data blocks.

EDIT:
From your data image I would say you are losing some data.

I would capture from the MSCOMM input, say 15 readings into an array and then convert to bits.
 

Attachments

  • 000esp07.gif
    18.9 KB · Views: 184
Last edited:
the data i should get is reading like this ( see the pic )

this app is the one i got with the Oximeter ( its actually usb but has a virtual com port which i connect to )

its working fine with the application but with my project not yet

all i got is the only app + protocol communication in PDF

i don't know what to do
 

Attachments

  • spo2.jpg
    163.2 KB · Views: 171

hi.
Capture a few seconds of UART data from the Oximeter to a file, use an array to save the 'raw' data and post the data file.

Can you do that.?

EDIT:
Added some notes to the protocol, these values are the ones of most interest
 

Attachments

  • oxim2.gif
    38.4 KB · Views: 181
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…