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

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

Post by mark bower »

I have an HPmeter with RS-232/DB-9 I/O serial connector which connects to the PC DB-9 connector. I am moving to inserting an adapter cable such that connectors now go HPmeter(DB-9) to PC(USB). The following code communicates for one loop, then errors on 2nd loop. The meter also displays an "Error" message. The "shell and open com lines" of the code I got from the FB Hardware Forum(and modified a bit to match required inputs to the meter).

Code: Select all

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

shell "stty -F /dev/ttyUSB0 speed 9600 -clocal -hupcl"		'code frm FB Hdware Forum
sleep 1000								'		"
open com "/dev/ttyUSB0:9600,e,7,2,rs,cd,ds,lf,pe" as #1 		'		"

Print #1, ":SYST:REM"                          			 'initialize HP meter 
Print #1,":CONF:VOLT:DC 10,.001;:SAMP:COUN 1"  	 'initialize HP meter
sleep 500                          				  	 'delay is essential this ln
do
    Print #1, ":READ?"								
    Input #1,resp 
    locate 5+j,20
    print "*" & resp & "*"  
    volt = Val(resp)
    locate 5+j,1  
    print using "##.####";volt
	j+= 1
	print j
loop until inkey<>"" or volt<.7
end
The display from running the code looks like the following. Note there are only two passes, though the code dictates looping until one of two events occur. Also note that 9600 is displayed. This is not desired.

Code: Select all

9600

 3.3467            *+3.34670000E+00*
 0.0000            **
 2

------------------
(program exited with code: 0)
Press return to continue
So, please, what are suggestions for code changes so that it behaves?
Last edited by mark bower on Jan 19, 2020 4:07, edited 3 times in total.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by badidea »

Try adding some delay in to loop, e.g. 100 ms.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by MrSwiss »

It is not really easy to fix code for a device that one doesn't have for testing.
The used protocol is also useful to know (commands, data e.t.c.).

As a first try, comment out the lines 5 & 6 of your code because the opening of the COM-
Port, can be done in FB-code (alone) and the following delay isn't needed any longer.
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by mark bower »

indeed, i remmed the 4&5 lines [shell "stty -F /dev/ttyUSB0 speed 9600 -clocal -hupcl", Sleep 1000] and the code executes, althoh no change. IE, it will only read once. i have played extensively with delays in the loop, but not effected a change in code execution. so at least your suggested simplification of the code is a good move(hopefully easier to debug), and frankly, i have no clue what "-clocal -hupcl" is intended to do.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by MrSwiss »

Not certain that this fixes any problems, it's just another try:

Code: Select all

Dim As String   resp                    ' resp = response
Dim As Single   volt
Dim As Long     fn = FreeFile, j = 0

Open com "/dev/ttyUSB0:9600,e,7,2,rs,cd,ds,lf,pe" as #fn
Sleep 3000                              ' delay to let device enumerate
Input #fn, resp                         ' see if we have a response
If Len(resp) Then Print "+"; resp; "+"  ' might remove "9600" from loop

Print #fn, ":SYST:REM"                  ' initialize HP meter
Print #fn, ":CONF:VOLT:DC 10,.001;:SAMP:COUN 1" ' initialize HP meter
sleep 500 : resp = ""                   ' delay is essential this ln

do
    Print #fn, ":READ?"                 ' commad --> to device
    sleep 500                           ' wait, before checking for response                      
    Input #fn, resp                     ' response <-- from device
    locate 5 + j, 20
    print "*"; resp; "*" 
    volt = CSng(resp)                   ' conversion: string to single
    locate 5 + j, 1 
    print using "##.####"; volt
    j += 1
    If j = 25 Then Cls : j = 0
    resp = "" : Print j
loop until InKey <> "" OrElse volt < 0.7
' End isn't required
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by mark bower »

bummer. no, execution is the same: only one data line and two attempts. i should add, that sporadically, when executing, no data is given. i have not seen a pattern when this happens. thank you for the modified code attempt.

and by the way, the impetus here is that i want to move to a 64bit M/B, but DB-9 serial ports are limited on new boards, if any include them at all versus ubiquitous USB. i have two of the HP34401A multi-meters, relatively expensive, and do a great job.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by MrSwiss »

Try to increase the sleep value (in the loop, between send & receive), step by step ...
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by mark bower »

Adding sleep 1000 between READ and resp does not make a change. I have played with any number of inserted sleep statements and not had success.

A further experiment: I took the contents between the do loop and repeated 4 times with Sleep 1000 between each "content". Of 11 executions, 8 had values reported for #1 and #3, 1 had a value for #1, and 2 had a value at number 3. Maybe a graphic is better where x = correct volts display. I wonder if this type of response gives any clues? Generally speaking because there is lack of consistency, every other read displays the data. Why not in "do loop"?

1 xxxxxxxx x
2
3 xxxx xxxxxx
4
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by mark bower »

So I changed the Do Loop to a FOR NEXT of 20 and this is the result:

Code: Select all

0.0000            **
 0.0000            **
 3.3441            *+3.3441000*
 0.0000            **
 3.3441            *+3.34410000E+00*
 0.0000            **
 0.0000            **
 0.0000            **
 0.0000            **
 0.0000            **
 3.3451            *+3.3451000*
 0.0000            **
 3.3441            *+3.34410000E+00*
 0.0000            **
 3.3441            *+3.34410000E+00*
 0.0000            **
 0.0000            **
 0.0000            **
 3.3441            *+3.3441000*
 0.0000            **

