Пример #1
0
 public int close(DeviceHandle handle)
 {
     if (handle == null)
     {
         _log.Warn("Called with null handle");
         return 0;
     }
     if (handle.isInvalid())
     {
         _log.Warn("Called with INVALID handle");
         return 0;
     }
     try
     {
         handle.TOOLSTICKhnd.hnd.Close();
         handle.setInvalid();
         return 0;
     }
     catch (Exception exception)
     {
         _log.Error(exception.Message);
         handle.setInvalid();
         return -1;
     }
 }
Пример #2
0
 public int close(DeviceHandle handle)
 {
     if (handle == null)
     {
         _log.Warn("Called with null handle");
         return 0;
     }
     if (handle.isInvalid())
     {
         _log.Warn("Called with INVALID handle");
         return 0;
     }
     try
     {
         Thread.Sleep(200);
         if (handle.RS232hnd.hnd.IsOpen)
         {
             handle.RS232hnd.hnd.Close();
         }
         _log.Debug(handle.RS232hnd.hnd.PortName + " has been closed.");
         handle.setInvalid();
         return 0;
     }
     catch (Exception exception)
     {
         _log.Error("Close() - " + exception.Message);
         handle.setInvalid();
         return -1;
     }
 }
Пример #3
0
 public AppWin_FTDITest()
 {
     this.InitializeComponent();
     this._appId = GlobalServices.uniqApplicationId(WDSApplicationType.FTDITest);
     this.Text = this._appId + ":   " + this.Text;
     this._readBuffer = new byte[0x1000];
     this._writeBuffer = new byte[0x100];
     this._devHandle1 = new DeviceHandle();
 }
Пример #4
0
 public int flushRead(DeviceHandle handle, DataBuffer data)
 {
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_TEST.flushRead()", "called with INVALID handle");
         return -1;
     }
     data.copy(handle.TestDevHnd.readBuff);
     handle.TestDevHnd.readBuff.NumItems = 0;
     handle.TestDevHnd.readBuffIdx = 0;
     return data.NumItems;
 }
Пример #5
0
 public int close(DeviceHandle handle)
 {
     if (handle != null)
     {
         if (handle.devType == PortType.SIMULATION)
         {
             return 0;
         }
         GlobalServices.ErrMsg("DDI_TEST.close()", "Not implemented for physical devices!");
     }
     return 0;
 }
Пример #6
0
 public int flushRead(DeviceHandle handle, DataBuffer data)
 {
     int bytesInRxQueue = 0;
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_USB.flushRead()", "called with INVALID handle");
         return -1;
     }
     if (FTDIWrapper.GetRxQueueLen(handle.USBhnd.hnd, ref bytesInRxQueue) != 0)
     {
         GlobalServices.ErrMsg("DDI_USB.flushRead()", "FTDIWrapper.GetRxQueueLen() returned:" + FTDIWrapper.GetErrorString());
         return -1;
     }
     return this.read(handle, data, bytesInRxQueue);
 }
Пример #7
0
 public bool isDeviceAlive(DeviceHandle handle)
 {
     DataBuffer data = new DataBuffer("\r".Length + "\n\rOK\n\r>".Length);
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_TEST.isDeviceAlive()", "called with INVALID handle");
         return false;
     }
     data.copy("\r");
     if (this.write(handle, data) < 0)
     {
         return false;
     }
     if (this.read(handle, data, data.Capacity) < 0)
     {
         return false;
     }
     return data.endsWith("\n\rOK\n\r>");
 }
Пример #8
0
 public int CancelIo(DeviceHandle handle)
 {
     if ((handle == null) || handle.isInvalid())
     {
         _log.Warn("Called with INVALID handle");
         return -1;
     }
     try
     {
         if (handle.HIDhnd.hnd.CancelIo() == 0)
         {
             throw new Exception("HID CancelIo failed");
         }
     }
     catch (Exception exception)
     {
         _log.Error(exception.Message);
         return -1;
     }
     return 0;
 }
Пример #9
0
 private void InitDeviceSettings(DeviceHandle handle, DeviceDescriptor a_dev)
 {
     IdentifyDevice(handle, a_dev);
 }
