|
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
|
|
|
|
|
hi every body
the idea of my project in general is to read an excel file and save them to to DB.
so I put a progress bar that work while reading the excel file but the problem is that the progress bar seems hung and doesn't work while reading.
I didn't find any solution for that so please I need ur help
thank u....
|
|
|
|
|
Genius.Boy,
You need to do the reading of the excel file in another thread. BackgroundWorker would be best to use, as it allows for you to also update the progress bar.
MSDN[^]
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Thank u Mr. Gareth H
Nice solution...
.
.
thank u again
Genius.Boy
|
|
|
|
|
i made a error reporter and i want to display a "Debug" button on my form...
I want to only show this button if theirs a debugger installed...
basically i want to display the Just-In-Time debugger window.
Anyway to do this?
|
|
|
|
|
There is a precompiler option #if DEBUG that could work for you. Otherwise a series of if-statements is the only choice.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
FocusedWolf wrote: I want to only show this button if theirs a debugger installed...
Look at the Debugger class, specifically IsAttached , Attach() and Break() .
|
|
|
|
|
I have an database editing application. The tables in this application are sorted by ID (an autonumber field), so they are basically in FIFO order.
However, the editing part of the application consists of a DataGridView object to enable the user to view all the records in the table and some text boxes and comboboxes below the DataGridView to see the details of each individual record in the table.
The user edits or adds records through the text boxes and comboboxes that reflect the fields in the datatable, while the DataGridView is just for viewing (set to Edit Programmatically). The user, though, can sort records using the DataGridView to help him/her find records in the table by the order of some field other than the ID.
Well, when I add records to the table when the table is sorted according to, say, a serial number, I'm experiencing some problems. The record is added, but does not occupy the final position in the data table. Rather, it occupies the first position in the table because a new record consists of a blank serial number. Is there a way to keep from sorting the new record into the first position in the datatable? I would prefer to keep it as the last record in the table, and then sort it into its appropriate position.
Thanks.
|
|
|
|
|
Is there a way I can determine the name of the variable that is being accessed.
In the following example, when I call Item22.Description (or any other property of BigClass), I'd like to be able to find variablename (Item22 in this case).
class BigClass
{
public static Hashtable DescriptionsTable;
DataItem Item01;
....
DataItem Item64;
}
class DataItem
{
double _Value;
string Description
{ get { return BigClass.DescriptionsTable[variablename]; } }
}
If I don't have access to this name I figure I'll have to add a second property to BigClass for each Item (ex. Item22Description...), which seems like a waste. And I don't want to have the descriptions in each BigClass because they can get quite lengthy and there will be hundreds of BigClass instances at a time.
Any ideas?
If there's another option, how could I re-architect without wasting too much space?
|
|
|
|
|
The approach you are using is probably not ideal. The only thing I can think of is to eliminate the members and add an indexor.
Ideally, however, each property should access an individual member. It is the most logical method.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
You can't get the variable name from the object, as you are not accessing the variable. You are just accessing an object that the variable happens to be referencing. There is no backwards reference from the object to the variable.
If you want the DataItem object to know the name of the variable, you have to store the name in the object.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi
I am using reflection to write properties in some code. But, I don't need to fetch readonly properties. How can I check whether a property is readonly or not in .NET?
Please advise. Thanks
Pankaj
|
|
|
|
|
You can use the second line specifying the BindingFlags with a SetProperty which excludes all properties that don't include a set declaration on the property.
static IEnumerable<PropertyInfo> GetWritableProperties<T>()
{
Type type = typeof(T);
return type.GetProperties(BindingFlags.SetProperty);
}
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Which is preferred, to pass a reference or use a return value
private DateTime SetToHour(DateTime timeCheck, int hours)
{
return timeCheck;
}
or
private void SetToHour(ref DateTime timeCheck, int hours)
{
}
I have done some searching online and asked around work, no definitive answer has come. Use ref for this and return for that. Mostly seems to personal choice. Thoughts???
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
Hi,
IMO a return value is the normal approach.
It has some drawbacks:
- you can return only one thing;
- if the return thingy is a reference type, then the API choice implies you must
create an object of that type, which you may or may not want to impose on the API users.
Hence, a ref parameter is acceptable and useful when:
- the function has to produce more than one thing;
- or the function is supposed to stuff some data in a pre-existing struct.
|
|
|
|
|
Thanks, answered my question succinctly.
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
In my opinion I'd use the non-ref method. The reason is, that many classes in the .NET framework are immutable, like string . Even more important, the DateTime class also uses return values (AddHours , AddMonths , etc.), which means that DateTime objects are immutable, too.
In C# 3.0 you could also use extension methods, for example like this:
public static class DateTimeExtensions
{
public static DateTime SetToHour(this DateTime source, int hours)
{
if ((hours < 0) || (hours > 23))
throw new ArgumentOutOfRangeException("Hours must be between 0 and 23");
return source.AddHours(hours - source.Hour);
}
}
and call it like that:
DateTime t = DateTime.Now;
Console.WriteLine(t);
t = t.SetToHour(24);
Console.WriteLine(t);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
>>The reason is, that many classes in the .NET framework are immutable, like string.
Im not quite getting in what way you mean that would affect anything?
Its perfectly possible to pass a "ref string"
Even if the instance of a string is immutable doesnt mean that the variable reference to that instance is immutable...
Or do you just mean that the api would be more standard because other methods on immutable types work that way?
(In that case I agree , rule of least surprise)
|
|
|
|
|
Roger Alsing wrote:
Its perfectly possible to pass a "ref string"
Even if the instance of a string is immutable doesnt mean that the variable reference to that instance is immutable...
Absolutely correct - what I meant is that the .NET library methods for the string and DateTime objects (among others) do not modify the variable but rather return a new instance. So if you want to add another method to the DateTime class (by using extension methods or simply a utility class) I might be a good idea to do it in the same way like the original DateTime methods do, by returning a new instance.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I developed a C# console program to control a camera's PTZ, and I call remote procedures from a GUI to move left/right/up/down. As I have 2 WindowsXP computers my C# RPC's work great. QUESTION: I also need to drive this PTZ from a computer running Windows, but the coding environment is JAVA. What does the JAVA coder need to do in order to call my functions? thanks, xlthim
|
|
|
|
|
Couple ways to do this. A popular one seems to be utilizing Mono's IKVM[^].
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
I am trying to use a DLL which was originaly written in fortran. Allthough this DLL is suposed to be in C, a lot of its functions do not work in C# (some does). I believe it has fortran version as well as C version. Has anyone played with Fortran DLL in C#. I get the following errors during compilation.
AccessViolationException
BadImageFormatException
DllNotFoundException
YOu can go to this link http://www.originlab.com/index.aspx?s=8&lm=117&pid=251[^]
download the "examples in zip form". They have a simple DLL,FortranDLL, which contains basic functions such as double SUMFT(double, double), which returns the sum of two doubles. Can any one make it work? What do i need to make it work?
|
|
|
|
|
I believe you can P/Invoke into most (all?) Fortran calls. Have you tried this? The Numerical Algorithms Group shows how to call their Fortran dll from C#[^], perhaps that will get you off to a good start.
If this fails or doesn't work for certain calls, but you can access it via C++, you could write a C++/CLI (managed C++) dll that talks to the Fortran dll, then have your C# code talk to the C++/CLI dll. There are articles on this site that show you how to write simple C++/CLI dlls to call native code.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
How may I stop a running method if it takes longer than 10 seconds. I want a procedure called hello() to be called 200 times in a loop & I want the method to be aborted & the loop to be broken if the hello() methods, fails to respond in 10 seconds. How may I do this?
|
|
|
|
|
semiramisContraA,
You've already asked that question Here[^]
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|