Go Down

Topic: software serial serial.write (Read 2016 times) previous topic - next topic

pauld

i want to send literal numbers out a software serial port, in the same way as serial.write allows me to do with the hardware serial port. But the software serial library does not seem to support a serial.write function.
the software serial serial.print function only sends ascii representations of numbers.

In particular I need to transmit numbers at the very bottom range of the ASCII table (e.g. 0, 1, 2...) that represent non-printable characters.

Is there any workaround for this? A lookup table for example, or a function to preprcess numbers into their corresponding ascii bytes?

PaulS

Can you process the string on the receiving end, to convert it back to an integer?

Whether this was an oversight or a deliberate omission, I don't know. But, it does appear to be a limitation of both SoftwareSerial and NewSoftSerial.

pauld

Unfortunately I can't do anything on the receive end, short of convincing the device manufacturer to revise his code.
but since the software serial can send single bytes, there must be some way to get it to send the bytes I want. So far, the compiler refuses to accept arguments like "\0" or "NUL"  - possible names of these low-valued ascii characters.

PaulS

I guess, then, that you are going to be limited to using a hardware serial port to communicate with this device.

The Mega has 4 such ports, if you need more than one. The SeeedStudio variant is not much more than an Arduino from SparkFun.

pauld

Yes, I have already applied the Megas in situations where I needed bidirectional serial communication with multiple serial peripherals  - it makes everything easier. I had just thought that in this situation, where data needs only to be sent and not received, that the software serial library would be applicable. it appears that it would not be too difficult to extend the library to include a serial.write function. Do you know who might be a good person to contact about this in a future revision.
Thanks

Ran Talbott

You can use the "serial.print(ascii_value, BYTE)" form of print() to send raw characters.

pauld


pauld

Yes  -  using the BYTE argument does the trick.
Thanks so much!

Go Up