Пример #10
0
 private void CloseDeviceSettings(DeviceHandle handle, DeviceDescriptor a_dev)
 {
     StopIdentifyDevice(handle, a_dev);
 }
Пример #11
0
 public void StopIdentifyDevice(DeviceHandle handle, DeviceDescriptor a_dev)
 {
     DataBuffer data = new DataBuffer(128);
     int pollDeviceTypeProcDelay = int.Parse(ConfigurationManager.AppSettings["PollDeviceTypeProcDelay"]);
     if ((a_dev.DeviceType != null) && (a_dev.DeviceType.TypeID == DeviceTypeID.LoadBoard))
     {
         data.copy("d0\r");
         write(handle, data);
         Thread.Sleep(pollDeviceTypeProcDelay);
     }
 }
Пример #12
0
 public int read(DeviceHandle handle, DataBuffer data, int bytesToRead)
 {
     if (handle.isInvalid())
     {
         _log.Error("read() - Called with INVALID handle");
         return -1;
     }
     data.NumItems = 0;
     return readAppend(handle, data, bytesToRead);
 }
Пример #13
0
        private void queryEBID(DeviceHandle handle, DeviceDescriptor a_dev)
        {
            DataBuffer data = new DataBuffer(512)
            {
                DType = Data_Type.ASCII
            };
            string bufToStr = "";
            if (handle.isInvalid() || a_dev.DeviceType == null)
                _log.Error("queryEBID() - Called with INVALID argument");
            else
            {
                flushRead(handle, data);
                if (a_dev.FirmwareType != null &&
                    (a_dev.FirmwareType.Name == "LoadBoard" || a_dev.FirmwareType.Name == "LoadBoard_Lite")
                    )
                {
                    switch (a_dev.DeviceType.TypeID)
                    {
                        case DeviceTypeID.LoadBoard:
                        case DeviceTypeID.SDBC:
                            data.copy("L6\r");
                            write(handle, data);
                            return;

                        case DeviceTypeID.EZLink:
                        case DeviceTypeID.SRW002:
                        case DeviceTypeID.Unknown:
                            return;

                        case DeviceTypeID.SRW004:
                            data.copy("ged\r");
                            if (ExchCmdWithDev(handle, data) && data.BufToStr.Contains("0x40"))
                            {
                                data.copy("gwd\r");
                                if (ExchCmdWithDev(handle, data))
                                {
                                    bufToStr = data.BufToStr;
                                    try
                                    {
                                        string[] strArray = bufToStr.Split(new char[] { ' ' });
                                        int index = strArray[0].IndexOf("x");
                                        strArray[0] = strArray[0].Remove(0, index + 1);
                                        for (int i = 1; i < strArray.Length; i++)
                                            strArray[i] = strArray[i].Replace("0x", "");

                                        byte[] bytes = new byte[strArray.Length];
                                        for (int j = 0; j < (strArray.Length - 1); j++)
                                            bytes[j] = Convert.ToByte(strArray[j], 16);

                                        string str3 = Encoding.Default.GetString(bytes);
                                        if (str3.Length > 6)
                                        {
                                            switch(str3.Substring(0, 6))
                                            {
                                                case "SI1000":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1000";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1002":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1002";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1004":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1004";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1010":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1010";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1012":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1012";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1014":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1014";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                            }
                                        }
                                    }
                                    catch (FormatException exception)
                                    {
                                        _log.Error("queryEBID()" + exception.Message);
                                    }
                                }
                            }
                            return;
                    }
                }
            }
        }
Пример #14
0
 public int flushRead(DeviceHandle handle, DataBuffer data)
 {
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_EZLinkDongle.flushRead()", "called with INVALID handle");
         return -1;
     }
     data.NumItems = 0;
     return 0;
 }
