Serial Read Write From PC USB to HP 34401A meter DB-9[Solved]

For issues with communication ports, protocols, etc.
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From PC USB to HP 34401A multi-meter DB-9 [solved]

Post by mark bower »

The code needed for communication for PC-USB to HP34401A multimeter RS-232 is solved. Below I present: 1) the code that works, 2) the result, 3) code provided in the HP manual that overly influenced my coding attempts. Since I have that code that works, I will not respond further to suggestions from Mr. Swiss and D.J Peters, but a BIG THANKS thanks to both of you for taking interest and trying to help me.

Code: Select all

Dim as string resp    						'resp = response
Dim volt as Single
dim J as integer

open com "/dev/ttyUSB0:9600,e,7,2,rs,cd0,cs0,ds0" for input as #1
sleep 300				

'print #1, ":SYST:BEEP;:DISP:TEXT 'HELLO WORLD'" 
'sleep 200

Print #1, ":SYST:REM"  										                     
print #1, "*IDN?"										
sleep 100											'***ESSENTIAL DELAY***

for j=1 to 4
Print #1, ":READ?"
sleep 400											'***ESSENTIAL DELAY***
Input #1,resp
Print resp
next

Print #1,":CONF:VOLT:DC 10,.001;:SAMP:COUN 1"   	'init meter                         				

For j = 1 to 10
    Print #1, ":READ?"								
    sleep 100										'***ESSENTIAL DELAY***
    Input #1,resp 
    volt = Val(resp)    
    locate 5+j,1  
    print using "##.###";volt
    locate 5+j,20
    print "*" & resp & "*"  
next
RESULTS
HEWLETT-PACKARD
34401A
0
4-1-1

3.871 *+3.87080000E+00*
3.870 *+3.86970000E+00*
3.870 *+3.86970000E+00*
3.870 *+3.86970000E+00*
3.870 *+3.86970000E+00*
3.870 *+3.86970000E+00*
3.870 *+3.86970000E+00*
3.869 *+3.86870000E+00*
3.869 *+3.86870000E+00*
3.869 *+3.86870000E+00*

HP Manual
/home/mark/Desktop/2020-01-17-0002.jpg

Addendum:
1) The code that worked with PC-DB-9 to HPmeter-RS-232 has to be altered for PC-USB to HPmeter-RS-232.
2) The key to getting properly working code was altering the Open Com parameters. Specifically, adding "ds0" and eliminating "lf" or line feed.
3) There is still some improvement needed in the code whereby I can send a message to the display and not have it foul the following the code which follows. Some form of clear needs to be sent after the display message - minor problem. Sending to the display is just kinda fun.
4) The "*IDN" parameter will not be used for my FB "equipment" programs. From the HP manual, I expected the return for "*IDN?" to be a single string, but it turns out that each of the meter I.D. parameters it reports are treated separately. Thus my For Next loop for 4 reads of the *IDN? return.

Looks like I do not know how to get a .jpg from Desktop into post?

And Joshy, thanks for clearing my mistake wherein I locked myself out from editing.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Serial Read Write From PC USB to HP 34401A meter DB-9[Solved]

Post by badidea »

If you use Line Input #1,resp instead of Input #1,resp then you probably get the meter ID string in 1 read.
mark bower wrote: /home/mark/Desktop/2020-01-17-0002.jpg
Looks like I do not know how to get a .jpg from Desktop into post?
You cannot upload an image directly to the forum. You can only place 'links' to images on another web-server/site.
E.g. image on wikipedia:
Image
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From PC USB to HP 34401A meter DB-9[Solved]

Post by mark bower »

@ badidea

Thank you. Line Input vs Input works a treat. Early in the struggle I tried Line Input and it balked; it was the code suggested by the HP manual. But apparently there were many other problems involved. My code now uses Line Input.

Bummer on .img insert, but your post shows the "beauty" (HP34401A).
mark
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From PC USB to HP 34401A meter DB-9[Solved]

Post by mark bower »

To wrap it up, just in case someone else with the HP34401A multimeter needs to communicate from USB to RS-232, the following is the key "open com" code line that worked for my equipment:

Code: Select all

open com "/dev/ttyUSB0:9600,e,7,2,rs,cd0,cs0,ds0" for input as #1
Post Reply