I need to send a string to 24C64 from my pc.I wrote a VB program.It sends 32 bytes at once for block write in 24C64.
I have two text boxes & one command button.
*One to enter the message
*Other is to enter the pattern
When I click the command button it must send in this order.
Packet = String Length,Pattern Byte,Message Data
I also use acknowledge from PIC side before sending the balance message.PIC must acknowledge after receiving every 32 bytes to get balance data.
Is my code ok? I use VB 6.0
I have two text boxes & one command button.
*One to enter the message
*Other is to enter the pattern
When I click the command button it must send in this order.
Packet = String Length,Pattern Byte,Message Data
I also use acknowledge from PIC side before sending the balance message.PIC must acknowledge after receiving every 32 bytes to get balance data.
Is my code ok? I use VB 6.0
Code:
Dim string_Length As Integer
Dim pointer As Integer
Dim Pattern_Byte As Integer
Dim Ack_Byte As Integer
Dim Message As String
Private Sub Command1_Click()
pointer = 0
string_Length = Len(Text1.Text) + 2
Pattern_Byte = Text2.Text
Message = string_Length & Pattern_Byte & Text1.Text
Call Send_Data
End Sub
Private Sub Send_Data()
If string_Length > 32 Then
MSComm1.Output = Mid(Message, pointer + 1, 32)
pointer = pointer + 32
string_Length = string_Length - 32
Else
If string_Length <= 32 Then
MSComm1.Output = Message
string_Length = 0
End If
End If
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvRecieve Then
Ack_Byte = MSComm1.Input
End If
If Ack_Byte = "A" Then
If string_Length > 0 Then
Call Send_Data
End If
End If
End Sub
Private Sub Form_Load()
With MSComm1
.CommPort = 1
.PortOpen = True
.Settings = "9600,n,8,1"
End With
End Sub
Last edited: