Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Would like to make sense to you, so you easy find out what i make mistake i attach my C program here as well.
Really thanks for your help...............
O.......Really thanks for your help.......
I will try to do it now.......
but may i know one command line from your VB??
Text1.SelText = "K" & vbCrLf
What is this line for??
and in the PIC, i just need to write when it received "K" then sent back signal right??
your original code.
Private Sub cmdK1_Click()
If MSComm1.PortOpen = True Then
MSComm1.Output = "K"
Text1.Text = "K" & vbCrLf
End If
End Sub
hi,
Thats a procedure from your original program, the 'K', I left it in thinking that you had some use for it.???
EDIT:Code:your original code. Private Sub cmdK1_Click() If MSComm1.PortOpen = True Then MSComm1.Output = "K" Text1.Text = "K" & vbCrLf End If End Sub
I did notice in your original code that you have a Do....While... Loop, which waits for the 'OK' reply... what IF the OK never arrives.??
Place a DoEvents within any 'closed' loop so that User can escape from the program, else he has to use Ctl-Alt-Del.....
' Wait for the data to come back to the serial port.
Do
Buffer = Buffer & MSComm1.Input
[B]DoEvents[/B]
Loop Until InStr(Buffer, "OK" & vbCrLf)
' Read the "OK" response data in the serial port.
' Close the serial port.
Hi Eric,
Thanks for what you teach me. But now i face another problem. I found a file, it say that RN41 need to send somethings special command to go into the command mode before i able to send and received data.such as "$$$".
I used your program and modify a bit to let me able to sent the command the device need, but now i just able to reach the first part. After i sent "$$$" and received CMD feedback (mean into the confg time). I not able to do the other steps the device need. The device will not respone to me or sent back "!" to me. DO you know what shoud i do??
Sorry for my poor english and explaination.Really thanks for your help..........................
hi,
So you say you are now able to communicate between the PC and PIC via the RN41's..ok???
The data sheet says you must respond within a limited time period. ie 60seconds.
Tell me what commands you want to send, also post your modified VB program and I will try to add the setup codes that you tell me.
Dont fuss about your English, its just fine..
Do this RESET when you restart...look at this image
hi,
Confirmation Check.
When you send from the PC to the RN41 the string "$$$" you should get the "CMD" response [ which I understand you do]
If you get the "CMD" this means that the PC to RN41 is OK.
You then send any other COMMANDS you need to make to the RN41, after each COMMAND sent you should get the "AOK" reply. [ else "ERR" if a problem]
To EXIT COMMAND mode send "---" & vbcrlf
Remember you have only 60 seconds before the COMMAND mode times out.
EDIT:
You do understand that in order to communicate with the PIC end of the link, that the PIC program has to confirm with its own RN41 the "$$$" ,,, "CMD" commands that its own serial connection is "AOK".
If you have not programmed the PIC, I would suggest you borrow another PC/Laptop and install a VB program that can control a RN41 and then use the two PC's to practice the setup command procedure and confirm that the RN41s are working OK.
you mean that I need to sent data after "---" ??
I tot i should sent during the command mode?
SO at the end, i should go in to command mode first (sent $$$")
then out from command mode (sent "---")
After that only sent the data i want such as K ??
Erm......sorry, so at the end i should sent the command "K" during command mode or data mode?IS data mode right??
Sure, I will attach my C program here and I am using PIC16F877A.
Really thanks so much for your helping..............
//==============================================================================================
// TX and RX Function
//==============================================================================================
unsigned char a;
void init(void) // subroutine to initialize
{
SPBRG=0x0A; // set baud rate as 115200 baud
INTCON.BRGH=1;
INTCON.TXEN=1;
INTCON.CREN=1;
INTCON.SPEN=1;
TRISD = 0b00000000;
}
void display(unsigned char c) // subrountine to display the text on the screen
{
while (TXIF == 0);
TXREG = c;
}
unsigned char receive(void) // subrountine to receive text from PC
{
while (RCIF == 0);
a = RCREG;
return a;
}
//================================================================================================
// Main Function
//================================================================================================
void main(void)
{
init();
do {
a = receive();
if (a == 'K')
{
portb.f7=1;
display("X");
}
a = receive();
if(a == 'A')
{
portb.f6=1;
display("Y");
}
}while(1) ;
}