Пример #15
0
 public int write(DeviceHandle handle, DataBuffer data)
 {
     string reply = "";
     byte[] buffer = new byte[15];
     if (handle != null)
     {
         if (handle.isInvalid())
         {
             GlobalServices.ErrMsg("DDI_TEST.write()", "called with INVALID handle");
             return -1;
         }
         if (data.NumItems == 0)
         {
             return 0;
         }
         if (data.DType == Data_Type.Binary)
         {
             GlobalServices.calculateExpextedReplyLen(data, ref buffer);
             handle.TestDevHnd.readBuff.copy(buffer);
         }
         else
         {
             GlobalServices.calculateExpextedReplyLen(data.objectInfo(false), ref reply);
             handle.TestDevHnd.readBuff.copy(reply);
         }
         handle.TestDevHnd.readBuffIdx = 0;
         Thread.Sleep(50);
     }
     return 0;
 }
Пример #16
0
Файл: EzDCP2.cs Проект: x893/WDS
 public EzDCP2(DeviceHandle deviceHandler)
 {
     _deviceHandler = deviceHandler;
 }
Пример #17
0
 public int flushRead(DeviceHandle handle, DataBuffer data)
 {
     int num;
     if (handle.isInvalid())
     {
         _log.Warn("Called with INVALID handle");
         return -1;
     }
     data.NumItems = 0;
     while ((num = readAppend(handle, data, 1)) == 1)
     {
     }
     if (num == -1)
     {
         _log.Warn("readAppend() returned with -1");
         return -1;
     }
     return data.NumItems;
 }
Пример #18
0
        public unsafe int read(DeviceHandle handle, DataBuffer data, int bytesToRead)
        {
            int num4;
            byte* numPtr = stackalloc byte[0x100];
            uint regData = 0;
            int num3 = -1;
            if (handle.isInvalid())
            {
                GlobalServices.ErrMsg("DDI_EZLinkDongle.read()", "called with INVALID handle");
                return -1;
            }
            switch (data.ddi_getProtocol())
            {
                case Protocol.ReadRegister:
                    uint num;
                    data.ddi_getCommand_ReadRegister(out num);
                    data.ddi_setReply_ReadRegister(num, regData);
                    return num3;

                case Protocol.ReadStatus:
                    data.NumItems = 14;
                    num4 = 0;
                    while (num4 < data.NumItems)
                    {
                        data.Buf[num4] = numPtr[num4];
                        num4++;
                    }
                    return num3;

                case Protocol.Read:
                    if (num3 == 0)
                    {
                        data.NumItems = numPtr[4];
                        for (num4 = 0; num4 < data.NumItems; num4++)
                        {
                            data.Buf[num4] = numPtr[num4 + 5];
                        }
                    }
                    return num3;
            }
            GlobalServices.ErrMsg("DDI_EZLinkDongle.read()", "Unexpected protocol received");
            return num3;
        }
Пример #19
0
 public void IdentifyDevice(DeviceHandle handle, DeviceDescriptor a_dev)
 {
     if (a_dev.DeviceType != null && a_dev.DeviceType.TypeID == DeviceTypeID.LoadBoard)
     {
         DataBuffer data = new DataBuffer(128);
         data.copy("d3\r");
         write(handle, data);
         Thread.Sleep(int.Parse(ConfigurationManager.AppSettings["PollDeviceTypeProcDelay"]));
     }
 }
Пример #20
0
 public int readAppend(DeviceHandle handle, DataBuffer data, int bytesToRead)
 {
     GlobalServices.ErrMsg("DDI_EZLinkDongle.readAppend()", "Not implemented function");
     return -1;
 }
