コード例 #1
0
        public (bool rtn, string msg) Open(ePWR_PortName Port, int[] addrAry, int enb4Bit)
        {
            try
            {
                int   idx      = 0;
                Any64 EnbItems = new Any64();
                EnbItems.INT32_0 = enb4Bit;
                foreach (var addr in addrAry)
                {
                    var item = _dicItems[(ePWRREAD_ITEMS)idx];
                    item.bEnb = EnbItems[idx];
                    item.add  = addr;
                    idx++;
                }
                modbusClnt = new ModbusClient();
                modbusClnt.ConnectedChanged += new EasyModbus.ModbusClient.ConnectedChangedHandler(On_Connected);
                modbusClnt.SerialPort        = Port.ToString();
                modbusClnt.Baudrate          = 38400;
                switch (type)
                {
                case ePWRTYPE.ElgenBattery:
                    modbusClnt.ReceiveDataChanged += new ModbusClient.ReceiveDataChangedHandler(On_ReceiveData);
                    modbusClnt.SendDataChanged    += new ModbusClient.SendDataChangedHandler(On_SendData);
                    modbusClnt.Baudrate            = 9600;
                    modbusClnt.StopBits            = System.IO.Ports.StopBits.One;
                    break;

                case ePWRTYPE.ElgenCharger:
                    modbusClnt.StopBits = System.IO.Ports.StopBits.One;
                    break;

                case ePWRTYPE.AutonicMeter:
                    modbusClnt.Baudrate = 9600;
                    modbusClnt.StopBits = System.IO.Ports.StopBits.Two;
                    break;

                default: return(false, $"Wrong {type} setting!!!!");
                }
                modbusClnt.Parity            = System.IO.Ports.Parity.None;
                modbusClnt.ConnectionTimeout = 500;
                if (!modbusClnt.Connected)
                {
                    modbusClnt.Connect();
                }
                return(true, null);
            }
            catch (Exception e)
            {
                return(false, e.ToString());
            }
        }
コード例 #2
0
 public bool Open(ePWR_PortName port)
 {
     try
     {
         serialPort.PortName = port.ToString();
         serialPort.Open();
         _StateChk.Start();
         Evt_Connection?.Invoke(this, serialPort.IsOpen);
         return(serialPort.IsOpen);
     }
     catch (Exception e)
     {
         ReportLog(e.ToString(), false);
         return(false);
     }
 }
コード例 #3
0
        public bool Open(ePWR_PortName port) // 에러는 보호상태
        {
            bool rtn = false;

            if (false == bUseModbus)
            {
                _PwrCom.PortName = port.ToString();
                _PwrCom.Open();
                rtn = _PwrCom.IsOpen;
            }
            else
            {
                // 모드버스 Data 주소 Curr Volt 온도1 온도2  온도3  보호상태(Error) 사용안함 버젼 == ePWRREAD_ITEMS
                var ary = new int[8] {
                    86, 73, -1, -1, -1, -1, -1, 1
                };
                var bit = new Any64();
                bit[(int)ePWRREAD_ITEMS.Current]  = true;
                bit[(int)ePWRREAD_ITEMS.Voltage]  = true;
                bit[(int)ePWRREAD_ITEMS.Error]    = false;
                bit[(int)ePWRREAD_ITEMS.Ver]      = false;
                bit[(int)ePWRREAD_ITEMS.Temp_1st] = false;
                bit[(int)ePWRREAD_ITEMS.Temp_2nd] = false;
                bit[(int)ePWRREAD_ITEMS.Temp_3th] = false;
                bit[(int)ePWRREAD_ITEMS.State]    = false;

                var chk = _PwrBus.Open(port, ary, bit.INT32_0);
                if (null != chk.msg)
                {
                    ReportLog(chk.msg);
                }
                rtn = chk.rtn;
            }
            _StateChk.Start();
            Evt_Connection?.Invoke(this, rtn);
            return(rtn);
        }