And then I modified the code to:

Code: Select all

For j = 1 to 20
    Print #1, ":READ?"								
    sleep 1000
    Input #1,resp 
    locate 5+j,20
    print "*" & resp & "*"  
    'volt = Val(resp)
    'locate 5+j,1  
    'print using "##.####";volt
next
And voila the following, which now shows consistency/repeatibility. So I wonder what this suggests?

Code: Select all

  *+3.34510000E+00*
                   **
                   *+3.34510000E+00*
                   **
                   *+3.34510000E+00*
                   **
                   *+3.34510000E+00*
                   **
                   *+3.34510000E+00*
                   **
                   *+3.34410000E+00*
                   **
                   *+3.34410000E+00*
                   **
                   *+3.34410000E+00*
                   **
                   *+3.34410000E+00*
                   **
                   *+3.34510000E+00*
                   **
                
------------------
(program exited with code: 0)
[code]Press return to continue
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by mark bower »

The code used for following discussion is,

Code: Select all

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

open com "/dev/ttyUSB0:9600,e,7,2,rs,cd,ds,lf,pe" as #1 
Print #1, ":SYST:REM"                           'initialize HP meter 
sleep 500										'sleep essential
'print #1, ":SYST:BEEP;:DISP:TEXT 'HELLO WORLD'" 		'causes interference with IDN reporting
'sleep 200

print #1, "*IDN?"								'gens error -101, invalid char in cmd string
sleep 200
input #1, resp
sleep 200
print "*IDN? returned: ", resp
sleep 200
Print #1,":CONF:VOLT:DC 10,.001;:SAMP:COUN 1"  	 'initialize HP meter
sleep 200                    						'delay is essential this ln

For j = 1 to 15
    Print #1, ":READ?"							'generates error -101
    Input #1,resp 
    sleep 500
    volt = Val(resp)
    locate 3+j,1  
    print using "##.###";volt
    locate 3+j,20
    print "*" & resp & "*" 
next
I have isolated in the code lines where the problem (or at least a problem is taking place). The meter displays error code -101 when "*IDN?" (query for meter identification) is sent to the meter. The manual says this error is "An invalid character was found in the command string. You may have inserted a character such as #, $, or % in the command header or within a parameter." The HP manual says to use "*IDN?" and "READ?". The return for the *IDN command is "meter name, model, 0, firmware revisions". It should read in one line: "HEWLETT-PACKARD,34401A,0,04-01-01". After remming out the *IDN? command, the "Read?" command will also throw the same error.

Information and data is returned by these two commands, but lines may be: 1) correct, 2) incorrect, or 3) missing, as seen below. Note that some of the IDN data flows into the FOR NEXT loop, which it should not, but the total lines displayed remains at 15.

Code: Select all

*IDN? returned:             HEWLETT-PACKARD                    


%34401.000         *34401A*
 0.000             *0*
 4.000             *4-1-1*
 0.000             **
 3.868             *+3.86773020E+00*
 0.000             **
 3.867             *+3.867+3.86777600E+00*
 0.000             **
 3.868             *+3.86779890E+00*
 0.000             **
 3.868             *+3.86779890E+00*
 0.000             **
 0.000             **
 0.000             **
 0.000             **


------------------
(program exited with code: 0)
The manual also states that the string variable must contain at least 35 characters. Not sure of syntax, but added "*35" to the resp string variable.

So, at this point, I believe the problem is the sends to the meter. Please note that with the same code there are no problems with the PC talking to the meter via DB-9 to DB-9 connections.

From what I have described are there some more ideas as to what might work?
Last edited by mark bower on Jan 17, 2020 3:03, edited 1 time in total.
mark bower
Posts: 395
Joined: Dec 28, 2005 6:12
Location: arcadia, CA USA

Re: Serial Read Write From DB-9 Device Connector to PC USB

Post by mark bower »

bump for attention to my replaced text from previous post.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

HP/Agilent 34401A wrote:Baud Rate: 9600 (selectable)
Data bits: 8 (selectable)
Parity: None (selectable)
Start bits: 1 (fixed)
Stop bits: 2 (fixed)
Flow control: DTR/DSR (fixed)
Do you use the right settings ?
2 stop bits and flow control !

Joshy

edit: I found this 34401a serial interface problems
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

Post by mark bower »

Joshy - thanks for interest. I will try and respond later today or tomorrow after trying a different bit format. For some reason I have been blocked from editing so I cannot change this post and will have to enter a new one.
To repeat a bit, please do note, that: 1)I had no problems with the code when going PC serial(RS-232) to meter RS-232, 2)the problems arise trying to go through USB, and 3)with USB I can easily send a display message to the meter without problems, and 4) data and information is returned using the USB, just scrambled and missing.
Mark
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

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

Post by Imortis »

mark bower wrote:Joshy - thanks for interest. I will try and respond later today or tomorrow after trying a different bit format. For some reason I have been blocked from editing so I cannot change this post and will have to enter a new one.
...
It looks like you accidentally reported your own post when attempting to edit it. I closed the report, so I think you will be able to edit it again.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

I have several USB serial converters is yours 5V or 3.3V does it have jumpers if so your jumper setting are the right ?

Joshy
Post Reply