Terribletrux Posted March 6, 2015 Posted March 6, 2015 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!
Terribletrux Posted March 9, 2015 Author Posted March 9, 2015 Bueller..... Bueller..... Bueller..... Bump:
Solution Terribletrux Posted March 16, 2015 Author Solution Posted March 16, 2015 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)
auto-it-tous Posted March 18, 2015 Posted March 18, 2015 Are you sure to using a "rs232 cable" to link with power supply ? -Everything are starting by the dreams.-Everybody is working with computer.-Everydays will auto because we need it. Come on..Let's doing...AUTOIT....^^"..just a little idea..a little A.D.
jchd Posted March 18, 2015 Posted March 18, 2015 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 hereRegExp tutorial: enough to get startedPCRE 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)
Anamaria Posted March 23, 2015 Posted March 23, 2015 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. expandcollapse popup#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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now