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 & HelpPrograms › DMX sketch quits
Page Index Toggle Pages: 1
DMX sketch quits (Read 601 times)
DMX sketch quits
Jan 2nd, 2010, 12:21am
 
I have a processing sketch which controls 16 LED channels via DMX.  Each separate LED is animated, slowly oscillating between bright and dark by having their voltages run along a sine wave.  The result is that the LEDs look like they're 'breathing'.  This sketch runs in an installation which is meant to run continuously for several weeks, but unfortunately the LEDs always quit 'breathing' after several days, leaving the LEDs in a constant dimly-lit state.  

From looking at my code below, can anyone determine why this sketch is quitting?

The code is in 2 parts: a DMX class in one tab of the sketch, and the main code in another tab.

I hope my question is clear to you.  Please let me know if you notice a possible source of the problem, thanks.

DMX CODE:
import processing.serial.*;

// This class encapsulates the handling of DMX messages through the Serial port.
// This first version only implements writting messages.
public class DMX
{
   // Constructor where the parent PApplet object, the string identifying the port ("COM1", "COM2", etc.),
   // the baudrate      and the number of channels are specified.
   DMX(PApplet parent, String port, int rate, int size)
   {
       serial = new Serial(parent, port, rate);
       
       universeSize = size;
       int dataSize = universeSize + 1;
       message = new byte[universeSize + 6];
       message[0] = DMX_PRO_MESSAGE_START;
       message[1] = DMX_PRO_SEND_PACKET;
       message[2] = byte(dataSize & 255);  
       message[3] = byte((dataSize >> 8) & 255);
       message[4] = 0;
       for (int i = 1; i <= universeSize; i++)
       {
           message[4 + i] = byte(0);
       }
       message[universeSize + 5] = DMX_PRO_MESSAGE_END;
   }
 
   // Writes value to the channel, if the value is different from the last written.
   void setDMXChannel(int channel, int value)
   {
       if (message[channel + 5] != byte(value))
       {
           message[channel + 5] = byte(value);
           serial.write(message);
       }
   }
   
     // Serial port to communicate with the DMX USB adapter.
   private Serial serial;
   
     // Number of channels.
   private int universeSize;
     
   // Format of the dmx message:
   // message[0] = DMX_PRO_MESSAGE_START;
   // message[1] = DMX_PRO_SEND_PACKET;
   // message[2] = byte(dataSize & 255);  
   // message[3] = byte((dataSize >> 8) & 255);
   //     message[4] = 0;
   // message[4 + 1] = value in channel 0
   // message[4 + 2] = value in channel 1
   // ...
   // message[4 + universeSize] = value in channel universeSize - 1
   // message[4 + universeSize + 1] = DMX_PRO_MESSAGE_END
   // where dataSize = universeSize + 1;        
   private byte[] message;
   
   private byte DMX_PRO_MESSAGE_START = byte(0x7E);
   private byte DMX_PRO_MESSAGE_END = byte(0xE7);
   private byte DMX_PRO_SEND_PACKET = byte(6);    
}

**and the MAIN CODE:

DMX dmx;
float a = 0.0;
float b = 0.0;
float c = 0.0;
float d = 0.0;
float e = 0.0;
float f = 0.0;
float g = 0.0;
float h = 0.0;
float i = 0.0;
float j = 0.0;
float k = 0.0;
float l = 0.0;
float m = 0.0;
float n = 0.0;
float o = 0.0;
float p = 0.0;

float inc = PI/25.0;

void setup() {
 size(200, 200);
 frameRate(120);
 for (int i = 0; i < 50; i++)
   //dmx = new DMX(this, "/dev/tty.usbserial-ENQBGG78", 9600, 32);
   dmx = new DMX(this, "/dev/cu.usbserial-ENQSIJZ9", 9600, 32);
}

void draw() {
 int v2 = int(150+sin(a)*105.0);
 int v3 = int(150+sin(b)*105.0);
 int v4 = int(150+sin(c)*105.0);
 int v5 = int(150+sin(d)*105.0);
 int v6 = int(150+sin(e)*105.0);
 int v7 = int(150+sin(f)*105.0);
 int v8 = int(150+sin(g)*105.0);
 int v9 = int(150+sin(h)*105.0);
 int v10 = int(150+sin(h)*105.0);
 int v11 = int(150+sin(h)*105.0);
 int v12 = int(150+sin(h)*105.0);
 int v13 = int(150+sin(h)*105.0);
 int v14 = int(150+sin(h)*105.0);
 int v15 = int(150+sin(h)*105.0);
 int v16 = int(150+sin(h)*105.0);
 int v17 = int(150+sin(h)*105.0);

 dmx.setDMXChannel(1, v2);
 a = a + (inc/20.0);

 dmx.setDMXChannel(2, v3);
 b = b + (inc/22.3);

 dmx.setDMXChannel(3, v4);
 c = c + (inc/18.6);

 dmx.setDMXChannel(4, v5);
 d = d + (inc/19.4);

 dmx.setDMXChannel(5, v6);
 e = e + (inc/24.1);

 dmx.setDMXChannel(6, v7);
 f = f + (inc/25.6);

 dmx.setDMXChannel(7, v8);
 g = g + (inc/20.4);

 dmx.setDMXChannel(8, v9);
 h = h + (inc/21.7);

 dmx.setDMXChannel(9, v10);
 i = i + (inc/19.8);
 
 dmx.setDMXChannel(10, v11);
 j = j + (inc/24.1);
 
 dmx.setDMXChannel(11, v12);
 k = k + (inc/21.8);
 
 dmx.setDMXChannel(12, v13);
 l = l + (inc/20.7);
 
 dmx.setDMXChannel(13, v14);
 m = m + (inc/26.0);
 
 dmx.setDMXChannel(14, v15);
 n = n + (inc/21.3);
 
 dmx.setDMXChannel(15, v16);
 o = o + (inc/19.3);
 
 dmx.setDMXChannel(16, v17);
 p = p + (inc/26.1);

 //println(v2);
 //println(Serial.list());
}
Re: DMX sketch quits
Reply #1 - Jan 2nd, 2010, 3:09am
 
No idea, you should take a look at the console, if available, you might have an exception, an error or something. Like out of memory (unlikely), problem with serial port, whatever.

That's the kind of question worth asking in the Electronics, Serial Library forum, perhaps, to meet people used to such experiments.
Page Index Toggle Pages: 1