2

I am currently on a project and trying to send data through an Xbee. I used the SerialPort.h library to send 'H' and 'L' via the serial port to an Arduino to turn on a led. It worked. This I tried in Arduino and then in Visual Studio. Both worked.

But my final goal is to send data through serial port as uint8. But I don't know how to send data as uint8. The libraries usually use char for writing on the port.

Thank you in advance. Sorry if it sounds as a newbie question.

Mousa
  • 2,190
  • 3
  • 21
  • 34
  • You could send the number you wish as string of chars, and in the other side convert it to int, using functions like Integer.parseint() – TheEngineer Dec 02 '18 at 23:11
  • Can you elaborate on what part you are finding difficult? Which part of your code is having problems with `uint8`? – Galik Dec 02 '18 at 23:14
  • Please post some of your code so we can see what you've tried, and let us know how you expect it to work and what it's doing instead. There should be an API to `write()` data that takes a pointer to that data and a length parameter. This could be in addition to a `print()` API that would take a `char *` and use `strlen()` for the length. – tomlogic Dec 08 '18 at 19:05

1 Answers1

1

A uint8 is an eight-bit unsigned value, while a char can be signed or unsigned, but is still an eight bit byte. For serial communications you can sent the uint8 using the char interface. The only special thing might be a cast when sending the data You will need to know from context what you are receiving and perform the reverse operation.

janm
  • 17,976
  • 1
  • 43
  • 61