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.

vb6 serial communication

Status
Not open for further replies.
Something like,
Code:
Private Sub Slider1_Change()
    MSComm1.output = Chr(Slider1.Value)
End Sub

Mike.
 
Last edited:
sending two bytes from VB to a microcontroller

hi
i need to send two bytes(Address and the instructions) from the serial port when i click a command button in VB6 interface.how can i do that? lets say i have a text box to give the address. when i click the command button first the value in the text box should go through the serial port and after few seconds the instruction byte should be transmitted. anyone please help me
 
sending two bytes

hi!
i need to send the 2 bytes via serial port when i click cmdsend button.
this i my code under cmdsend event

MSComm1.Output = Chr$(160)
MSComm1.Output = Chr$(170)

after sending these two bytes should be stored in two variables in the microcontroller. here is my code for microcontroller

do {

if (Usart_Data_Ready())
{
k=Usart_read();
i = Usart_Read();
portd=i;
porta=k;
}
} while (1);

but this is not working properly. every time i send this the pic read them but not as intended.the variables are showing 160 and 170 changingly. its like a synchronization error. can anyone help me please
 
You are probably missing bytes when you are processing the previous pair. Try adding a sync byte at the start (or end) of your message. If you send 13, 160, 170 then your pic can wait until it receives a 13 before getting the two variables. If you still have problems then reduce your baud rate or use an interrupt driven fifo.

Mike.
 
two bytes send

hi thanx for the reply
hi!
i changed my code according to you.

MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(160)
MSComm1.Output = Chr$(170)

after sending these two bytes should be stored in two variables in the microcontroller. here is my code for microcontroller

do {

if (Usart_Data_Ready())
j=Usart_Read();
if(j=255)
{
{
k=Usart_read();
i = Usart_Read();
portd=i;
porta=k;
}}
} while (1);

but still problem arises. is there any yhin wrong with the two codes?
nothing happens when bord rate changes also
 
I'm only guessing how the library functions work but I think this should work.

Code:
char GetByte(){
    while(!Usart_Data_Ready()); 
    return(Usart_Read());
}

do {
   while (GetByte!=255);
       k=GetByte();
       i = GetByte(); 
       portd=i;
       porta=k;
       }
} while (1);

Mike.
 
reading to a long variable

unsigned long j;
j=usart_read;

this code is not taking the incoming 4 bytes from the serial port to variable j. instead it only takes the first incoming byte to the variable j. is there anyway of getting incoming 4 bytes to a long variable in microc?
please help me
 
edit ms access table from VB6 runtime?

hi
i need to edit MS access data from VB6. Lets say i have a table in access name 'table1'.and it has some data. i need to enter more data to the table from VB. there is a text box in vb to add data called name.txt.i m using ADODC can anyone please help me. if u can please send me a sample code.
 
store data in access via VB6

hi
i have a program to get a byte from a microcontroller to a VB6 interface. i need to store them in the MS access table.i linked VB and access using ADODC.through that i can read data in the table from VB. Say i have the table1 in access. i need to store the incoming byte in the "address" field of the table.please anyone help me.if you can send me a sample code
 
Updating and Adding Records in VB

Iish,

This should point you in the right direction MSDN.

Good luck!
 
serial sending more than two bytes from a VB6

hi
i need to send 5 bytes through serial port when i click the command button in VB 6 and assign those bytes to a microcontroller.
but i can send only the first two bytes when click the button. the other 3 bytes are not sending.. is there any sending buffer to increase the size? following is my code
PLS ANYONE CAN HELP ME. if my code is wrong pls send me a correct code

Private Sub cmdtx_Click()
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(123)
MSComm1.Output = Chr$(233)
MSComm1.Output = Chr$(234)
MSComm1.Output = Chr$(134)
End Sub
 
VB Comm1 Output

Iish

Does it work if you buffer the output something along the lines of:
Code:
Private Sub cmdtx_Click()
    Dim Buffer as String
    Buffer = ""
    Buffer = Buffer &  Chr$(255)
    Buffer = Buffer &   Chr$(123)
    Buffer = Buffer &   Chr$(233)
    Buffer = Buffer &   Chr$(234)
    Buffer = Buffer &   Chr$(134)
    MSComm1.Output = Buffer
End Sub

Not sure if I have the syntax correct, but I hope you get the idea!

Please also see here which talks auout input and output buffer sizes
 
Last edited:
thanx
yeah i tried that but the same problem arises. any otether method to increase the sending buffer ora sample code. please send me. argent
thanx
 
The size of the output buffer doesn't matter as it is the micro controller that is crashing. You either have to fix the micro controller code or use a (VB) timer to send 1 character every 10mS or so.

Mike.
 
thanx
this is my mivrocontrollr code

do {

if (Usart_Data_Ready()) {
one = USART_Read();
}
if (Usart_Data_Ready()) {
two = USART_Read();
}
if (Usart_Data_Ready()) {
three = USART_Read();
}
if (Usart_Data_Ready()) {
four = USART_Read();
}


}while (1);

anything wrong? im using 16f877a. how can i alter input buffer size of the micro contraller?
 
I would try slowing down the VB first.

Try adding a timer and the following code,
Code:
Dim OutString As String

Private Sub Form_Load()
    MSComm1.PortOpen = True
    Timer1.Interval = 10
    OutString = "Hello World"
End Sub

Private Sub Timer1_Timer()
    If Len(OutString) > 0 Then
        MSComm1.output = Left(OutString, 1)
        OutString = Mid(OutString, 2)
    End If
End Sub

Then to send a character add it to OutString.

Mike.
 
Actually, that receive code is completely wrong. You need to wait for a byte to be ready. Something like the code I posted on the previous page.

Mike.
Edit, you could try something like,
Code:
do {
    one=0;
    while(one!=255){			//wait for start of packet
        while(!Usart_Data_Ready());	//wait for byte to be received
        one = USART_Read(); 		//read it
    }
    while(!Usart_Data_Ready());
    one = USART_Read(); 		//should contain 123
    while(!Usart_Data_Ready());
    two = USART_Read(); 
    while(!Usart_Data_Ready());
    three = USART_Read(); 
    while(!Usart_Data_Ready());
    four = USART_Read(); 

}while (1);
 
Last edited:
receiver reads the first two byts successfully. problem is with the third byte and the know how to change the input buffer of the microcontroller?
thanx
 
Status
Not open for further replies.

Latest threads

Back
Top