Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

VB 6.0 Sending a String to 24C64

Status
Not open for further replies.

Suraj143

Active Member
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

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:
hi Suraj.

The
Dim Pattern_byte as Integer
gives and error at
Pattern_Byte = Text2.Text

You can check whats being sent by using another Text box in Send-Sub
 
Last edited:
Suraj143:

I presume you would not be asking this question if your program worked as you want it to. So, what result is it giving, and what do you think might be the cause of that problem?

For example, why are you defining Pattern_Byte as an integer and then expecting it to hold string data?
 
Hi thanks for both of you.

In simply this is for a LED moving sign.As previous explain
" String Length,Pattern Byte,Message Data " this is the string I'm going to send.

So when PIC recieves this string & PIC knows whats the string length & what pattern (effect) to show.
In other words PIC has now received message data & now PIC must needs to know what pattern to show these data.
Hope now you all understood about pattern byte.
 
Last edited:
if you do,

int=123
char=int

then the string char will contain "123" not the byte 123.

For your code I think you need,
Message = chr(string_Length) & chr(Pattern_Byte) & Text1.Text

However, if string_Length or Pattern_Byte are greater than 255 it will cause an error.

You may have other problems with your code due to the fact send_data can be called from two different processes one of which is a serial event. The lack of DoEvent()s should stop this being a problem but you will not receive an Ack until all the data is sent.

Mike.
 
Hi thanks for both of you.

In simply this is for a LED moving sign.As previous explain
" String Length,Pattern Byte,Message Data " this is the string I'm going to send.

So when PIC recieves this string & PIC knows whats the string length & what pattern (effect) to show.
In other words PIC has now received message data & now PIC must needs to know what pattern to show these data.
Hope now you all understood about pattern byte.

Sorry, but this does not answer the question I asked in Post#3. You just seem to be re-stating the result you would like to achieve. Perhaps I don't understand what is causing you a problem but I cannot help more if you don't answer my questions. The answer should help me to understand the problem better.
 
if you do,

int=123
char=int

then the string char will contain "123" not the byte 123.

For your code I think you need,
Message = chr(string_Length) & chr(Pattern_Byte) & Text1.Text

However, if string_Length or Pattern_Byte are greater than 255 it will cause an error.

You may have other problems with your code due to the fact send_data can be called from two different processes one of which is a serial event. The lack of DoEvent()s should stop this being a problem but you will not receive an Ack until all the data is sent.

Mike.

You have understood correctly mike.I have added your code.
Message = chr(string_Length) & chr(Pattern_Byte) & Text1.Text
You may have other problems with your code due to the fact send_data can be called from two different processes one of which is a serial event. The lack of DoEvent()s should stop this being a problem but you will not receive an Ack until all the data is sent.
What you mean by this.Can you explain a bit :)

Yup my string length will never exceed 256.
 
Last edited:
To develop/Debug Serial comm, I highely recommend you to use a serial port sniffer/monitor. I use the one of HHD Software, There's also some freebies around, google them.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top