Exemple #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);
        }
Exemple #2
0
        private void btnOpenDevice_Click(object sender, RoutedEventArgs e)
        {
            int deviceId = DeviceId;

            ClearLeft();
            PrintLeft("Device ID: {0} - status: {1}\n", deviceId, CH341NativeFunctions.CH341OpenDevice(deviceId));

            byte[]        bArr     = new byte[100];
            StringBuilder sb       = new StringBuilder("", 256);
            int           ioLength = 100;

            CH341NativeFunctions.CH341GetInput(deviceId, bArr);
            PrintLeft("Status: {0}\n", bArr.GetString());

            CH341NativeFunctions.CH341GetConfigDescr(deviceId, sb, ref ioLength);
            PrintLeft("Config description: {0}\n", bArr.GetString());

            CH341NativeFunctions.CH341GetDeviceDescr(deviceId, sb, ref ioLength);
            PrintLeft("Device description: {0}\n", bArr.GetString());
            object obj = CH341NativeFunctions.CH341GetDeviceName(deviceId);

            //PrintLeft("Device name: {0}\n", sb.ToString());

            PrintLeft("Driver version: {0}\n", CH341NativeFunctions.CH341GetDrvVersion());
        }
Exemple #3
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);
        }