I have developed a GUI using VB.NET and am attempting to send a byte(4) across the RS232 line to a PIC18F8722. My function makes use of the System.IO.Ports using the
Write(buffer() as byte, integer offset, # of bytes to write)
the following code is located in my VB GUI and attempts to send the data buffer across the serial port.
Private Sub Peppers()
Dim data(4) As Byte
data(0) = 54
data(1) = 80
data(2) = 44
data(3) = 66
UserPort1.SelectedPort.Write(data, 0, 4)
End Sub
In the PIC I am using the RDA interrupt which detects data on the RS232 receive pin. My code for this is as follows:
int8 buffer[4];
int8 next_in = 0;
int8 next_out = 0;
int i=0;
#INT_RDA
void RDA_isr(void)
{
disable_interrupts(INT_RDA);
i++;
if(i=1){
buffer[0] = getc();
sendData(1,buffer[0]);
}
if(i=2){
buffer[1] = getc();
sendData(2,buffer[1]);
}
if(i=3){
buffer[2] = getc();
sendData(3,buffer[2]);
}
if(i=4){
buffer[3] = getc();
sendData(4,buffer[3]);
}
if(i>=4){
i=0;
buffer[0] =0;
buffer[1] =0;
buffer[2] =0;
buffer[3] =0;
}
enable_interrupts(INT_RDA);
}
Ideally the PIC receives the data and then calls my "sendData" function which simply sends the data back to the GUI. My problem is that I never get data for buffer[2] and buffer[3]. The first two bytes of data for buffer[0] and buffer[1] get accepted fine and display on the GUI but the last two never come across.
I think the problem lyes in the UserPort1.SelectedPort.Write(data, 0, 4) function. The syntax for the function states that the last term is the number of bytes to send. I have selected 4 but it seems that it only ever sends two bytes.
Can I not send 4 bytes of data to the RS232? or is there something noticeably wrong with my code, is there another function in VB.NET I can use to send data to the RS232?
any insight is appreciated
Write(buffer() as byte, integer offset, # of bytes to write)
the following code is located in my VB GUI and attempts to send the data buffer across the serial port.
Private Sub Peppers()
Dim data(4) As Byte
data(0) = 54
data(1) = 80
data(2) = 44
data(3) = 66
UserPort1.SelectedPort.Write(data, 0, 4)
End Sub
In the PIC I am using the RDA interrupt which detects data on the RS232 receive pin. My code for this is as follows:
int8 buffer[4];
int8 next_in = 0;
int8 next_out = 0;
int i=0;
#INT_RDA
void RDA_isr(void)
{
disable_interrupts(INT_RDA);
i++;
if(i=1){
buffer[0] = getc();
sendData(1,buffer[0]);
}
if(i=2){
buffer[1] = getc();
sendData(2,buffer[1]);
}
if(i=3){
buffer[2] = getc();
sendData(3,buffer[2]);
}
if(i=4){
buffer[3] = getc();
sendData(4,buffer[3]);
}
if(i>=4){
i=0;
buffer[0] =0;
buffer[1] =0;
buffer[2] =0;
buffer[3] =0;
}
enable_interrupts(INT_RDA);
}
Ideally the PIC receives the data and then calls my "sendData" function which simply sends the data back to the GUI. My problem is that I never get data for buffer[2] and buffer[3]. The first two bytes of data for buffer[0] and buffer[1] get accepted fine and display on the GUI but the last two never come across.
I think the problem lyes in the UserPort1.SelectedPort.Write(data, 0, 4) function. The syntax for the function states that the last term is the number of bytes to send. I have selected 4 but it seems that it only ever sends two bytes.
Can I not send 4 bytes of data to the RS232? or is there something noticeably wrong with my code, is there another function in VB.NET I can use to send data to the RS232?
any insight is appreciated