Пример #21
0
 public int readAppend(DeviceHandle handle, DataBuffer data, int bytesToRead)
 {
     int num2;
     byte[] buffer = new byte[bytesToRead];
     int num = 0;
     int num5 = bytesToRead;
     try
     {
         if (handle == null || handle.isInvalid() || !handle.RS232hnd.hnd.IsOpen)
         {
             string portName = "unknown port";
             if (handle != null && handle.RS232hnd != null && handle.RS232hnd.hnd != null)
                 portName = handle.RS232hnd.hnd.PortName;
             _log.Error("readAppend() - " + portName + " - Port is not accessible");
             return -1;
         }
         if (data.Capacity < (data.NumItems + num5))
         {
             if (_log.IsErrorEnabled)
                 _log.Error("readAppend() - DataBuffer is too small: data.Capacity:'" + data.Capacity.ToString() + "' < data.NumItems:'" + data.NumItems.ToString() + "' + bytesToRead:'" + num5.ToString() + "'");
             return -1;
         }
     }
     catch (Exception exception)
     {
         _log.Error("readAppend() 1 - " + exception.Message);
         return -1;
     }
     int num4 = num2 = data.NumItems;
     data.NumItems += num5;
     do
     {
         try
         {
             int num7 = handle.RS232hnd.hnd.BytesToRead;
             num = handle.RS232hnd.hnd.Read(buffer, 0, (num5 < num7) ? num5 : num7);
         }
         catch (TimeoutException)
         {
         }
         catch (Exception exception2)
         {
             _log.Error("readAppend() 2 - " + exception2.Message);
             return -1;
         }
         int num3 = 0;
         num5 = 0;
         while (num3 < num)
         {
             byte num6 = buffer[num3++];
             if (data.DType == Data_Type.ASCII)
             {
                 if (num6 != 0)
                     data[num2++] = num6;
                 else
                 {
                     num5++;
                     _log.Warn("delivered a NULL byte");
                 }
             }
             else
                 data[num2++] = num6;
         }
     } while (num5 > 0);
     data.NumItems = num2;
     return (num2 - num4);
 }
Пример #22
0
 public void StopIdentifyDevice(DeviceHandle handle, DeviceDescriptor a_dev)
 {
 }
Пример #23
0
 public int write(DeviceHandle handle, DataBuffer data)
 {
     if (handle == null || handle.isInvalid())
     {
         _log.Warn("Called with INVALID handle");
         return -1;
     }
     try
     {
         handle.RS232hnd.hnd.Write(data.Buf, 0, data.NumItems);
     }
     catch (Exception exception)
     {
         _log.Error("write() - " + exception.Message);
         return -1;
     }
     return 0;
 }
Пример #24
0
 public unsafe int write(DeviceHandle handle, DataBuffer data)
 {
     byte* numPtr = stackalloc byte[0x100];
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_EZLinkDongle.write()", "called with INVALID handle");
         return -1;
     }
     Protocol protocol2 = data.ddi_getProtocol();
     if (protocol2 == Protocol.Write)
     {
         string str;
         data.ddi_getCommand_Transmit(out str);
         numPtr[0] = (byte) (str.Length + 4);
         numPtr[1] = 170;
         numPtr[2] = 0x2d;
         numPtr[3] = 0xd4;
         numPtr[4] = (byte) str.Length;
         for (int i = 0; i < str.Length; i++)
         {
             numPtr[i + 5] = (byte) str[i];
         }
         this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLink_Transmit_Start;
         this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLink_Transmit_End;
     }
     else if (protocol2 == Protocol.WriteRegister)
     {
         uint num;
         uint num2;
         data.ddi_getCommand_WriteRegister(out num, out num2);
         this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLinkReg_Write_Start;
         this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLinkReg_Write_End;
     }
     else
     {
         GlobalServices.ErrMsg("DDI_EZLinkDongle.write()", "Unexpected protocol received");
     }
     return 0;
 }
Пример #25
0
 private bool ExchCmdWithDev(DeviceHandle a_Handle, DataBuffer a_Data)
 {
     int writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
     DataBuffer data = new DataBuffer(512)
     {
         DType = Data_Type.ASCII
     };
     while (writeRetryCnt > 0)
     {
         data.copy(a_Data);
         int readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);
         if (write(a_Handle, data) < 0)
         {
             _log.Warn("Device was probably disconnected.  write() returned with -1");
             return false;
         }
         Thread.Sleep(100);
         data.NumItems = 0;
         while (readRetryCnt > 0)
         {
             if (readAppend(a_Handle, data, data.Capacity - data.NumItems) < 0)
             {
                 _log.Warn("Device was probably disconnected.  readAppend() returned with -1");
                 Thread.Sleep(50);
                 readRetryCnt--;
             }
             else
             {
                 if (data.endsWith("OK\n\r>"))
                 {
                     a_Data.copy(data);
                     return true;
                 }
                 Thread.Sleep(100);
                 readRetryCnt--;
             }
         }
         writeRetryCnt--;
     }
     a_Data.NumItems = 0;
     return false;
 }
