Jump to content

RS-232 communication to a Agilent E3649A, Help


Go to solution Solved by Terribletrux,

Recommended Posts

Hello,

I'm trying to communicate with a Agilent E3649A DC Power Supply. I have written some code using the CommAPI and so far I am only able to send commands, I cannot receive anything.  When I use the application that comes with the power supply everything is working as it should so that rules out the cable. Can someone look over my test code? I may have missed something...

#include <CommInterface.au3>
#include <MsgBoxConstants.au3>


Local Const $iPort = 1
Local Const $iBaud = 9600
Local Const $iParity = 0
Local Const $iByteSize = 8
Local Const $iStopBits = 2

Local $hFile =_CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits)
_CommAPI_ClearCommError($hFile)
_CommAPI_PurgeComm($hFile)

_CommAPI_TransmitString($hFile, "OUTP ON"&@LF) ;Turn output on
Sleep (1000)
_CommAPI_TransmitString($hFile, "VOLT 7.0"&@LF) ;Adjust voltage to 7 volts
Sleep (1000)
_CommAPI_TransmitString($hFile, "VOLT 0.0"&@LF) ;Adjust voltage to 0 volts
Sleep (1000)
_CommAPI_TransmitString($hFile, "OUTP OFF"&@LF) ;Turn output off
Sleep (1000)
_CommAPI_TransmitString($hFile, "*IDN?") ;Identify your-self

Local $sResult =_CommAPI_ReceiveString($hFile, 1, 0);Recieve string

_CommAPI_ClosePort($hFile)

MsgBox($MB_SYSTEMMODAL, "Title", $sResult, 5) 

I know that the commands are being sent properly because I can see the output status change on the display of the power supply and my connected LED lights up and then goes out.

 Also here is a link to the user manual http://cp.literature.agilent.com/litweb/pdf/E3646-90001.pdf

Thank you in advance!

Link to comment
Share on other sites

  • Solution

Not sure why I could not get this to work with CommAPI, but i was able to get this working using >VISA / GPIB library for AutoIt3.  See my attached code. 

#include <Visa.au3>
#include <MsgBoxConstants.au3>

;Open a connection to the instrument.
Local $h_Instr = _viOpen("ASRL1::INSTR") ;"ASRL1::INSTR" is the VISA connection handle for COMM 1 on my PC.
MsgBox($MB_SYSTEMMODAL, "Instrument Handle obtained", "$h_Instr = " & $h_Instr) ;Show the Session Handle.

;Query the instrument.
Local $s_Answer = _viExecCommand($h_Instr, "*IDN?") ;$h_Instr is NOT A STRING now!
MsgBox($MB_SYSTEMMODAL, "GPIB QUERY result", $s_Answer ) ;Show the answer.

_viExecCommand($h_Instr, "OUTP ON") ;Turn output on.
Sleep (1000)
_viExecCommand($h_Instr, "VOLT 7.0") ;Adjust voltage to 7 volts.
Sleep (1000)
_viExecCommand($h_Instr, "VOLT 0.0") ;Adjust voltage to 0 volts.
Sleep (1000)
_viExecCommand($h_Instr, "OUTP OFF") ;Turn output off.
Sleep (1000)
$s_Answer = _viExecCommand($h_Instr, "VOLT?") ;Query the instruments current voltage setting.

; Close the instrument conection.
_viClose($h_Instr)

MsgBox($MB_SYSTEMMODAL, "Title", $s_Answer, 5)
Link to comment
Share on other sites

auto-it-tous,

The OP uses a serial (RS232) communication cable to manage (send commands, receive status and measurements) an Agilent PSU (lab power supply unit) from a PC.

Another commonly used communication is GP-IB (also known as HP-IB).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hi, 

use this link for the start: '?do=embed' frameborder='0' data-embedContent>>

Download the "commg.dll" and "CommMG.au3"

I made a change to your code (not to all) and hope that give you a start to begin with ... for communication I used the  CommMG.au3 and commg.dll.  

#include <CommMG.au3>
#include <MsgBoxConstants.au3>

;~  need to add the dll file to work properly
_CommSetDllPath(@ScriptDir & "\commg.dll")

Global $iPort = 1
Global $iBaud = 9600
Global $iByteSize = 8
Global $iParity = 0
Global $iStopBits = 1 ; must be set as 1 for the corect language
Global $iSetFlow = 0
Global $sportSetError = ''
Global $ValRTS = 0
Global $ValDTR = 0

;~ _CommSetPort -- not accepting the "Const" variable
_CommSetPort($iPort, $sportSetError, $iBaud, $iByteSize, $iParity, $iStopBits, $iSetFlow, $ValRTS, $ValDTR)
Sleep(200)

_CommClearInputBuffer()
_CommClearOutputBuffer()
$iWaitComplete = 1
$sEndChar = @CRLF
$maxlen = 200
$maxtime = 200
;~ _CommSendString("syst:rem" & @CRLF,1)
;~ Sleep(200)
_CommSendString("*cls" & @CRLF, 1)
Sleep(200)
_CommSendString("*idn?" & @CRLF, 1)
Sleep(200)
$s_Answer = _CommGetLine($sEndChar, $maxlen, $maxtime)
ConsoleWrite($s_Answer)
MsgBox($MB_SYSTEMMODAL, "Title", $s_Answer, 5)

;~ adding new function here// new command line 

_CommClearInputBuffer()
_CommClearOutputBuffer()
Sleep(200)
_CommClosePort() ;close the communication with com port

This work for me. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...