Commit 9f260e79 LN

增加art-net

1 个父辈 176e3b0a
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Box\BOXManager.cs" /> <Compile Include="Box\BOXManager.cs" />
<Compile Include="DeviceLibrary\led\BaseLedManager.cs" /> <Compile Include="DeviceLibrary\led\BaseLedManager.cs" />
<Compile Include="DeviceLibrary\led\LEDColorArtNet.cs" />
<Compile Include="DeviceLibrary\led\LEDColorModule.cs" /> <Compile Include="DeviceLibrary\led\LEDColorModule.cs" />
<Compile Include="DeviceLibrary\led\LEDSingleModule.cs" /> <Compile Include="DeviceLibrary\led\LEDSingleModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
......
...@@ -183,7 +183,13 @@ namespace SmartShelf.DeviceLibrary ...@@ -183,7 +183,13 @@ namespace SmartShelf.DeviceLibrary
{ {
LEDColorModule module = new LEDColorModule(ip); LEDColorModule module = new LEDColorModule(ip);
return module; return module;
}else }
else if (LEDManager.DeviceLedType.Equals(2))
{
LEDColorArtNet module = new LEDColorArtNet(ip);
return module;
}
else
{ {
LEDSingleModule module = new LEDSingleModule(ip); LEDSingleModule module = new LEDSingleModule(ip);
return module; return module;
...@@ -243,7 +249,7 @@ namespace SmartShelf.DeviceLibrary ...@@ -243,7 +249,7 @@ namespace SmartShelf.DeviceLibrary
{ {
public static Light DefaultLight(int dmxId, int index) public static Light DefaultLight(int dmxId, int index)
{ {
return new Light(dmxId, index, 50, 0, 0,200); return new Light(dmxId, index, 0, 50, 0,200);
} }
public static Light GetLight(int dmxId,int index, string color="green") public static Light GetLight(int dmxId,int index, string color="green")
{ {
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace SmartShelf.DeviceLibrary
{
/// <summary>
/// 三色灯,RGB,红蓝绿
/// </summary>
public class LEDColorArtNet : LEDBaseModule
{
private const ushort MAX_RGBDMX_UNI = 8;//定义8个RGB灯的DMX域缓存
//每个DMX域的灯数量
private const int LIGHT_COUNT_PER_DMX = 170;
//byte[][] dmxData = new byte[MAX_RGBDMX_UNI][];
private List<byte[]> dmxDatas = new List<byte[]>(MAX_RGBDMX_UNI);
internal LEDColorArtNet(string ip) : base(ip)
{
iep = new IPEndPoint(IPAddress.Parse(ip), 6454);
AllLightOff();
}
private void InitDatas()
{
dmxDatas = new List<byte[]>(MAX_RGBDMX_UNI);
for (int i = 0; i < MAX_RGBDMX_UNI; i++)
{
dmxDatas.Add(new byte[1024]);
}
}
public override void AllLightOff(int dmx = -1)
{
InitDatas();
PushToDevice();
}
public override void AllLightOn(int dmx = -1)
{
AllLightOn(Light.DefaultLight(dmx, 1));
}
public override void AllLightOn(Light light)
{
for (int i = 0; i < MAX_RGBDMX_UNI; i++)
{
byte[] data = dmxDatas[i];
for (int lightIndex = 0; lightIndex < LIGHT_COUNT_PER_DMX; lightIndex++)
{
data[lightIndex * 3] = light.Red;
data[lightIndex * 3 + 1] = light.Blue;
data[lightIndex * 3 + 2] = light.Green;
//dmxDatas[i] = data;
}
}
PushToDevice();
}
/// <summary>
/// 只有某些灯亮,其他灯灭掉
/// </summary>
/// <param name="lights"></param>
public override void OnlyLightOn(params Light[] lights)
{
AllLightOff();
LightOn(lights);
}
/// <summary>
/// 在之前的状态之上点亮某些灯
/// </summary>
/// <param name="lights"></param>
public override void LightOn(params Light[] lights)
{
foreach (Light light in lights)
{
int dmxIndex = light.index / LIGHT_COUNT_PER_DMX;
int lightIndex = light.index % LIGHT_COUNT_PER_DMX;
byte[] data = dmxDatas[dmxIndex];
//SPI第二通道为蓝色,DMX第二通道为绿色
data[lightIndex * 3] = light.Red;
data[lightIndex * 3 + 1] = light.Blue;
data[lightIndex * 3 + 2] = light.Green;
//data[lightIndex * 3] = 255;
//data[lightIndex * 3 + 1] = 255;
//data[lightIndex * 3 + 2] = 255;
}
PushToDevice();
}
public override void LightOff(int dmx, params int[] lightIndexs)
{
foreach (int lightId in lightIndexs)
{
int dmxIndex = lightId / LIGHT_COUNT_PER_DMX;
int lightIndex = lightId % LIGHT_COUNT_PER_DMX;
byte[] data = dmxDatas[dmxIndex];
//SPI第二通道为蓝色,DMX第二通道为绿色
data[lightIndex * 3] = 0;
data[lightIndex * 3 + 1] = 0;
data[lightIndex * 3 + 2] = 0;
}
PushToDevice();
}
public override void LightOff(params Light[] lights)
{
foreach (Light light in lights)
{
int lightId = light.index;
int dmxIndex = lightId / LIGHT_COUNT_PER_DMX;
int lightIndex = lightId % LIGHT_COUNT_PER_DMX;
byte[] data = dmxDatas[dmxIndex];
//SPI第二通道为蓝色,DMX第二通道为绿色
data[lightIndex * 3] = 0;
data[lightIndex * 3 + 1] = 0;
data[lightIndex * 3 + 2] = 0;
}
PushToDevice();
}
private void PushToDevice()
{
//闲置的时候会有不起作用的情况,这里多发几遍
for (int time = 0; time < 2; time++)
{
UdpClient myUdpClient = new UdpClient();
try
{
for (int i = 0; i < dmxDatas.Count; i++)
{
byte[] toSend = ToSPIData(i, dmxDatas[i]);
myUdpClient.Send(toSend, toSend.Length, iep);
break;
}
}
catch (Exception err)
{
Console.WriteLine("发送失败");
}
finally
{
myUdpClient.Close();
}
}
}
/// <summary>
/// 46:51:35:31:32:4e:65:74: 数据包头[16]
//0b:00: OpCode
//40:
//06: 序列号
//00:
//01: 更新标准:0=写到缓存,未输出到dmxData;1=无缓存,立即输出到dmxData
//03: 0=没有广播,只控制指定域;1=对设备的所有端口广播;2=对某个子网内的所有域广播;3,对网络下的所有子网广播;0xff=对所有网络设备的所有口广播
//34: 字节的高4位为子网,字节的低4位为dmxData域,;子网:0~15,DMX域:0~15;
//02: IP灯光网络地址:0~127
//02:00: 通道数512
//00:00:00: 第0个灯RBG
//00:00:00: 第1个灯RBG
//...: 第n个灯RBG
/// </summary>
/// <returns></returns>
private byte[] ToSPIData(int dmxIndex, byte[] dmxData)
{
string ID = "41:72:74:2D:4E:65:74:00:";// 8字节数据包头: "FQ512Net"
//string head = "46:51:35:31:32:4e:65:74:";// 8字节数据包头: "FQ512Net"
string OpCode = "00:50:"; //指令2字节
string ProVer = "000e";
string seq = "00";
string phy = "00";
string SubUni = "00";//更新标准:0=写到缓存,未输出到dmxData;1=无缓存,立即输出到dmxData
string Net = "00";
string length = "0200";
//string Broadcast = "0";//0=没有广播,只控制指定域;1=对设备的所有端口广播;2=对某个子网内的所有域广播;3,对网络下的所有子网广播;0xff=对所有网络设备的所有口广播
//string SubUni = "00";// IP灯光子网地址:0~255;子网又可分,字节的高4位为子网,字节的低4位为dmxData域,;子网:0~15,DMX域:0~15;
//string net = "" + dmxIndex + "00"; //IP灯光网络地址:0~127
string preStr = ID + OpCode + ProVer + seq + phy + SubUni + Net + length;
// preStr = "4172742d4e657400:0050:";
byte[] preBytes = StringToByte(preStr);
byte[] toSend = new byte[preBytes.Length + dmxData.Length];
Array.Copy(preBytes, 0, toSend, 0, preBytes.Length);
Array.Copy(dmxData, 0, toSend, preBytes.Length, dmxData.Length);
return toSend;
}
//41 72 74 2D 4E 65 74 00 00 20 00 0E 00 00
// Artnet 地址
//Artnet 协议中,设备的设置一般为 X:Y,其中 X 为 subnet, Y 为 universe,均为 16
//进制,共可以容纳 256 个 Universe。此时对应的控台端,当设置对应的 Universe
//的时候应注意 16 进制到 10 进制的转换。比如 Artnet 协议设备端(Arkaos)设
//置为 2:1,则控台端应设备为 16*2+1 = 33.
//控台的 IP 地址应设置为:2.B.C.D ,其中 BCD 为 0-255
//41 72 74 2D 4E 65 74 00 00 50 00 0E 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
}
}
...@@ -56,8 +56,8 @@ namespace SmartShelf.DeviceLibrary ...@@ -56,8 +56,8 @@ namespace SmartShelf.DeviceLibrary
for (int lightIndex = 0; lightIndex < LIGHT_COUNT_PER_DMX; lightIndex++) for (int lightIndex = 0; lightIndex < LIGHT_COUNT_PER_DMX; lightIndex++)
{ {
data[lightIndex * 3] = light.Red; data[lightIndex * 3] = light.Red;
data[lightIndex * 3 + 1] = light.Blue; data[lightIndex * 3 + 1] = light.Green;
data[lightIndex * 3 + 2] = light.Green; data[lightIndex * 3 + 2] = light.Blue;
//dmxDatas[i] = data; //dmxDatas[i] = data;
} }
} }
...@@ -87,8 +87,8 @@ namespace SmartShelf.DeviceLibrary ...@@ -87,8 +87,8 @@ namespace SmartShelf.DeviceLibrary
byte[] data = dmxDatas[dmxIndex]; byte[] data = dmxDatas[dmxIndex];
//SPI第二通道为蓝色,DMX第二通道为绿色 //SPI第二通道为蓝色,DMX第二通道为绿色
data[lightIndex * 3] = light.Green; data[lightIndex * 3] = light.Red;
data[lightIndex * 3 + 1] = light.Red; data[lightIndex * 3 + 1] = light.Green;
data[lightIndex * 3 + 2] = light.Blue; data[lightIndex * 3 + 2] = light.Blue;
} }
PushToDevice(); PushToDevice();
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!