Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Communiqué

Post new topic   Reply to topic
sending mixed information with mscomm1
View previous topic :: View next topic  
Author Message
ninebarmaximus
Newbie


Joined: 24 Apr 2006
Posts: 2

PostPosted: Apr 24th, 2006 01:55 PM    Post subject: sending mixed information with mscomm1 Reply with quote

I am writing a program to interact with a PIC microcontroller, and i need to send it characters and hex information

the frame i send the pic is firstly a letter, then a number, then 5 hex characters, but when im sending over mscomm1 i need to convert to a string and this is messing everything up this is the code that im using and the pic should just send the pc the same information that i send to the pic the frame i am sending is
w 5 00 C0 02 A0 08

Code:

Private Sub H_Test_Click()
Dim outstring As Variant
Dim instring As Variant
ReDim commandbyte(9)
commandbyte(3) = (Text1.Text)
commandbyte(4) = (Text5.Text)
commandbyte(5) = (Text6.Text)
commandbyte(6) = (Text7.Text)
commandbyte(7) = (Text8.Text)
Text3.Text = ""
Text4.Text = ""
Text2.Text = ""
Text11.Text = ""
If Text9.Text <> "" Then
    commandbyte(8) = Text9.Text
End If
If Text10.Text <> "" Then
    commandbyte(9) = Text10.Text
End If
If Text9.Text = "" Or Text10.Text = "" Then
    commandbyte(2) = 5
Else
    commandbyte(2) = 8
End If
For i = 3 To (2 + commandbyte(2))
    commandbyte(i) = Hex(HexByte(commandbyte(i))) //converts string to hex i.e ff->hFF,02->h2, a4->hA4
Next i
If MSComm1.PortOpen = True Then
    MSComm1.PortOpen = False
End If

MSComm1.PortOpen = True
'*****************************************************************************
commandbyte(1) = "w"
For i = 1 To (commandbyte(2) + 2)
MSComm1.Output = Str(Asc(commandbyte(i)))
Next i
'*****************************************************************************
For i = 1 To (commandbyte(2) + 2)
Text11.Text = Text11.Text + Str(Asc(commandbyte(i)))
Next i
start = Timer
Do
    DoEvents
Loop Until (Timer >= start + 0.5 Or MSComm1.InBufferCount >= commandbyte(2))

'*****************************************************************************

instring = MSComm1.Input
MSComm1.PortOpen = False
currentTime = Time
currentTime = Str(currentTime)

If instring = "" Then
    Label1.Caption = "no responce"
    Text2.Text = "no responce " + currentTime
End If

If instring <> "" Then
    Label1.Caption = "responce received"
    Text2.Text = "responce received " + currentTime
    For a = 1 To 5
        Text3.Text = Hex(Str$(Asc(Mid$(instring, a, 1))))
    Next a
End If
    Label2.Caption = "program finished"
End Sub

I get no responce at all from the pic and the reason is that the w is not being read properly
could someone please help!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Communiqué All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic