ninebarmaximus Newbie
Joined: 24 Apr 2006 Posts: 2
|
Posted: Apr 24th, 2006 01:55 PM Post subject: sending mixed information with mscomm1 |
|
|
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!! |
|