Beispiel #1
0
        private SerialCOMManager()
        {
            SerialCOMListRepository   serialCOMListRepository   = new SerialCOMListRepository();
            List <SerialCOMList>      serialCOMList             = serialCOMListRepository.GetList();
            TurnTableListRepository   turnTableListRepository   = new TurnTableListRepository();
            List <Guid?>              turnTableSerialComIDs     = turnTableListRepository.GetListWithCondition(new { CommunicationType = 1 }).Select(_ => _.CommunicationID).ToList();
            UPSListRepository         UPSListRepository         = new UPSListRepository();
            List <Guid?>              UPSSerialComIDs           = UPSListRepository.GetListWithCondition(new { CommunicationType = 1 }).Select(_ => _.CommunicationID).ToList();
            SolarEnergyListRepository solarEnergyListRepository = new SolarEnergyListRepository();
            List <Guid?>              solarEnergySerialComIDs   = solarEnergyListRepository.GetListWithCondition(new { CommunicationType = 1 }).Select(_ => _.CommunicationID).ToList();

            string falseMsg = string.Empty;

            foreach (var item in serialCOMList)
            {
                try
                {
                    SerialPort serialPort = new SerialPort();
                    serialPort.PortName = item.COMNo;   //COM口名
                    serialPort.BaudRate = item.Baud;    //波特率
                    serialPort.DataBits = item.DataBit; //每个字节的标准数据位长度
                    serialPort.Parity   = (Parity)item.CheckBit;
                    serialPort.StopBits = StopBits.One;
                    if (turnTableSerialComIDs.Contains(item.DeviceID))
                    {
                        serialPort.DataReceived += TurntableSerialPortDataReceived;
                    }
                    else if (UPSSerialComIDs.Contains(item.DeviceID))
                    {
                        serialPort.DataReceived += UPSSerialPortDataReceived;
                    }
                    else if (solarEnergySerialComIDs.Contains(item.DeviceID))
                    {
                        serialPort.DataReceived += SolarEnergySerialPortDataReceived;
                    }
                    SerialPortDic[item.DeviceID] = serialPort;
                    if (!OpenSerialCOM(item.DeviceID, out falseMsg))
                    {
                        throw new Exception(falseMsg);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(falseMsg);
                    LogServerManager.AddErrLog(ErrLogType.DBErr, ex);
                    continue;
                }
            }
        }
Beispiel #2
0
        public void InsertTest()
        {
            //UserPermissionList newUserPermission = new UserPermissionList();
            //UserPermissionListRepository repository = new UserPermissionListRepository();
            //newUserPermission.UserPermissionID = repository.GetGuid();
            //wancheng Guid g = repository.Insert(newUserPermission);
            //SerialCOMListRepository repo = new SerialCOMListRepository();
            //SerialCOMList deviceList = new SerialCOMList();
            //deviceList.DeviceID = repo.GetGuid();
            //deviceList.COMNo = "COM3";
            //repo.Insert(deviceList);
            //for (int i = 0; i < 8; i++)
            //{
            //    deviceList.DeviceID = repo.GetGuid();
            //    deviceList.VideoIP = "192.168.10.14";
            //    Guid result = repo.Insert(deviceList);
            //}
            //using (FileStream fs = new FileStream("Image\\Turntable.png", FileMode.Open, FileAccess.Read))
            //{
            //    byte[] buffer = new byte[1024];
            //    int count = fs.Read(buffer, 0, buffer.Length);
            //    deviceList.Image1 = buffer;
            //}

            //RunLogRepository repo = new RunLogRepository();
            //for (int i = 0; i < 105; i++)
            //{
            //    RunLog log = new RunLog();
            //    log.OperationTime = DateTime.Now.ToString();
            //    log.OperationType = 1;
            //    log.Operator = "ly";
            //    log.OperationContent = "登录";
            //    repo.Insert(log);
            //    Thread.Sleep(100);
            //}

            //AlarmLogRepository repo = new AlarmLogRepository();
            //for (int i = 0; i < 105; i++)
            //{
            //    AlarmLog log = new AlarmLog();
            //    log.AlarmTime = DateTime.Now.ToString();
            //    log.AlarmDeviceID = new Guid();
            //    log.Operator = "无";
            //    log.AlarmID = new Guid();
            //    log.AlarmLevel = 1;
            //    log.AlarmName = "测试报警" + i;
            //    log.AlarmStatus = 1;
            //    log.AlarmType = 1;
            //    log.Alt = i;
            //    log.Lat = i;
            //    log.Lon = i;
            //    repo.Insert(log);
            //    Thread.Sleep(100);
            //}

            //ErrLogRepository repo = new ErrLogRepository();
            //for (int i = 0; i < 105; i++)
            //{
            //    try
            //    {
            //        throw new Exception("TestException" + i);
            //    }
            //    catch(Exception ex)
            //    {
            //        LogServerManager.AddErrLog(LogServerManager.ErrLogType.InnerErr, ex);
            //    }
            //    Thread.Sleep(100);
            //}

            //StationListRepository repo = new StationListRepository();
            //StationList station = new StationList();
            //station.PStationID = Guid.Parse("e2061d09-111e-413b-8ab5-6b71d4c38b3d");
            //station.Name = "监控站2";
            //station.Lon = 104.317792;
            //station.Lat = 30.541620;
            //station.TypeID = 9;
            //repo.Insert(station);

            //for (int i = 0; i < 16; i++)
            //{
            //    TurnTableListRepository repo = new TurnTableListRepository();
            //    TurnTableList TurnTableList = new TurnTableList();
            //    TurnTableList.StationID = Guid.Parse("e2061d09-111e-413b-8ab5-6b71d4c38b3d");
            //    TurnTableList.Name = "转台";
            //    TurnTableList.TypeID = 7;
            //    repo.Insert(TurnTableList);
            //}

            //for (int i = 0; i < 12; i++)
            //{
            //    StreamMediaListRepository repo = new StreamMediaListRepository();
            //    StreamMediaList streamMediaList = new StreamMediaList();
            //    //streamMediaList.VideoIP = "192.168.10.1" + i;
            //    streamMediaList.Name = "监控站1-转台1-白光";
            //    streamMediaList.TypeID = 1;
            //    repo.Insert(streamMediaList);
            //}

            //for (int i = 1; i <= 12; i++)
            //{
            //    CameraListRepository repo = new CameraListRepository();
            //    CameraList CameraList = new CameraList();
            //    CameraList.VideoName = "监控站-转台-白光";
            //    CameraList.VideoChannel = 1;
            //    CameraList.VideoType = "101";
            //    CameraList.TypeID = 4;
            //    repo.Insert(CameraList);
            //}

            //for (int i = 0; i < 3; i++)
            //{
            //    UPSListRepository repo = new UPSListRepository();
            //    UPSList upslist = new UPSList();
            //    upslist.Name = "UPS";
            //    upslist.TypeID = 8;
            //    repo.Insert(upslist);
            //}

            for (int i = 0; i < 3; i++)
            {
                SolarEnergyListRepository repo            = new SolarEnergyListRepository();
                SolarEnergyList           SolarEnergyList = new SolarEnergyList();
                SolarEnergyList.Name   = "太阳能";
                SolarEnergyList.TypeID = 6;
                repo.Insert(SolarEnergyList);
            }
        }