First test and I can hardly catch the trick, I managed to turn the green LED on the DexDrive. For something one starts.
What I have done, only awakens Dedrive withthe green LED showing it is ready to receive commands in which I have not yet scheduled.
In the black box, shown in green letters characters.
For now, this is the code.
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports; // No olvidar.
using System.Threading;
namespace DexPlorer
{
public partial class Form1 : Form
{
public enum Dex_Comandos
{
INIT = 0x00, STATUS = 0x01, READ = 0x02, SEEK = 0x03, WRITE = 0x04, PAGE = 0x05, LIGHT = 0x07, MAGIC_HANDSHAKE = 0x27
}
public enum Dex_Respuestas
{
POUT = 0x20, ERROR = 0x21, NOCARD = 0x22, CARD = 0x23, CARD_NEW = 0x25, SEEK_OK = 0x27, WRITE_OK = 0x28, WRITE_SAME = 0x29, WAIT = 0x2A, ID = 0x40, DATA = 0x41
}
byte[] TRAMAS = { 0x10, 0x29, 0x23, 0xbe, 0x84, 0xe1, 0x6c, 0xd6, 0xae, 0x52, 0x90, 0x49, 0xf1, 0xf1, 0xbb, 0xe9, 0xeb };
// Utilizaremos un string como buffer de recepción.
string Recibidos;
// Buffer para almacenar leer datos de la DexDrive.
byte[] Leer_Datos = null;
// Contiene una versión de firmware de un dispositivo detectado.
string Firmware_Version = null;
public Form1()
{
InitializeComponent();
// Puerto abierto desde que arranca la aplicación.
if (!serialPort1.IsOpen)
{
try
{
serialPort1.Open();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//Dexdrive won't respond if RTS is not toggled on/off
serialPort1.RtsEnable = false;
Thread.Sleep(300);
serialPort1.RtsEnable = true;
Thread.Sleep(300);
//DTR line is used for additional power
serialPort1.DtrEnable = true;
// Comprobar si DexDrive está conectado al puerto.
// La detección puede fallar primera o segunda vez, por lo que el comando es enviado 5 veces.
for (int i = 0; i < 5; i++)
{
serialPort1.DiscardInBuffer();
serialPort1.Write("XXXXX");
Thread.Sleep(20);
}
// Compruebe cadena "IAI".
Leer_Datos = Leer_datos_del_puerto();
if ((Leer_Datos[0] != 0x49) || (Leer_Datos[1] != 0x41) || (Leer_Datos[2] != 0x49)) return;
// Despierta DexDrive arriba (patear desde el modo POUT).
//Envia_dato_al_puerto((byte)Dex_Comandos.INIT, new byte[] { 0x10, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0xAA, 0xBB, 0xCC, 0xDD }, 50);
Envia_dato_al_puerto((byte)Dex_Comandos.INIT, new byte[] { 0x10, 0x29, 0x23, 0xbe, 0x84, 0xe1, 0x6c, 0xd6, 0xae, 0x52, 0x90, 0x49, 0xf1, 0xf1, 0xbb, 0xe9, 0xeb }, 50);
// Compruebe cadena "PSX".
Leer_Datos = Leer_datos_del_puerto();
if ((Leer_Datos[5] != 0x50) || (Leer_Datos[6] != 0x53) || (Leer_Datos[7] != 0x58)) return; // "Dispositivo detectado no es un PS1 DexDrive."
// Obtener la versión del firmware.
Firmware_Version = (Leer_Datos[8] >> 6).ToString() + "." + ((Leer_Datos[8] >> 2) & 0xF).ToString() + (Leer_Datos[8] & 0x3).ToString();
label_chivato.Text = Firmware_Version;
// Enviar señal de handshake magia 10 veces.
for (int i = 0; i < 10; i++) Envia_dato_al_puerto((byte)Dex_Comandos.MAGIC_HANDSHAKE, null, 0);
Thread.Sleep(50);
// Enciende la luz de estado.
Envia_dato_al_puerto((byte)Dex_Comandos.LIGHT, new byte[] { 1 }, 50);
// Todo ha ido bien, DexDrive está listo para recibir comandos.
//return null;
Recibidos = Encoding.ASCII.GetString(Leer_Datos);
// Recibidos = Encoding.Default.GetString(Leer_Datos);
// Para ver lo que envÃa desde el DexDrive hacia esta interfaz de C#.
// Asignar el valor de la trama al richTextBox.
richTextBox1.Text = Recibidos;
// // Para ver lo que envÃa desde el DexDrive hacia esta interfaz de C#.
// // Asignar el valor de la trama al richTextBox.
richTextBox1.Text = Recibidos;
// Selecciona la posición final para leer los mensajes entrantes.
richTextBox1.SelectionStart = richTextBox1.Text.Length;
//serialPort1.DataReceived += new SerialDataReceivedEventHandler(Recepcion);
}
// Enviar comando DexDrive en el puerto COM se abrió con un retraso.
private void Envia_dato_al_puerto(byte Comando, byte[] Dato, int Delay)
{
// Borrar todo en el búfer de entrada.
serialPort1.DiscardInBuffer();
// Cada comando debe comenzar con la cadena "IAI".
serialPort1.Write("IAI" + (char)Comando);
if (Dato != null) serialPort1.Write(Dato, 0, Dato.Length);
// Espere un tiempo establecido (para la respuesta DexDrive).
if (Delay > 0) Thread.Sleep(Delay);
}
// Captura la respuesta de un DexDrive.
private byte[] Leer_datos_del_puerto()
{
// Buffer para la lectura de datos.
byte[] Flujo_de_entrada = new byte[256];
// Leer datos de DexDrive.
if (serialPort1.BytesToRead != 0) serialPort1.Read(Flujo_de_entrada, 0, 256);
return Flujo_de_entrada;
}
}
}
Thereby still trying to send commands to see if allowed, how to format, read, erase something.
Your program does not read the model as the original Explorer?
I've noticed that your program has everything, except that you have forgotten some details. Your program has to detect when a "Memory Card" inserted. When you remove or insert the memory card, "DeXplorer 2" shows a picture next.
Can you do this in the future?
That will be more complete.
Happy holidays.