Hi,
I'm wondering if I can deal with multiple SoftwareSerial at the same time.
This is not about receiving things from SoftwareSerial, but just about writing.
I need to write 18 SoftwareSerial at the same time.
I'm trying to control 18 thermal printers simultaneously, sending them exactly same data via SoftwareSerial. (but not to all 18 printers everytime. it could be just 1, 5, or some random number)
No need to read data from printers.
First I tried using array.
I declared an array of SoftwareSerial, and sent data one by one like this:
void handOverLine() {
for(int i = 0; i < 18; i++) {
if(targets[i] == 1) {
printBitmap(Thermal[i], 48, line);
}
}
}
void printBitmap(SoftwareSerial thermal, int w, byte data[]) {
//w = width/8 of bitmap, data = pixel data(one line = 48bytes, 384px)
thermal.write(28); //FS
thermal.write(75); //K
thermal.write((byte)0x00); //n1
thermal.write(w); //n2
for(int i = 0; i < w; i++) {
thermal.write(data[i]);
}
}
Note that the code is just an excerpt.
I succeeded with this code.
However, the problem was that it took forever to print entire picture!
So I tried to fix the SoftwareSerial library.
But I just cannot figure out how.
What I'm imagining is like this:
- When you declare ModifiedSoftwareSerial, there is no need of arguments for construction.
- Instead, ALL pins I'm planning to use are set as OUTPUT and pulled-up. (just TX pins)
- When you write something with ModifiedSoftwareSerial, ALL TX pins write the same data simultaneously.
- Then chips like 74HC245 filters signal in order to send data just to printers that I want to print. (This part is nothing to do with library)
Okay, this cannot be something universal.
I just want a library only for this project.
What I cannot understand of the SoftwareSerial library is this 'tx_pin_write' thing.
void SoftwareSerial::tx_pin_write(uint8_t pin_state)
{
if (pin_state == LOW)
*_transmitPortRegister &= ~_transmitBitMask;
else
*_transmitPortRegister |= _transmitBitMask;
}
I can't figure out what _transmitPortRegister is about.
And it looks like controlling just a pin of A port.
I need to control total 6 ports: PA, PB, PC, PD, PG, PL.
Can anyone advice me?
Thank you for reading my poor English,
and thanks again in advance for replies ![]()
Please feel free to reply and to ask me more information to solve this problem.
Oh and I'm only friendly with Arduino code, not competent in any other languages, though I can understand most of easy codes.