예제 #1
0
        private void btnRead_Click(object sender, RoutedEventArgs e)
        {
            int deviceId = DeviceId;

            byte[] bArr = new byte[50];
            String text = String.Empty;

            try
            {
                CH341NativeFunctions.CH341OpenDevice(deviceId);
                if (CH341NativeFunctions.CH341ReadEEPROM(deviceId, EEPROM_TYPE.ID_24C128, 0, 33, bArr))
                {
                    String inStr = String.Empty;
                    foreach (char b in bArr)
                    {
                        if (b == '\0')
                        {
                            break;
                        }
                        inStr += b;
                    }
                    text = String.Format("Read from EEPROM ID: {0} successful\nValue: {1}\n", deviceId, inStr);
                }
                else
                {
                    text = String.Format("Error reading from EEPROM ID: {0}\n", deviceId);
                }
                PrintRight(text);
            }
            catch (Exception ex)
            {
                log.WriteToLog(ex);
            }
            CH341NativeFunctions.CH341CloseDevice(deviceId);
        }
예제 #2
0
        private void btnWrite_Click(object sender, RoutedEventArgs e)
        {
            int deviceId = DeviceId;

            CH341NativeFunctions.CH341OpenDevice(deviceId);
            String outStr = String.Format("{0}\0", tbInput.Text);

            PrintRight("Write status: {0}: {1}\n", CH341NativeFunctions.CH341WriteEEPROM(deviceId, EEPROM_TYPE.ID_24C128, 0, outStr.Length, outStr.GetBytes()) ? "Success!" : "Fail", outStr);
            CH341NativeFunctions.CH341CloseDevice(deviceId);
        }