Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem in viewing pictures on a Win Form Pin
LordCover28-May-08 15:24
LordCover28-May-08 15:24 
QuestionHow to delete memory allocated by COM? Pin
RYU^^28-May-08 13:52
RYU^^28-May-08 13:52 
AnswerRe: How to delete memory allocated by COM? Pin
RYU^^28-May-08 14:34
RYU^^28-May-08 14:34 
AnswerRe: How to delete memory allocated by COM? Pin
Tony Richards29-May-08 3:30
Tony Richards29-May-08 3:30 
GeneralRe: How to delete memory allocated by COM? Pin
RYU^^29-May-08 13:51
RYU^^29-May-08 13:51 
QuestionAbout DMX protocol Pin
pocho210128-May-08 13:24
pocho210128-May-08 13:24 
AnswerRe: About DMX protocol Pin
Vasudevan Deepak Kumar28-May-08 18:31
Vasudevan Deepak Kumar28-May-08 18:31 
AnswerRe: About DMX protocol [modified] Pin
muzes24-Sep-09 11:37
muzes24-Sep-09 11:37 
The DMX software protocol is described here:

http://www.theater-technisch-lab.nl/dmxen.htm

RS-485 is not actually a protocol but a hardware interface.
It transmits data as the voltage difference between two data lines, rather than the absolute voltage on a single data line. Software wise, it is exactly like RS-232 but its maximum cable length is much further (roughly 1000M vs 12M).

In other words, for DMX you cannot use your serial port, have to spend money on hardware. The cheapest I have found is the Enttec Open DMX controller. (USD) $60.


If you are writing your own code this guy, Hippy, is a great start.

http://members.westnet.com.au/rowanmac/opendmx.html

He has an open source VB that shows how to write to the controller.

One thing to watch out for is installing the driver for the controller.
The included driver did not work for me on WinXP.
But the following did:

http://www.enttec.com/dmx_usb/d2xx_setup.exe

Here is a quick and dirty C# class to run the Enttec OpenDmx usb controller:



using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;


