Android Question Please Help A newbie :)

Danbicky

Member
Licensed User
Longtime User
Hi Guys,

I am new to this forum, hello to all you super guru's. I have had B4A for quite some time but have struggled getting in to it. I am more of a hardware person, but do have experience with C.

My requirement is as follows:

I have 5 seekbars, I want to use each seek bar to control a channel of my garden lighting system. The goal is to have a mood type settings within the android app. So once the seekbar values have been set through the user interface, the seekbar values 1 - 5 can be stored against a specific mood number.

UPD protocol will be used to send the data to my hardware control unit. This part is all working and not a problem.

A typical UDP command would be : Garden-Node;setpwm;4;1023; 4 represents the chan and 1023 the value.

Tinkering with B4A, I can send simple UDP commands. The tricky bit is forming the string of data to send.
I have created a subroutine, and I am sure you can help me with this, It throws a moan

Sub Update_Seekbar(vChan As Int, vValue As Int)
Dim Packet As UDPPacket
Dim Dest As String
Dim data() As Byte
data = "All;setpwm;",vChan,";",vValue,";".GetBytes("UTF8")
' data = "All;allon;".GetBytes("UTF8")
Dest = "255.255.255.255"
Packet.Initialize(data, Dest, 12345)
UDPSocket1.Send(Packet)

End Sub

Any Advice and help will be so much appreciated. I will grasp it, possibly will take a little time.
Thanks in advance.

Dans
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
This is not a valid string..
B4X:
data = "All;setpwm;",vChan,";",vValue,";".GetBytes("UTF8")

Try this instead...
B4X:
data = "All;setpwm;" & vChan & ";" & vValue & ";".GetBytes("UTF8")
I'm presuming that you require the semicolon as a separator?
 
Upvote 0

Danbicky

Member
Licensed User
Longtime User
Hi Random, Awesome, been quite some time programming in basic, yes the semi is a separator that get's parsed by main routine in my controller.

Do you have any ideas how to save 5 seekbar values under lets say 5 mood options. The idea is that when a selected mood button/drop down or something is selected the state of the seekbars under this idx is restored. and the same option apply's that if they are changed they can be stored against a mood number.

I hope someone can help with this part. Big thanks mate. Much appreciated.

Dans
 
Upvote 0

Danbicky

Member
Licensed User
Longtime User
Hi RandomCoder.

Nope that did not work, is the problem I am trying to convert and int to a string, for example in C this is taken care of or I can convert a string to int using toInt()
B4A still throws an error with :
data = "All;setpwm;" & vChan & ";" & vValue & ";".GetBytes("UTF8")

Thanks Dans
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
data = "All;setpwm;" & vChan & ";" & vValue & ";".GetBytes("UTF8")
remove the .GetBytes("UTF8")

later, when you want to use data you use it like this
B4X:
data.GetBytes("UTF8")
 
Upvote 0

Danbicky

Member
Licensed User
Longtime User
remove the .GetBytes("UTF8")

later, when you want to use data you use it like this
B4X:
data.GetBytes("UTF8")

Don,

Even when I remove the .Getbytes("UTF8") on the end, on compile it still throws an error

Error description: Cannot cast type: {Type=String,Rank=0} to: {Type=Byte,Rank=1}
Occurred on line: 16
data = "All;setpwm;" & vChan & ";" & vValue & ";"
Word: ;

Is this because data is declared as a byte? I am using version 2.70 of the IDE not sure if this is a problem with earlier version?
Thanks Dan
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is this because data is declared as a byte?
Oh, i did not read carefully.
Yes. You are defining a string but want to add this to a byte array...

Try it this way
B4X:
    Dim dummy As String = "All;setpwm;"&vChan&";"&vValue&";"
    Dim data() As Byte = dummy.GetBytes("UTF8")
 
Upvote 0

Danbicky

Member
Licensed User
Longtime User
Don,

You are a hero, it likes this :)

Brilliant massive thankies. Any idea on the seekbar stuff?

So much appreciated.

Regards

Dans
 
Upvote 0
Top