I have been working on a rather simple serial port send routine (to get my feet wet with B4X). I got it working, but my issue is understanding one of the problems I ran across to get it working properly.
In my code I defined an array of bytes called buffered_bytes. I tried using the following simple statement, astream.Write(buffered_bytes(0)), the IDE would throw a cast error on this statement. I am not sure why, I am trying to send a byte (I also tried a straight byte with no array defined) and the statement calls for a byte to be sent. I went through a ton of samples on your forums and found the following instead - this being correct - Dim b() As Byte = Array As Byte(buffered_byte(0)). What is the difference except the verbosity of the statement. In my case as well as this statement a byte is passed to the function, but one calls a cast error and one does not. I thought cast errors were due to mixing types, in essence you can pass a string when an integer is called for as a type. Any help hopefully may clear this up for me. Even though I have the routine working I would like to understand what I did wrong.
In my code I defined an array of bytes called buffered_bytes. I tried using the following simple statement, astream.Write(buffered_bytes(0)), the IDE would throw a cast error on this statement. I am not sure why, I am trying to send a byte (I also tried a straight byte with no array defined) and the statement calls for a byte to be sent. I went through a ton of samples on your forums and found the following instead - this being correct - Dim b() As Byte = Array As Byte(buffered_byte(0)). What is the difference except the verbosity of the statement. In my case as well as this statement a byte is passed to the function, but one calls a cast error and one does not. I thought cast errors were due to mixing types, in essence you can pass a string when an integer is called for as a type. Any help hopefully may clear this up for me. Even though I have the routine working I would like to understand what I did wrong.