I would like to be able to pass the serial port number I want to use as an argument to a function. This would allow me to use the same function with two different devices connected to two different serial ports. See the example below to get the idea of what I want to do.
If you are only interested in allowing hardware serial ports, which sounds like the case, use the class USARTSerial&. For example:
void foo(USARTSerial &portName) {
}
You can pass in Serial1, Serial2, … to foo.
However, if you want to be able to pass in Serial (USB serial) or a hardware serial port (Serial1, Serial4, …) then your options are a bit more limited.
You can use Stream which will allow you to read, write, print, etc… That’s usually the best choice. The issue is that there is no common base class that supports, for example, begin().
If you want to support all kinds Stream based interfaces (e.g. USBSerial, USARTSerial, ParticleSoftSerial, …) you could creat a base class that internally uses Stream and derive some templated classes from it that implement the hardware specific routines (e.g. xxx.begin()).
Is there documentation for the configuration using USB serial commands? Some of them are pretty self explanatory, but not all of them.
i - Prints the device ID (24 character hexadecimal string)
f - Firmware update (using ymodem)
x - Exit listening mode
s - Print system_module_info
v - System firmware version
L - Safe listen mode (does not run user code concurrently with listening mode)
w - Configure Wi-Fi
m - Print MAC Address for the Wi-Fi adapter
More documentation would lead me to believe that I’m not missing anything. More documentation around what the different fields in system_module_info are would be nice. It’s not critical by any means, but more documentation and less effort on the user’s end allows the user to spend more time on their application, rather than decoding undocumented Serial interfaces.
I have followed your tutorial. I am using putty on my windows, but the only the analogread value seems to be showing up? It’s all jumbled together so I can’t decipher my data. I tried to insert commas to separate the values, or use println(), but no luck. Any ideas?
Have you tried particle serial monitor --follow() to catch the serial output?
If the data shows up with line breaks there you probably need to change some PuTTY settings.
epar@epar-laptop:~/bin$ ./particle usb
Control USB devices
Usage: particle usb <command>
Help: particle help usb <command>
Commands:
list List the devices connected to the host computer
start-listening Put a device into the listening mode
stop-listening Make a device exit the listening mode
safe-mode Put a device into the safe mode
dfu Put a device into the DFU mode
reset Reset a device
configure Update the system USB configuration
Global Options:
-v, --verbose Increases how much logging to display [count]
-q, --quiet Decreases how much logging to display
I think this is a Serial issue, but to be honest I am not sure. I am sending data over a Mesh network from edge devices to my gateway, and then writing that data over the USB port.
Serial.write(data);
Off the USB port, I’m getting all sorts of extra data & errors I think are from the Serial port? Does anyone know where this extra metadata is coming from (and how to stop it/ parse it out and only send my simple dictionary over in Serial.write(data); ?
All these lines starting with a milliseconds timestamp and [....] category label come from the logging commands embedded in the device OS.
You obviously have a SerialLogHandler declared but haven’t limited the scope as shown in the reference docs https://docs.particle.io/reference/device-os/firmware/photon/#logging-categories
If you want to get rid of all the logging output and only want to see your Serial.write() output you can just remove/comment the declaration of the SerialLogHandler entirely.
I have 9 parameters reading by the electron remotely, now i am thinking to use LCD to locally monitor them. i found LCD that can accept RS232, so is it possible to to get all these 9 parameters from particle electron to the LCD using RS232 communication?