VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之.实现设备(驱动)与设备(驱动)交互(3)

    3.金三接收到普京的返回信息后,把矛头指向了奥黑。代码如下:

1
2
3
4
5
6
public override void DeviceConnectorCallback(object obj)
        {
            Console.WriteLine(obj.ToString());//输出返回结果
            Console.WriteLine(this.DeviceParameter.DeviceName+ "说:奥黑也真够坑爹的!");
            Console.WriteLine(">>>>模拟控制命令结束");
        }

     注:这里并没有用到DeviceConnectorCallbackError执行异常返回接口函数。

11.5     宿主程序服务实例配置注意事项

       这是用自控模式实现的,设备驱动并没有主动发送数据。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
static void Main(string[] args)
        {
            DeviceSelfDriver dev1 = new DeviceSelfDriver();
            dev1.DeviceParameter.DeviceName = "金三";
            dev1.DeviceParameter.DeviceAddr = 0;
            dev1.DeviceParameter.DeviceID = "0";
            dev1.DeviceDynamic.DeviceID = "0";
            dev1.DeviceParameter.DeviceCode = "0";
            dev1.DeviceParameter.COM.Port = 1;
            dev1.DeviceParameter.COM.Baud = 9600;
            dev1.DeviceParameter.NET.RemoteIP = "127.0.0.1";
            dev1.DeviceParameter.NET.RemotePort = 9600;
            dev1.CommunicateType = CommunicateType.NET;
            dev1.Initialize("0");
 
            DeviceSelfDriver dev2 = new DeviceSelfDriver();
            dev2.DeviceParameter.DeviceName = "普京";
            dev2.DeviceParameter.DeviceAddr = 1;
            dev2.DeviceParameter.DeviceID = "1";
            dev2.DeviceDynamic.DeviceID = "1";
            dev2.DeviceParameter.DeviceCode = "1";
            dev2.DeviceParameter.NET.RemoteIP = "127.0.0.1";
            dev2.DeviceParameter.NET.RemotePort = 9600;
            dev2.CommunicateType = CommunicateType.NET;
            dev2.Initialize("1");
 
            IServer server = new ServerManager().CreateServer(new ServerConfig()
            {
                ServerName = "服务1",
                ComReadTimeout = 1000,
                ComWriteTimeout = 1000,
                NetReceiveTimeout = 1000,
                NetSendTimeout = 1000,
                ControlMode = ControlMode.Self,
                SocketMode = SocketMode.Tcp,
                StartReceiveDataFliter = true,
                ClearSocketSession = false,
                StartCheckPackageLength = true,
                CheckSameSocketSession = false,
                DeliveryMode = DeliveryMode.DeviceCode,
            });
 
            server.AddDeviceCompleted += server_AddDeviceCompleted;
            server.DeleteDeviceCompleted+=server_DeleteDeviceCompleted;
            server.Start();
 
            server.AddDevice(dev1);
            server.AddDevice(dev2);
 
            while ("exit" == Console.ReadLine())
            {
                server.Stop();
            }
        }

相关教程