namespace Test
{

public class OpenDMX

{

public static byte[] buffer;
public static uint handle;
public static bool done = false;
public static int bytesWritten = 0;
public static FT_STATUS status;

public const byte BITS_8 = 8;
public const byte STOP_BITS_2 = 2;
public const byte PARITY_NONE = 0;
public const UInt16 FLOW_NONE = 0;
public const byte PURGE_RX = 1;
public const byte PURGE_TX = 2;




[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_Open(UInt32 uiPort, ref uint ftHandle);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_Close(uint ftHandle);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_Read(uint ftHandle, IntPtr lpBuffer, UInt32 dwBytesToRead, ref UInt32 lpdwBytesReturned);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_Write(uint ftHandle, IntPtr lpBuffer, UInt32 dwBytesToRead, ref UInt32 lpdwBytesWritten);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_SetDataCharacteristics(uint ftHandle, byte uWordLength, byte uStopBits, byte uParity);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_SetFlowControl(uint ftHandle, char usFlowControl, byte uXon, byte uXoff);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_GetModemStatus(uint ftHandle, ref UInt32 lpdwModemStatus);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_Purge(uint ftHandle, UInt32 dwMask);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_SetBreakOn(uint ftHandle);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_SetBreakOff(uint ftHandle);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_GetStatus(uint ftHandle, ref UInt32 lpdwAmountInRxQueue, ref UInt32 lpdwAmountInTxQueue, ref UInt32 lpdwEventStatus);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_ResetDevice(uint ftHandle);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_SetDivisor(uint ftHandle, char usDivisor);
[DllImport("FTD2XX.dll")]
public static extern FT_STATUS FT_ClrRts(uint ftHandle);




public static void start()
{
buffer = new byte[4]; // can be any length up to 512. The shorter the faster.
handle = 0;
status = FT_Open(0, ref handle);
Thread thread = new Thread(new ThreadStart(writeData));
thread.Start();
setDmxValue(1, 0); // set DMX channel 1 to maximum value
}

public static void setDmxValue(int channel, byte value)
{
buffer[channel]=value;
}

public static void writeData()
{
while (!done)
{
initOpenDMX();
FT_SetBreakOn(handle);
FT_SetBreakOff(handle);
bytesWritten = write(handle, buffer, buffer.Length);
System.Threading.Thread.Sleep(50);
}

}

public static int write(uint handle, byte[] data, int length)
{
IntPtr ptr = Marshal.AllocHGlobal((int)length);
Marshal.Copy(data, 0, ptr, (int)length);
uint bytesWritten = 0;
FT_Write(handle, ptr, (uint)length, ref bytesWritten);
return (int)bytesWritten;
}

public static void initOpenDMX()
{
status = FT_ResetDevice(handle);
status = FT_SetDivisor(handle, (char)12); // set baud rate
status = FT_SetDataCharacteristics(handle, BITS_8, STOP_BITS_2, PARITY_NONE);
status = FT_SetFlowControl(handle, (char)FLOW_NONE, 0, 0);
status = FT_ClrRts(handle);
status = FT_Purge(handle, PURGE_TX);
status = FT_Purge(handle, PURGE_RX);
}

}


public enum FT_STATUS2
{
FT_OK = 0,
FT_INVALID_HANDLE,
FT_DEVICE_NOT_FOUND,
FT_DEVICE_NOT_OPENED,
FT_IO_ERROR,
FT_INSUFFICIENT_RESOURCES,
FT_INVALID_PARAMETER,
FT_INVALID_BAUD_RATE,
FT_DEVICE_NOT_OPENED_FOR_ERASE,
FT_DEVICE_NOT_OPENED_FOR_WRITE,
FT_FAILED_TO_WRITE_DEVICE,
FT_EEPROM_READ_FAILED,
FT_EEPROM_WRITE_FAILED,
FT_EEPROM_ERASE_FAILED,
FT_EEPROM_NOT_PRESENT,
FT_EEPROM_NOT_PROGRAMMED,
FT_INVALID_ARGS,
FT_OTHER_ERROR
};

}

modified on Thursday, September 24, 2009 6:54 PM

Questionprogress bar is hanging Pin
Genius.Boy28-May-08 12:54
Genius.Boy28-May-08 12:54 
AnswerRe: progress bar is hanging Pin
Gareth H28-May-08 13:27
Gareth H28-May-08 13:27 
GeneralRe: progress bar is hanging Pin
Genius.Boy28-May-08 17:58
Genius.Boy28-May-08 17:58 
QuestionDisplay a "Debug" button? Pin
FocusedWolf28-May-08 10:23
FocusedWolf28-May-08 10:23 
AnswerRe: Display a "Debug" button? Pin
Ennis Ray Lynch, Jr.28-May-08 11:00
Ennis Ray Lynch, Jr.28-May-08 11:00 
AnswerRe: Display a "Debug" button? Pin
leppie28-May-08 21:25
leppie28-May-08 21:25 
QuestionAdd Record to Data Table Pin
polishprogrammer28-May-08 10:09
polishprogrammer28-May-08 10:09 
QuestionProgramatically determine variable name Pin
redivider28-May-08 9:29
redivider28-May-08 9:29 
AnswerRe: Programatically determine variable name Pin
Ennis Ray Lynch, Jr.28-May-08 11:02
Ennis Ray Lynch, Jr.28-May-08 11:02 
AnswerRe: Programatically determine variable name Pin
Guffa28-May-08 12:31
Guffa28-May-08 12:31 
QuestionChecking readonly property using reflection? Pin
pankazmittal28-May-08 9:11
pankazmittal28-May-08 9:11 
AnswerRe: Checking readonly property using reflection? Pin
Ed.Poore28-May-08 10:33
Ed.Poore28-May-08 10:33 
QuestionPass Reference or Return Value Pin
Jim Warburton28-May-08 8:24
Jim Warburton28-May-08 8:24 
AnswerRe: Pass Reference or Return Value Pin
Luc Pattyn28-May-08 8:40
sitebuilderLuc Pattyn28-May-08 8:40 
GeneralRe: Pass Reference or Return Value Pin
Jim Warburton28-May-08 8:54
Jim Warburton28-May-08 8:54 
AnswerRe: Pass Reference or Return Value Pin
User 665828-May-08 8:59
User 665828-May-08 8:59 
GeneralRe: Pass Reference or Return Value Pin
Roger Alsing28-May-08 10:46
Roger Alsing28-May-08 10:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.