Пример #26
0
 private unsafe bool isDeviceAlive(DeviceHandle handle)
 {
     byte* numPtr = stackalloc byte[0x40];
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_EZLINKUSB.isDeviceAlive()", "called with INVALID handle");
         return false;
     }
     int dev = handle.EZLinkhnd.dev;
     this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLink_Status_DevAlive_Start;
     int num = 0;
     this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLink_Status_DevAlive_End;
     return ((num == 0) && (numPtr[1] == 0));
 }
Пример #27
0
        private DeviceHandle open(IOPortAddress a_iopAddr, int baudRate, char a_handshake)
        {
            DeviceHandle handle = new DeviceHandle();
            SafeSerialPort port = null;
            string portName = "COM" + a_iopAddr.comAddr.COMPortId.ToString();
            _log.Debug(string.Concat(new object[] { "Serial Port to open, ", portName, ", baud:", baudRate }));
            if (!ADTManager.instance().isRS232PortExcluded(portName))
            {
                bool flag;
                int num = 0;
                do
                {
                    flag = false;
                    try
                    {
                        bool suppressFinalize = false;
                        suppressFinalize = true;
                        port = new SafeSerialPort(portName, baudRate, Parity.None, 8, StopBits.One, suppressFinalize);
                        port.Open();
                        port.ReadTimeout = 100;
                        if (a_handshake == 'E')
                            port.RtsEnable = true;
                        else
                            port.RtsEnable = false;

                        Thread.Sleep(20);
                        handle = new DeviceHandle(new RS232Handle(port));
                        a_iopAddr.comAddr.baudRate = baudRate;
                    }
                    catch (Exception exception)
                    {
                        flag = true;
                        num++;
                        _log.Error("Open() - " + portName + " - " + exception.Message);
                        if (port != null)
                            port.Dispose();
                    }
                    Thread.Sleep(50);
                }
                while (flag && (num < 3));
                if (flag && !ADTManager.instance().isRS232PortExcluded(portName))
                {
                    _log.Debug(portName + " is busy. Temporarily excluded from WDS.");
                    ADTManager.instance().excludeRS232Port(portName);
                }
            }
            else
                _log.Debug("Port is excluded, will not open it:" + portName);

            _log.Debug("Port has been successfully (re)opened");
            return handle;
        }
Пример #28
0
 public int close(DeviceHandle handle)
 {
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_EZLINKUSB.close()", " was calleed with an invalid handle");
         return -1;
     }
     this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLink_Disconnect_Start;
     this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLink_Disconnect_End;
     return -1;
 }
