ldj/WcfService2/Service1.svc.cs

105 lines
3.0 KiB
C#
Raw Normal View History

2023-05-23 16:13:17 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using DeiNiu.Utils;
namespace WcfService2
{
// 注意: 使用“重构”菜单上的“重命名”命令可以同时更改代码、svc 和配置文件中的类名“Service1”。
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public bool lightTables(int led_color, int port,
string[] ele_lab_id, string[] ele_address, string[] Out_count )
{
elelab.pick.init_port(enumLabelPickType.pick);
Util.WAVE_CURRENT_PICK_STATUS.Clear();
Util.WAVE_CURRENT_LIGHTS_STATUS.Clear();
port = 10;
ele_lab_id = new string[3];
ele_address = new string[3];
Out_count = new string[3];
for (int i = 1; i < 4; i++)
{
ele_lab_id[i - 1] = i + "";
ele_address[i - 1] = i + "";
Out_count[i - 1] = i + "";
}
for (int i = 1; i < 4; i++)
{
led_color = i;
elelab.pick.make_data(null, get_byte(led_color + ""), get_byte(led_color + ""), get_byte(port + ""), ele_lab_id, ele_address, Out_count, 0);
}
return true;
}
byte get_byte(string data)
{
int length = data.Length;
List<string> str = new List<string>();
for (int i = 0; i < length; i++)
{
string result = data.Substring(i, 1);
char aaaq = Convert.ToChar(result);
if ((aaaq >= 0x30) && (aaaq <= 0x39))
{
str.Add(data.Substring(i, 1));
}
}
if (str.Count == 1)
{
return Convert.ToByte(str[0]);
}
else if (str.Count == 2)
{
int len = Convert.ToInt16(str[0]);
int len1 = Convert.ToInt16(str[1]);
len = len * 10 + len1;
return Convert.ToByte(len);
}
else if (str.Count == 3)
{
int len = Convert.ToInt16(str[0]);
int len1 = Convert.ToInt16(str[1]);
int len2 = Convert.ToInt16(str[2]);
len = len * 100 + len1 * 10 + len2;
return Convert.ToByte(len);
}
return 0;
}
}
}