B4R Question Changing serial port 2 parameters

Gerardo Tenreiro

Active Member
Licensed User
Hello, I need to change the communication speed of serial port 2 while executing the program. There is a team that starts communication at 19200 and then changes to 115200.
De momento tengo el segundo puerto serial funcionando a una velocidad fija de 11500 con el siguiente código:

The intention is to pass a speed configuration parameter to the code
#if C
void SerialNative2(B4R::Object* unused)
{
::Serial2.begin(115200);
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#EndIf
That instead of always using 115200 to be able to make a call

RunNative("SerialNative2", 19200) or RunNative("SerialNative2", 115200) as needed, including RunNative("SerialNative2", 9600),...

This is possible?
Thank you so much
 

Gerardo Tenreiro

Active Member
Licensed User
Please use [code]code here...[/code] tags when posting code.

See the second example here: https://www.b4x.com/android/forum/threads/inline-c-c.65714/#content
Thanks Erel.
I think I understood you, but this code compiles fine and the result is wrong:




while this other code if it works correctly



The only difference in the code is:
::Serial2.begin(115200,SERIAL_8N1); --> works OK
::Serial2.begin(b4r_main::_brate2,SERIAL_8N1); --> frame error

Any ideas, does the brate variable have to be an int or another type?
thanks a lot
 
Upvote 0

candide

Active Member
Licensed User
can you check this post :

you can make a search for "Serial port 2" and you will see several threads on similar question
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
Hi, I can get serial port 2 to work correctly. I checked the posts and the code I attached works correctly, the problem I have is changing the communication speed of serial port 2 in the program loop so that each time I can have different parameters of the serial port.

If you set the serial port to 115200 with the instruction
::Serial2.begin(115200, SERIAL_8N1);
It works correctly, on the other hand, if instead of the value "115200" it passes a variable, the serial port 2 does not work correctly, review the previous post where I explain determine the problem.


Please read this carefully: https://www.b4x.com/android/forum/threads/changing-serial-port-2-parameters.148023/post-938558

Thank you so much
We are still trying to find the right key to fix the problem.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…