Пример #29
0
        private DeviceDescriptor queryDeviceInfo(DeviceHandle handle, DeviceDescriptor devInfo)
        {
            DataBuffer data = new DataBuffer(128);
            int writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
            int pollDeviceTypeProcDelay = int.Parse(ConfigurationManager.AppSettings["PollDeviceTypeProcDelay"]);
            int readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);
            if (handle.isInvalid())
            {
                _log.Error("QueryDeviceInfo() - Called with INVALID argument");
                return devInfo;
            }
            data.copy("\r");
            write(handle, data);
            Thread.Sleep(pollDeviceTypeProcDelay);
            flushRead(handle, data);
            while (writeRetryCnt > 0)
            {
                if (devInfo.BootloaderMode)
                {
                    data.copy("J");
                    _log.Debug("queryDeviceInfo():: 'J'");
                }
                else
                {
                    data.copy("I\r");
                    _log.Debug("queryDeviceInfo():: 'I\r'");
                }
                if (write(handle, data) < 0)
                {
                    _log.Warn("Device was probably disconnected. write() returned with -1");
                    return devInfo;
                }

                Thread.Sleep(pollDeviceTypeProcDelay);
                data.NumItems = 0;
                for (int i = readRetryCnt; i > 0; i--)
                {
                    if (readAppend(handle, data, data.Capacity - data.NumItems) < 0)
                    {
                        _log.Warn("Device was probably disconnected.  readAppend() returned with -1");
                        return devInfo;
                    }
                    if (data.endsWith("OK\n\r>"))
                        break;
                    Thread.Sleep(20);
                }

                string response = data.BufToStr;
                _log.Info("queryDeviceInfo():: response:" + response);
                try
                {
                    if (response.Length < 10)
                        return devInfo;

                    string strTmp = response.Substring(0, 10);
                    if (response.Contains("SRW"))
                    {
                        #region SRW...

                        string[] strArray = response.Remove(0, response.IndexOf("SRW")).Split(new char[] { ',' });
                        string subType = strArray[3].Substring(0, 3).Trim();
                        switch (strArray[0].Trim())
                        {
                            case "SRW001":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SDBC_8);
                                switch (subType)
                                {
                                    case "NW2":
                                        devInfo.FirmwareType = new FirmwareType("ENW_Master");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;

                                    case "PED":
                                        devInfo.FirmwareType = new FirmwareType("PER_Demo");
                                        break;
                                }
                                devInfo.DevicePhoto = SDBC.SDBC_8;
                                devInfo.MarketingName = SDBC.MarketingName;
                                devInfo.UnAssignedDeviceText = SDBC.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SDBC.SDBC_switch;
                                devInfo.WarningText = SDBC.WarningText;
                                devInfo.PartNumber = SDBC.PartNumber;
                                break;

                            case "SRW002":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW002);
                                if (subType != null && subType == "LBF")
                                    devInfo.FirmwareType = new FirmwareType("LBF");
                                devInfo.DevicePhoto = SRW002.SRW002_400;
                                devInfo.MarketingName = SRW002.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW002.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SRW002.SRW002_400;
                                devInfo.WarningText = SRW002.WarningText;
                                devInfo.PartNumber = SRW002.PartNumber;
                                break;

                            case "SRW003":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.EZLink);
                                switch (subType)
                                {
                                    case "NW1":
                                        devInfo.FirmwareType = new FirmwareType("NWD_Slave");
                                        break;

                                    case "NW2":
                                        devInfo.FirmwareType = new FirmwareType("ENW_Slave");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;

                                    case "ED":
                                        devInfo.FirmwareType = new FirmwareType("EZLink");
                                        break;
                                }
                                devInfo.DevicePhoto = EzLink.EZLink_D_EP;
                                devInfo.MarketingName = EzLink.MarketingName;
                                devInfo.UnAssignedDeviceText = EzLink.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = EzLink.EZLink_switch;
                                devInfo.WarningText = EzLink.WarningText;
                                devInfo.PartNumber = EzLink.PartNumber;
                                break;

                            case "SRW004":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW004);
                                switch (subType)
                                {
                                    case "LBL":
                                        devInfo.FirmwareType = new FirmwareType("LoadBoard_Lite");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;
                                }
                                devInfo.DevicePhoto = SRW004.Si1000DK;
                                devInfo.MarketingName = SRW004.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW004.UnAssignedDeviceText;
                                devInfo.WarningText = SRW004.WarningText;
                                devInfo.PartNumber = SRW004.PartNumber;
                                break;

                            case "SRW005":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.EZLink);
                                switch (subType)
                                {
                                    case "NW1":
                                        devInfo.FirmwareType = new FirmwareType("NWD_Slave");
                                        break;

                                    case "NW2":
                                        devInfo.FirmwareType = new FirmwareType("ENW_Slave");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;

                                    case "ED":
                                        devInfo.FirmwareType = new FirmwareType("EZLink");
                                        break;
                                }
                                devInfo.DevicePhoto = EzLink.EZLink_D_EP;
                                devInfo.MarketingName = EzLink.MarketingName;
                                devInfo.UnAssignedDeviceText = EzLink.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = EzLink.EZLink_switch;
                                devInfo.WarningText = EzLink.WarningText;
                                devInfo.PartNumber = EzLink.PartNumber;
                                break;

                            case "SRW007":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW007);
                                switch (subType)
                                {
                                    case "RKD":
                                        devInfo.FirmwareType = new FirmwareType("RKE_Master");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;
                                }
                                devInfo.DevicePhoto = SRW007.SRW007_100x84;
                                devInfo.MarketingName = SRW007.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW007.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SRW007.SRW007_switch;
                                devInfo.WarningText = SRW007.WarningText;
                                devInfo.PartNumber = SRW007.PartNumber;
                                break;

                            case "SRW008":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW008);
                                switch (subType)
                                {
                                    case "RKD":
                                        devInfo.FirmwareType = new FirmwareType("RKE_Master");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;
                                }
                                devInfo.DevicePhoto = SRW008.SRW008_100x84;
                                devInfo.MarketingName = SRW008.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW008.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SRW008.SRW008_switch;
                                devInfo.WarningText = SRW008.WarningText;
                                devInfo.PartNumber = SRW008.PartNumber;
                                break;

                            case "SRW009":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW009);
                                switch (subType)
                                {
                                    case "RKD":
                                        devInfo.FirmwareType = new FirmwareType("RKE_Master");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;
                                }
                                devInfo.DevicePhoto = SRW009.SRW009_100x84;
                                devInfo.MarketingName = SRW009.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW009.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SRW009.SRW009_switch;
                                devInfo.WarningText = SRW009.WarningText;
                                devInfo.PartNumber = SRW009.PartNumber;
                                break;

                            default:
                                break;
                        }
                        devInfo.DeviceVersion = new DeviceVersion(strArray[1]);
                        devInfo.FirmwareVersion = new FirmwareVersion(strArray[2]);
                        return devInfo;

                        #endregion
                    }

                    if (strTmp.Contains("SDBC-8"))
                    {
                        #region SDBC-8

                        int idx = strTmp.IndexOf("SDBC-8");
                        //	SDBC-8......VVVVV......FFFFF..PED
                        //	SDBC-8......VVVVV......FFFFF..NWD
                        //            dev.version  fw.version

                        devInfo.DeviceType = new DeviceType(DeviceTypeID.SDBC_8);
                        strTmp = response.Substring(idx + 30, 3);
                        if (strTmp == "NWD")
                        {
                            devInfo.DeviceVersion = new DeviceVersion(response.Substring(idx + 12, 5));
                            devInfo.FirmwareType = new FirmwareType("NWD_Master");
                            devInfo.FirmwareVersion = new FirmwareVersion(response.Substring(idx + 23, 5));
                            devInfo.DevicePhoto = SDBC.SDBC_8;
                            devInfo.SwitchPhoto = SDBC.SDBC_switch;
                            devInfo.WarningText = SDBC.WarningText;
                            return devInfo;
                        }
                        if (strTmp == "PED")
                        {
                            devInfo.DeviceVersion = new DeviceVersion(response.Substring(idx + 12, 5));
                            devInfo.FirmwareType = new FirmwareType("PER_Demo");
                            devInfo.FirmwareVersion = new FirmwareVersion(response.Substring(idx + 23, 5));
                            devInfo.DevicePhoto = SDBC.SDBC_8;
                            devInfo.SwitchPhoto = SDBC.SDBC_switch;
                            devInfo.WarningText = SDBC.WarningText;
                            return devInfo;
                        }

                        #endregion
                    }
                    else if (strTmp.Contains("D-EP"))
                    {
                        #region EZLink
                        int idx = strTmp.IndexOf("D-EP");
                        devInfo.DeviceType = new DeviceType(DeviceTypeID.EZLink);
                        if (response.Substring(idx + 27, 3) == "NWD")
                        {
                            strTmp = response.Substring(idx + 9, 5);
                            devInfo.DeviceVersion = new DeviceVersion(strTmp);
                            devInfo.FirmwareType = new FirmwareType("NWD_Slave");
                            strTmp = response.Substring(idx + 20, 5);
                            devInfo.FirmwareVersion = new FirmwareVersion(strTmp);
                            return devInfo;
                        }
                        #endregion
                    }
                    else
                    {
                        if (response.Contains("V1.10W"))
                        {
                            devInfo.DeviceType = new DeviceType(DeviceTypeID.SDBC_8);
                            devInfo.DeviceVersion = new DeviceVersion("01.1r");
                            devInfo.FirmwareType = new FirmwareType("Bootloader");
                            devInfo.FirmwareVersion = new FirmwareVersion("V1.10W");
                            devInfo.DevicePhoto = SDBC.SDBC_8;
                            devInfo.SwitchPhoto = SDBC.SDBC_switch;
                            devInfo.WarningText = SDBC.WarningText;
                            return devInfo;
                        }
                        if (response.Length >= 26)
                        {
                            #region LoadBoard
                            if (response.Substring(4, 26) == "Wireless Development Suite")
                            {
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.LoadBoard);
                                devInfo.DeviceVersion = new DeviceVersion("02.20");
                                devInfo.FirmwareType = new FirmwareType("LoadBoard");
                                devInfo.FirmwareVersion = new FirmwareVersion(response.Substring(0x23, 4));
                                devInfo.DevicePhoto = LoadBoard.HWBoard_LoadBoard;
                                return devInfo;
                            }
                            if (response.Substring(4, 16) == "LoadBoard Loader")
                            {
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.LoadBoard);
                                devInfo.DeviceVersion = new DeviceVersion("02.20");
                                devInfo.FirmwareType = new FirmwareType("BootLoader");
                                devInfo.FirmwareVersion = new FirmwareVersion(response.Substring(0x17, 4));
                                return devInfo;
                            }
                            #endregion
                        }
                    }
                }
                catch (Exception exception)
                {
                    _log.Error("QueryDeviceInfo() - " + exception.Message);
                    return devInfo;
                }
                writeRetryCnt--;
            }
            return devInfo;
        }
