[Gambas-user] Serial I/O with byte data
Alexie
ualex73 at ...626...
Mon May 15 07:17:30 CEST 2017
Following should work for you:
Public Sub XXX_Read()
Dim iLen As Integer
Dim aData As Byte[]
iLen = Lof(Last)
aData = New Byte[]
aData.Resize(iLen)
Try aData.Read(Last, 0, iLen)
End
You need to get the length (lof) first, then resize array ... only then you
can read it.
2017-05-14 21:56 GMT+02:00 Tobias Boege <taboege at ...626...>:
> On Sun, 14 May 2017, alexchernoff wrote:
> > Good day all,
> >
> > Anyone know how to read data received on serial port into an array of
> bytes
> > instead of string?
> >
>
> I think that's not possible.
>
> > String gets unreadable binary characters, so how can I
> > put them into byte[] or so?
> >
>
> This shouldn't be a problem. Gambas Strings are not null-terminated and can
> contain any sequence of bytes, which includes non-printable characters
> (which
> I think is what you meant by "unreadable" characters).
>
> If you insist on a Byte[], read it into a String and use
> Byte[].FromString(),
> but there is no way to go around the String, AFAICT (and that is because
> there is no need to, as Strings can handle binary data just fine).
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list