Failed to communicate with device

Started by mikerabat, January 15, 2018, 08:39:02 am

Previous topic - Next topic

mikerabat

January 15, 2018, 08:39:02 am Last Edit: January 15, 2018, 11:40:35 am by mikerabat
Hey there!
I'm trying to communicate with an Agilent E3631A Power supply device but I'm failing miserably....

I got some C++ demo code that works but I cannot get the correct settings for my Delphi program.

The c++ code uses the follwing settings:

IO class is : System::IO::Ports::SerialPort

PowerPort->PortName = command[1];
PowerPort->BaudRate = 9600;
PowerPort->Parity = System::IO::Ports::Parity::Even;
PowerPort->DataBits = 7;
PowerPort->StopBits = System::IO::Ports::StopBits::Two;

PowerPort->DtrEnable = true;   // otherwise we don't receive anything
PowerPort->NewLine = L"\n";

I'm especially troubled by teh DTR enabled flag which I have now idea on how to correctly use that stuff.
-> I'm setting the
fComPort.SetStateDTR(True);   
though but it doesn't do anything.

I got the description here :
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwjwodOI1dnYAhVEyKQKHQz1A48QFggoMAA&url=https%3A%2F%2Fedisciplinas.usp.br%2Fpluginfile.php%2F517639%2Fmod_folder%2Fcontent%2F0%2FAgilent_E3631%2520Power%2520Supply_Users_Guide.pdf%3Fforcedownload%3D1&usg=AOvVaw1ve67l1V5AS-lcpcYXVhGr

My code looks as this:

-> first init
-> send the SYST:REM command to setup the remote control
-> last step: send th *IDN command to receive the device's serial number

function TPowerSupplyE3631A.Connect(Port: integer): boolean;
var baudRate : integer;
    c : AnsiChar;
    found : boolean;
    retVal : Ansistring;
    cfg : Array[0..1] of byte;
    s : AnsiString;
begin
     fDevice := '';
     fConnected := False;
     Result := False;

     // ###########################################

     FreeAndNil(fComPort);
         
     try
        fComPort := TnrComm.Create(nil);
        fComPort.UseMainThread := True;
        fComPort.Log := frmServiceTool.nrLogFile1;
        fComPort.Terminal := frmServiceTool.Memo1;
        fComPort.TerminalUsage := tuBoth;
        fComPort.TerminalEcho := True;
        fComPort.TraceStates := [tsRxChar, tsRxFlag, tsTxEmpty, tsCTS, tsDSR, tsRLSD, tsBreak, tsErr];
        fComPort.MonitorDSR := frmserviceTool.chkMonitorDSR;
        fComPort.MonitorCTS := frmServiceTool.chkMonitorCTS;
        fComPort.MonitorRLSD := frmServiceTool.chkMonitorRLSD;
       
        fComPort.Parity := pNone; // pEven; // fParity;
        fComPort.StopBits := sbTwo; // fStopBits;
        fComPort.StreamProtocol := spHardware; // fProtocol;
        fComPort.ByteSize := 8; // fByteSize;

        fComPort.ComPortNo := Port;

        fComPort.TimeoutRead := 10000;
        fComPort.TimeoutWrite := 10000;

        fComPort.BaudRate := 9600; //fBaudRate;
        fComPort.RS485Mode := true;
         
        fComPort.Active := True;
       
        fComPort.ClearDeviceBuffers;

        sleep(500);
     
        // ###########################################
        // #### init device -> send some strings and get the device string back
      //  fComPort.SetStateDTR(True);
               
               
        fComPort.SendString('SYST:REM' + #10);  // enable remote access
        sleep(100);
        s := fComPort.ReadString;
        frmServiceTool.Memo1.Lines.Add('REM: ' + s);
       
        fComPort.SendString('*RST' + #10);      // system reset
        fComPort.SendString('*CLS' + #10);
        fComPort.SendString('*IDN' + #10);      // request identification string

        //fComPort.SetStateDTR(False);
     
        sleep(400);
        fDevice := fComPort.ReadString;

        Result := fDevice <> '';
     except
           on E : exception do
           begin
                FreeAndNil(fComPort);
                Result := False;
           end;
     end;
end;


But except a few beeps and an error indicator on the front panel I got nothing.

UPDATE:

The error came from the an missing character on the *IDN? string (the question mark was missing)

I managed to send data to the device and set some output value but still... I'm not able
to read the identification string from it:

fComPort.SendString('*IDN?' + #10);      // request identification string


so.. at least I can issue the command:
fComPort.SendString('APPL P6V,1.5,1.0' + #10);

and that sets some output current and voltage for the device... but still... I cannot manage to
read data from the device.