Пример #30
0
        private FDResult WriteFirmwareToDevice(ArrayList firmware, UpdateFirmwareCallback callback, ushort vid, ushort pid, string serial, string hexFileName)
        {
            BootloadStatus fail = BootloadStatus.Fail;
            int num = 0;
            int num2 = 0;
            m_hidApp = _adtRecord.PortAddress.handle;
            if (((m_hidApp.HIDhnd.hnd.IsOpened() != 0) || m_hidApp.HIDhnd.hnd.Connect(vid, pid, serial, 0x7d0, 0x7d0)) &&
                ((fail = LoadHexFile(hexFileName)) == BootloadStatus.Success))
            {
                bool[] flashPageModified = m_flashPageModified;
                for (int i = 0; i < flashPageModified.Length; i++)
                    if (flashPageModified[i])
                        num++;

                EzDCP2 zdcp = new EzDCP2(m_hidApp);
                fail = zdcp.initiateIcommand() ? BootloadStatus.Success : BootloadStatus.Fail;
                byte[] rxDara = new byte[1];
                callback(0, false, "", MessageBoxButtons.OK);
                fail = zdcp.exchangeMessagese(new byte[] { 0x80, 0x55, 4, 0x18, 0x2a, 0, 0x36 }, ref rxDara, 0x9c4, true, false) ? BootloadStatus.Success : BootloadStatus.Fail;
                if (fail != BootloadStatus.Success)
                    return FDResult.Error;

                for (int j = 0; j < m_flashPageModified.Length; j++)
                {
                    if (m_flashPageModified[j])
                    {
                        ushort num6;
                        ushort sourceIndex = (ushort)(j * 512);
                        for (ushort k = 0; k < 512; k = (ushort)(k + num6))
                        {
                            num6 = (ushort)(512 - k);
                            num6 = Math.Min(num6, (ushort)32);
                            byte[] destinationArray = new byte[num6];
                            Array.Copy(m_flashMemory, sourceIndex, destinationArray, 0, num6);
                            fail = zdcp.exchangeMessagese(zdcp.createDCP2Commands(destinationArray, sourceIndex), ref rxDara, 0, true, false) ? BootloadStatus.Success : BootloadStatus.Fail;
                            if (fail != BootloadStatus.Success)
                                return FDResult.Error;

                            sourceIndex = (ushort)(sourceIndex + num6);
                        }
                        num2++;
                        if (num > 0)
                        {
                            int percentageComplete = (num2 * 100) / num;
                            callback(percentageComplete, false, "", MessageBoxButtons.OK);
                        }
                        if (fail != BootloadStatus.Success)
                            return FDResult.Error;
                    }
                }
                fail = zdcp.exchangeMessagese(new byte[] { 0x80, 0x55, 4, 0x18, 0x29, 0, 0x35 }, ref rxDara, 0, true, false) ? BootloadStatus.Success : BootloadStatus.Fail;
                zdcp.initiateIcommand();
            }
            Thread.Sleep(500);
            return FDResult.OK;
        }