Thanks for your interest in the Intel Edison Platform.
We appreciate the information provided, could you please help us to clarify if when you are referring that the Uart.readStr() method truncates at nulls, it is because you are not receiving any data through the uart port ?
Also, we would like to suggest you to use the function dataAvailable() (more details regarding this function here: Uart Class Reference), and you will be able to read data only when it is available, please try adding this to your code and let us know your results.
I am definitely receiving data through the UART port. It's just incomplete. Here's an example of the data that I receive using readStr in Java:
00fe 0009 0016 0001 0001
00fe 0009 0017 0001 0001
00fe 0009 0018 0001 0001
00fe 0009 0019 0001 0001
00fe 0033 001a 0001 0001 00fd 0002 0050 0072 0065 0041 0072 006d 003a 0020 0052 0043 0020 006e 006f 0074 0020 0063 0061 006c 0069 0062 0072 0061 0074 0065 0064
0041 0072 006d 003a 0020 0043 006f 006d 0070 0061 0073 0073 0020 006e 006f 0074 0020 0063 0061 006c 0069 0062 0072 0061 0074 0065 0064
00fe 0009 001d 0001 0001
00fe 0009 001e 0001 0001
00fe 0009 001f 0001 0001
00fe 0009 0020 0001 0001
and here's an example of some correct data that I receive using a python script:
This is the python script:
ser = serial.Serial('/dev/ttyMFD1', baudrate=921600)
packet = ''
byte = ser.read(size=1)
hexstr = codecs.encode(byte, 'hex_codec')
packet += str(hexstr)
if hexstr == 'fe':
packet = packet[:-2]
packet = 'fe'
Observe the similarity (except for the formatting, which doesn't bother me). The main problem is that readStr simply terminates at 0000, which makes sense, because strings are often null-terminated, right? That's why I am asking about a workaround for the lack of a read(int) method.
Thank you for all the information provided and clarify me that. I have found this information regarding the Java strings: Do strings in Java also terminate with a '\0' character like strings in C? and why strings are terminated with null character in java?, there is mentioned that the Java strings are not null terminated, however, the behavior you are getting is very strange since the readStr terminates at 0000. I’d suggest you to report this issue in the “issues” tab in the mraa web site since they could give you a more accurate answer.
Moreover, we would like to know if could be an option to use C/C++ instead of Java in the Intel System Studio IoT Edition in order to use int read (char *data, int length) and test if it works.
I have considered and rejected that option. I have opted to program in Python for the Edison (without the Intel System Studio IoT Edition) for now. I may consider returning to Intel System Studio IoT Edition if the Java libraries are completed in future.
Thanks for your reply, I understand and using Python is the best option, good luck with your project, also, we’d suggest you to report this behavior in the “issues” tab in the Mraa web site since they are in charge of it and they would be aware of this behavior.