Commit f0dd7bd2 LN

art-net修改

1 个父辈 9f260e79
......@@ -174,7 +174,6 @@ namespace SmartShelf.DeviceLibrary
public abstract class LEDBaseModule
{
//DMX端口为6454, SPI端口为6858
protected IPEndPoint iep = null;
public string ModuleIP = "";
public static LEDBaseModule GetModule(string ip)
......@@ -199,8 +198,8 @@ namespace SmartShelf.DeviceLibrary
internal LEDBaseModule(string ip)
{
ModuleIP = ip;
iep = new IPEndPoint(IPAddress.Parse(ip), 6858);
AllLightOff();
// iep = new IPEndPoint(IPAddress.Parse(ip), 6858);
// AllLightOff();
}
......
using System;
using SmartShelf.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
......@@ -16,27 +17,51 @@ namespace SmartShelf.DeviceLibrary
public class LEDColorArtNet : LEDBaseModule
{
private const ushort MAX_RGBDMX_UNI = 8;//定义8个RGB灯的DMX域缓存
private const ushort Max_DMX = 16;//定义8个RGB灯的DMX域缓存
//每个DMX域的灯数量
private const int LIGHT_COUNT_PER_DMX = 170;
private int Max_Light = 170;
private int datalength = 512;
//byte[][] dmxData = new byte[MAX_RGBDMX_UNI][];
private List<byte[]> dmxDatas = new List<byte[]>(MAX_RGBDMX_UNI);
private List<byte[]> dmxDatas = new List<byte[]>(Max_DMX);
internal LEDColorArtNet(string ip) : base(ip)
{
datalength = 512;
Max_Light = datalength / 3;
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 = new List<byte[]>(Max_DMX);
for (int i = 0; i < Max_DMX; i++)
{
dmxDatas.Add(new byte[datalength]);
}
}
private void UpdateLightData(int dmx,int index,byte red=0, byte green =0, byte blue =0)
{
int ldmx = dmx;
int lIndex = index;
if (index >= Max_Light)
{
dmxDatas.Add(new byte[1024]);
ldmx = index / Max_Light;
lIndex = index % Max_Light;
}
if (ldmx >= dmxDatas.Count)
{
LogUtil.error(" UpdateLightData error: dmx [" + ldmx + "] MAX_UNI[" + Max_DMX + "]");
return ;
}
byte[] data = dmxDatas[ldmx];
//SPI第二通道为蓝色,DMX第二通道为绿色
data[lIndex * 3] = red ;
data[lIndex * 3 + 1] = green ;
data[lIndex * 3 + 2] = blue ;
}
public override void AllLightOff(int dmx = -1)
{
InitDatas();
......@@ -50,15 +75,12 @@ namespace SmartShelf.DeviceLibrary
public override void AllLightOn(Light light)
{
for (int i = 0; i < MAX_RGBDMX_UNI; i++)
for (int i = 0; i < Max_DMX; i++)
{
byte[] data = dmxDatas[i];
for (int lightIndex = 0; lightIndex < LIGHT_COUNT_PER_DMX; lightIndex++)
for (int index = 0; index < Max_Light; index++)
{
data[lightIndex * 3] = light.Red;
data[lightIndex * 3 + 1] = light.Blue;
data[lightIndex * 3 + 2] = light.Green;
//dmxDatas[i] = data;
UpdateLightData(i, index, light.Red, light.Green, light.Blue);
}
}
PushToDevice();
......@@ -82,17 +104,8 @@ namespace SmartShelf.DeviceLibrary
{
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];
UpdateLightData(light.dmx, light.index, light.Red, light.Green, light.Blue);
//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();
}
......@@ -101,14 +114,8 @@ namespace SmartShelf.DeviceLibrary
{
foreach (int lightId in lightIndexs)
{
int dmxIndex = lightId / LIGHT_COUNT_PER_DMX;
int lightIndex = lightId % LIGHT_COUNT_PER_DMX;
byte[] data = dmxDatas[dmxIndex];
UpdateLightData(dmx, lightId, 0, 0, 0);
//SPI第二通道为蓝色,DMX第二通道为绿色
data[lightIndex * 3] = 0;
data[lightIndex * 3 + 1] = 0;
data[lightIndex * 3 + 2] = 0;
}
PushToDevice();
......@@ -117,15 +124,8 @@ namespace SmartShelf.DeviceLibrary
{
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];
UpdateLightData(light.dmx, light.index, 0, 0, 0);
//SPI第二通道为蓝色,DMX第二通道为绿色
data[lightIndex * 3] = 0;
data[lightIndex * 3 + 1] = 0;
data[lightIndex * 3 + 2] = 0;
}
PushToDevice();
......@@ -144,7 +144,6 @@ namespace SmartShelf.DeviceLibrary
{
byte[] toSend = ToSPIData(i, dmxDatas[i]);
myUdpClient.Send(toSend, toSend.Length, iep);
break;
}
}
catch (Exception err)
......@@ -185,9 +184,14 @@ namespace SmartShelf.DeviceLibrary
string ProVer = "000e";
string seq = "00";
string phy = "00";
string SubUni = "00";//更新标准:0=写到缓存,未输出到dmxData;1=无缓存,立即输出到dmxData
string SubUni = "00";
SubUni= String.Format("{0:X}", dmxIndex).PadLeft(2, '0');
string Net = "00";
int len = dmxData.Length;
string str = String.Format("{0:X}", dmxData.Length).PadLeft(4,'0');
string length = "0200";
length = str;
//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
......
......@@ -12,8 +12,8 @@
<!--服务器地址-->
<add key="http.server" value="http://192.168.200.22:8080/" />
<!--料架灯类型,0=单色灯料架,1=三色灯料架-->
<add key="DeviceLedType" value="1" />
<!--料架灯类型,0=单色灯料架,1=三色灯料架,2=art-net-->
<add key="DeviceLedType" value="2" />
<!--一下为一个料仓的默认配置 开始-->
<add key="Store_Position_Config" value="\Config\GW\linePositions.csv"/>
<add key="Store_ConfigPath" value="\Config\StoreConfig.csv" />
......
......@@ -32,6 +32,7 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmSMStore));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button5 = new System.Windows.Forms.Button();
this.btnCloseSLed = new System.Windows.Forms.Button();
this.btnOpenSLed = new System.Windows.Forms.Button();
this.cmbNum = new System.Windows.Forms.ComboBox();
......@@ -57,10 +58,13 @@
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.panel1 = new System.Windows.Forms.Panel();
this.lblLedInfo = new System.Windows.Forms.Label();
this.button5 = new System.Windows.Forms.Button();
this.numYu = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numYu)).BeginInit();
this.SuspendLayout();
//
// timer1
......@@ -73,6 +77,9 @@
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.numYu);
this.groupBox2.Controls.Add(this.button5);
this.groupBox2.Controls.Add(this.btnCloseSLed);
this.groupBox2.Controls.Add(this.btnOpenSLed);
......@@ -102,6 +109,17 @@
this.groupBox2.TabStop = false;
this.groupBox2.Text = "门锁操作测试";
//
// button5
//
this.button5.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button5.Location = new System.Drawing.Point(106, 421);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(95, 35);
this.button5.TabIndex = 112;
this.button5.Text = "亮黄灯";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// btnCloseSLed
//
this.btnCloseSLed.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
......@@ -167,7 +185,7 @@
// btnCloseLed
//
this.btnCloseLed.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCloseLed.Location = new System.Drawing.Point(155, 369);
this.btnCloseLed.Location = new System.Drawing.Point(170, 366);
this.btnCloseLed.Name = "btnCloseLed";
this.btnCloseLed.Size = new System.Drawing.Size(115, 35);
this.btnCloseLed.TabIndex = 36;
......@@ -178,16 +196,16 @@
// txtLedIndex
//
this.txtLedIndex.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtLedIndex.Location = new System.Drawing.Point(34, 337);
this.txtLedIndex.Location = new System.Drawing.Point(75, 370);
this.txtLedIndex.Name = "txtLedIndex";
this.txtLedIndex.Size = new System.Drawing.Size(115, 26);
this.txtLedIndex.Size = new System.Drawing.Size(89, 26);
this.txtLedIndex.TabIndex = 35;
this.txtLedIndex.Text = "0";
//
// button4
//
this.button4.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button4.Location = new System.Drawing.Point(155, 328);
this.button4.Location = new System.Drawing.Point(170, 327);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(115, 35);
this.button4.TabIndex = 34;
......@@ -364,16 +382,37 @@
this.lblLedInfo.TabIndex = 0;
this.lblLedInfo.Text = "label3";
//
// button5
//
this.button5.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button5.Location = new System.Drawing.Point(106, 421);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(95, 35);
this.button5.TabIndex = 112;
this.button5.Text = "亮黄灯";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
// numYu
//
this.numYu.Location = new System.Drawing.Point(75, 333);
this.numYu.Maximum = new decimal(new int[] {
15,
0,
0,
0});
this.numYu.Name = "numYu";
this.numYu.Size = new System.Drawing.Size(89, 23);
this.numYu.TabIndex = 113;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 336);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(57, 17);
this.label3.TabIndex = 115;
this.label3.Text = "区域ID:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 375);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 17);
this.label4.TabIndex = 114;
this.label4.Text = "灯地址:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// FrmSMStore
//
......@@ -397,6 +436,7 @@
this.groupBox1.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numYu)).EndInit();
this.ResumeLayout(false);
}
......@@ -430,5 +470,8 @@
private System.Windows.Forms.Button btnCloseSLed;
private System.Windows.Forms.Button btnOpenSLed;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.NumericUpDown numYu;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
}
}
\ No newline at end of file
......@@ -181,7 +181,7 @@ namespace SmartShelf
{
string ip = txtAddr.Text;
int index = FormUtil.GetIntValue(txtLedIndex);
int dmxId = FormUtil.GetIntValue(txtDmxId);
int dmxId =(int) numYu.Value;
LEDManager.GetLedModule(ip).LightOn(Light.DefaultLight(dmxId, index));
}
......@@ -189,7 +189,7 @@ namespace SmartShelf
{
string ip = txtAddr.Text;
int index = FormUtil.GetIntValue(txtLedIndex);
int dmxId = FormUtil.GetIntValue(txtDmxId);
int dmxId = (int)numYu.Value;
LEDManager.GetLedModule(ip).LightOff( dmxId, index);
}
public int preIndex = 0;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!