We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › Serial communication with message display....
Page Index Toggle Pages: 1
Serial communication with message display.... (Read 1402 times)
Serial communication with message display....
Apr 11th, 2009, 5:05pm
 
I am having a few issues using a moving message display I bought from Maplin (#N01GA - It won't let me directly link you to it)...

The display works fine with the software provided but I want to use processing to send twitter messages to it for a Uni project.

The idea is fine but unless I use the provided software it only lets me send upto 18 characters before the display goes blank until I reprogram it.

I have been using a serial communication monitor to compare the messages sent by the original app to mine and byte for byte they are the exact same and come in one lump rather than seperate communications.

I cannot understand it, the checksum is even the same, please can people wiser than I offer a few suggestions?

Thanks!

Code:
import processing.serial.*;

// Before the message
String before_out_crc = "<ID00>";
String before_in_crc = "<BE>05<E><ID00><L1><PA><FE><MQ><WC><FE>";

// The message
String message = "OMG I MADE IT WORK";
String crc;

// After the message
String after_in_crc = "<E><ID00><BF>06";
String after_out_crc = "<E>";

// Serial connection
Serial display;
int port = 2;

void setup() {
 display = new Serial(this, Serial.list()[port], 9600);
 display.write(createMessage());
}

void draw() {
}

String createMessage() {
 char check = 0;
 String output;
 String theseChars = before_in_crc + message + after_in_crc;
 for (int c = 0; c < theseChars.length(); c++) {
   check = char(check ^ theseChars.charAt(c));
 }  
 output = before_out_crc + before_in_crc + message + hex(check, 2) + after_in_crc + after_out_crc;
 return output;
}
RESOLVED
Reply #1 - Apr 12th, 2009, 10:55am
 
It seems that sending one command after another so quickly was causing issues and that delay(1000) when coupled with Serial.write() causes no delays? Not sure why but its working now, for reference here is the code I wrote and I found an Protocol guide for the exact unit I have...

It won't let me post links yet so just let me know if you need the link via email or what ever.

Code:
  import processing.serial.*;

String message = "Happy Easter from all at Ash Cottage!";
//String message = "This message has been put here by Processing v1";
int state = 0;
Serial display;
boolean firstRun = true;

void setup() {
display = new Serial(this, Serial.list()[2]);
}

void draw() {

if (message.length() > 239) {
display.stop();
exit();
}

if (firstRun) {
firstRun = false;
state = 1;
display.write("<ID01><BE>05<E>");
}

if (display.available() > 2) {

String serialData = display.readString();
println(serialData);

if (serialData.equals("ACK")) {
if (state == 0) {
state = 1;
display.write("<ID01><BE>05<E>");
} else if (state == 1) {
state = 2;
display.write(outputMessage());
} else if (state == 2) {
state = 3;
display.write("<ID01><BF>06<E>");
} else if (state == 3) {
display.stop();
exit();
}
}
}
}

String outputMessage() {
String theseChars = "<BE>05<E><ID01><L1><PA><FE><MA><WC><FE>" + message + "<E><ID01><BF>06";
char check = 0;
for (int c = 0; c < theseChars.length(); c++) {
check = char(check ^ theseChars.charAt(c));
}
return "<ID01><L1><PA><FE><MA><WC><FE>" + message + hex(check, 2) + "<E>";
}
Page Index Toggle Pages: 1