# USB Printer Setup Guide - Dai Nippon Printing DS-RX1HS

## Problem Summary
The app printing is not working with your USB printer:
- **Printer**: Dai Nippon Printing DS-RX1HS Photo Printer
- **Connection**: USB (vendor_id=4931, product_id=5)
- **Device**: /dev/bus/usb/007/002

---

## ✅ Fixed Configuration
Your app now includes:
- ✅ USB permissions added to `config.xml`
- ✅ Enhanced error logging for USB/IP printing
- ✅ Device diagnostics functions
- ✅ Better error messages in Chinese

---

## 🚀 Next Steps to Fix USB Printing

### **Step 1: Enable USB Debugging on Android Device**
1. Go to **Settings** → **About Phone**
2. Tap **Build Number** 7 times to enable Developer Mode
3. Go to **Settings** → **Developer Options** → Enable **USB Debugging**
4. Connect device via USB cable

### **Step 2: Rebuild Android App with New USB Permissions**
```bash
cd "/Applications/XAMPP/xamppfiles/htdocs/Android Photo App"

# Clean and rebuild
rm -rf platforms/android/build
npm run cordova-build
# or for release:
npm run cordova-build-apk
```

### **Step 3: Install on Device**
```bash
# Using adb
adb install -r platforms/android/build/outputs/apk/debug/app-debug.apk
```

### **Step 4: Test USB Printing**
1. Open app on Android device
2. Select a photo
3. Click **"透過OS打印"** (Print via OS)
   - This uses the system print dialog which should detect the USB printer
4. Check console logs for diagnostics:
   ```
   📱 Printing Diagnostics
   ✅ Cordova Available: true
   ✅ Printer Plugin: true
   ```

---

## 🔧 Troubleshooting

### Issue: "未能連結打印機" (Cannot connect to printer)

#### ❌ If you see: "Printer plugin is NOT available"
**Solution**: Reinstall printer plugin
```bash
cordova plugin remove cordova-plugin-printer
cordova plugin add cordova-plugin-printer@0.9.1
npm run cordova-build
```

#### ❌ If USB printer still not detected
**Try these solutions**:

1. **Check Device Connection**
   ```bash
   adb devices
   # Should show your device as "device"
   ```

2. **Verify USB Device is Visible**
   ```bash
   lsusb -v | grep -A 20 "4931"
   # Should show: Dai Nippon Printing
   ```

3. **Check Android Permissions**
   - Go to **Settings** → **Apps** → **Photo App**
   - Check **Permissions** → Grant USB permission if available

4. **Try Using Network Mode Instead**
   - Some USB printers can be configured to work over network
   - Use "透過IP打印" (Print via IP) if printer supports network
   - Enter printer IP: 192.168.x.x

---

## 💡 For Dai Nippon Printing DS-RX1HS Specifically

The DS-RX1HS is a specialized photo printer. Depending on the model variant:

### If using USB Direct
- The printer needs USB host mode support on Android device
- Requires proper USB driver (usually included via cordova-plugin-printer)
- Ensure printer firmware is up to date

### If Printer Supports Network
- Connect printer to WiFi network
- Use "透過IP打印" button
- Enter printer's IP address (find in printer settings)

### If Printer Supports Proprietary Protocol
You may need a custom Cordova plugin. Contact support:
- https://dnpphoto.com/en-us/Products/Printers/ds-rx1hs
- Check for Android SDK/API documentation

---

## 🔍 Debug Logs

When testing, check the console for:

**Successful USB Print:**
```
Initiating print via OS with USB printer...
Print job sent to OS successfully
打印成功!
```

**Failed USB Print:**
```
Initiating print via OS with USB printer...
Print error: [error details]
USB打印失敗 - Please check:
1. USB線連接
2. USB調試已啟用  
3. 打印機已開啟
```

---

## 📞 If Still Not Working

Try Alternative Approach - **Use Network Printing if Supported**:

1. If printer supports WiFi/Ethernet:
   - Configure printer network settings
   - Get printer IP address
   - Use "透過IP打印" button in app
   - Enter IP: 192.168.x.x

2. Document the exact error message from console logs:
   ```
   Open Chrome DevTools F12 → Console tab
   Take screenshot of any error messages
   ```

3. Check printer manufacturer support:
   - Model: DS-RX1HS
   - Manufacturer: Dai Nippon Printing
   - Support: https://dnpphoto.com/

---

## ✨ What Changed in Your App

### **config.xml** - Added USB Permissions
```xml
<uses-permission android:name="android.permission.USB_PERMISSION" />
```

### **utils.js** - Enhanced Functions
- `printViaOS()` - Now with detailed error logging
- `printViaIP()` - Network printer support
- `logPrintingDiagnostics()` - New debugging tool
- `checkPrinterPlugin()` - Plugin status check
- `getDeviceInfo()` - Device information

### **App.vue** - Improved Error Messages
- Better Chinese error messages specific to USB/network printing
- Auto-diagnostics on app load
- Success confirmations

---

## 🎯 Quick Checklist

- [ ] USB Debugging enabled on device
- [ ] Device connected via USB cable
- [ ] Rebuilt app with new permissions
- [ ] Printer turned on
- [ ] Printer USB cable connected to Android device
- [ ] Tested with "透過OS打印" button
- [ ] Checked console logs for diagnostics
- [ ] Reviewed error messages from app alerts

---

## 📚 Related Documentation

- [Cordova Plugin Printer](https://github.com/katzer/cordova-plugin-printer)
- [Dai Nippon Printing DS-RX1HS](https://dnpphoto.com/en-us/Products/Printers/ds-rx1hs)
- [Android USB Host](https://developer.android.com/guide/topics/connectivity/usb/host)

