B4J Question Serial Port

mrossen

Active Member
Licensed User
Longtime User
serialport.jpg
Hi,

I am trying to get CHAT sample program to communicate with a device.

When I debug on my device end the char is not send correct.

I have now found out if I run my software made with visual studio it afterwards Work perfect.

So I think it is the setup of the port that is wrong.

I an using normal com setup "9600, 8, none, 1" in my software.

In the chat sample I have put in

B4X:
Sub btnOpen_Action
  
    sp.Open(cmbPort.Value)
    sp.SetParams(9600, 8, 0, 1)

    'AStreams.InitializePrefix(sp.GetInputStream, True, sp.GetOutputStream, "AStreams")
    AStreams.Initialize(sp.GetInputStream, sp.GetOutputStream, "AStreams")
    txtInput.Enabled = True
    btnOpen.Enabled = False
    lblStatus.Text = "Status: Open"
  
End Sub

I an not using "handshake" but I can not see a option in b4j to set this to "false"

I attached at screendump from VS


Mogens
 

positrom2

Active Member
Licensed User
Longtime User
I was wondering why in B4J I did not need to specify the baud rate. I can even run two com ports at different speeds without setting any of them and hardware HS is not enabled thereby. Nice, but strange. And when there are pauses between receiving of data (I have not checked how short they might be) then Asyncstreams without prefix works perfect, which is less effort on the other side.
See my posthttp://www.b4x.com/android/forum/threads/more-than-one-virtual-com-port-at-the-same-time.35491/
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
So, I found it out:
For testing, I had inserted in my working code the line
sp.SetParams(9600, 8, 0, 1).
Then I had a problem, transmission did not work anymore. Then I deleted that line, but the problem persisted. Then I checked on what is coming in with Hterm terminal emulator. As soon as I had set the baud rate therein to the previously used value (38400) and had closed Hterm, receiving in the B4J program revived, luckily. Maybe some freak here can explain this behaviour.
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
I found out.

Stopbit and Parity has to swap.

Must look like :

B4X:
sp.SetParams(9600, 8, 1, 0).

Not

B4X:
sp.SetParams(9600, 8, 0, 1).

Thank you for your help

Mogens
 
Upvote 0
Top