Android Question Convert java to b4a

george21

Member
Hello,

Could someone Please help me convert this java code to b4a or how could I use it with inline java.
Thank you

private void Init(int address) throws Exception
{

serialPort.setBreakOff();
Thread.sleep(300);

serialPort.setBreakOn();
Thread.sleep(200);

// Bang the bits (one byte) of our address
for (int i = 0; i < 8; i++)
{
if (((0x01 << i) & address) > 0)
{
serialPort.setBreakOff();
}
else
{
serialPort.setBreakOn();
}

Thread.sleep(200);
}

serialPort.setBreakOff();
}
 

Daestrum

Expert
Licensed User
Longtime User
I believe serialPort is actually JD2XX ( for reading/writing to UARTS )
 
Upvote 0

george21

Member
I am trying to bitbang the port at 5 Baud, this is as far as i got to try convert the java code to b4a.


Private Sub Init(ByVal address As Int)

mSerial.setBitmode(True,0x00,0x00)
Sleep(300)

' Start bit, 200ms low
mSerial.setBitmode(True,0x01,0x01)
Sleep(200)

' Bang the bits (one byte) of our address
For i As Int = 0 To 7
If ((0x01 << i) And address) > 0 Then
mSerial.setBitmode(True,0x00,0x00)
Else
mSerial.setBitmode(True,0x01,0x01)
End If

Sleep(200)
Next i

mSerial.setBitmode(True,0x00,0x00)
End Sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
B4X:
    For i = 0 To 7
        If Bit.And(Bit.ShiftLeft(1,i),address)>0 Then
            '???
        End If
    Next
 
Upvote 0
Top