lee
New Member
Posts: 5
|
Post by lee on May 20, 2019 16:11:23 GMT -5
I want to use LB to communicate with an HP Digital Volt Meter to take Voltage readings and report values via RS232. I can talk to the DVM to set it up for readings but it never comes back with a value. I can see the DVM getting set up and take a reading with the value on its screen. At that time DSR is not set high by the PC so the DVM will not send the reading.
I can use this same DVM and null modem cable with another program to make readings. In this situation the PC sets DSR high for the DVM to send the value. So I know that the cable and DVM can do what I want.
This is the LB code I am using:
open "com6:9600,n,8,2,rs,cd0,ds0,cs,LF" for random as #1 print #1, ":SYST:REM" ' Configure the multimeter for ac voltage readings, ' 1 V range, 0.0001 V resolution, 1 reading PRINT #1, ":CONF:VOLT:AC 1,0.0001;:SAMP:COUN 1" ' Trigger the readings, and fetch the results PRINT #1, ":READ?" resp$=input$ (#1, lof(#1)) PRINT ":READ? returned: ", resp$ close #1
There must be something I am not setting correctly.
Lee
|
|
|
Post by Rod on May 23, 2019 3:51:52 GMT -5
I missed this post. Couple of things, first off use the standard Liberty phrase for opening the port. DSR is I believe the signal from the remote device to say the data is ready. DTR is the signal from the PC to tell the remote device the PC is ready. With the standard phrase liberty ignores all these handshakes and just gets on with job.
Second point is that it will take time to read,process and transmit the data. It will not appear instantly in the buffer. But you may be using the debugger and giving it time to respond.
If we do need to alter DTR etc it can be done. I will post a link and a bit more detail when I get to my pc.
|
|
|
Post by Rod on May 23, 2019 4:16:56 GMT -5
Ok this is the standard phrase open "com2:9600,n,8,1,ds0,cs0,rs" for random as #1 This is a link to the LBPE article that discusses serial messaging. Look at the Handshaking paragraph, later it shows how to set and reset the handshaking lines. The DSR line is controlled by the remote device, it is more likely DTR that needs changed. But try the standard phrase and a delay before reading the buffer.
|
|
lee
New Member
Posts: 5
|
Post by lee on May 24, 2019 22:08:10 GMT -5
I did try the standard phrase at the start. I had read the help under OPEN "COMn:...". I also have "INPUT a$" in between some lines to allow time for reading and processing. I also have the Carl Gundel book but haven't found anything on OPEN COMn. I am using a null modem cable with DTR and DSR interchanged. The LED indicator I use is on the Volt Meter end. It would be DTR on the PC end. The Volt Meter manual says it uses DSR and DTR for handshaking. The line with the label DSR comes from the PC and is low when the Volt Meter data is ready to send.
I have disconnected the DTR line from the PC and wired the RTS line from the PC to the disconnected DSR line at the Volt Meter to see if that was the reason for the hold up. It worked but I would rather not solve the issue this way.
In the LBPE article, I see "Liberty can set and reset these lines. RTS is on by default, DTR is not. If you have a device that refuses to work with Liberty BASIC, DTR may need set on.". I am studying the section under 'Obtaining the serial port #handle". I will see what I can do with setting the handshake line ON/OFF.
Thanks so much for your help!
|
|
lee
New Member
Posts: 5
|
Post by lee on May 29, 2019 16:38:19 GMT -5
I did get the port talking both directions. Thanks!
The response coming back is in the form +4.56754E-2. I would like to do a PRINT USING "#.#####";+4.56754E-2 but can't find a way to get it to work like Quick Basic.
Is there a way to print using specific Formats?
|
|
lee
New Member
Posts: 5
|
Post by lee on May 29, 2019 16:49:55 GMT -5
I now see it under USING( ).
|
|
|
Post by tenochtitlanuk on May 30, 2019 15:29:52 GMT -5
Yes.. 'if you have the returned data as a NUMBER print using( "#.#####", 0 +4.56754E-2) ' it doesn't like the + sign on its own.. so strip it off or do as here..
'if received as a string, r$ ="+4.56754E-2" print using( "#.#####", val( r$))
|
|
|
Post by arsk3bpp on Mar 24, 2023 10:54:12 GMT -5
Hi Lee and the group I was glad to read your posts, I am sort of trying to do the same thing with a Radio Shack 22-168 multimeter with an RS232 output port. So far all attempts have failed as well as the loopback from the article "Accessing the Serial Port". All failed attempts seem to be because the DTR pin is not high. I have 2 working loopback programs that work fine ( python and putty ) both of which have DTR high. All of the articles that I have seen on setting the DTR are quite long. My Python loopback program is about 10 lines long see below import time import serial ser=serial.Serial(port="com4",baudrate=1200,bytesize=8,timeout=2,stopbits=1) while True: ser.write("ABCDE") receive=ser.readline() print(receive) time.sleep(1) ser.close() So all in all I am curious as to how you set DTR High. These Liberty Basic fourms are jus fantastic !!
|
|
|
Post by arsk3bpp on Mar 24, 2023 18:49:13 GMT -5
Hi I have set the DTR to high in the loopback program program posterd by Rod Bird still does not work.
|
|
|
Post by Rod on Mar 25, 2023 2:52:12 GMT -5
Have you found this? www.linuxtoys.org/dvm/dvm.htmlThis from another forum, in case it goes awal the key issue seems to be that DTR needs set high and RTS needs set low. Both by the pc which then powers the rs232 interface no doubt providing opto isolation. Introduction Protocol C Program An Application Introduction
Picture of the DMM The "Micronta LCD Digital Multimeter" is a fairly nice 3 1/2 digit multimeter (DMM) with an RS-232 output to report the readings. The older unit (pictured) has part number 22-182 and the newer unit has part number 22-168. The catalog list price is $129.99 but it goes on sale for $100 or $110 once in a while. The older DMM features : DC Voltage: 0.1 mV to 1000 V AC Voltage: 0.1 mV to 750 V DC Current: 0.001 mA to 20 A AC Current: 0.001 mA to 20 A Resistance: 0.1 ohm to 20 Mohm Frequency: 10 Hz to 200 kHz Capacitance: 1 pF to 20 uF Transistor Gain: 0-1000 hFE Continuity Checker
Picture of the cable The DMM has a 5 pin in-line connector for the RS-232 output. A supplied cable has the mating 5 pin plug on one end and a female 9 pin D connector on the other end. The cable is configured as a DCE so it can plug directly into a PC serial port. Other DMMs with RS-232 are available. Jameco catalog #942 lists four of them; one by Protek and three by Metex. The Techni-Tool catalog #58 lists an Extech DMM which has a serial interface.
Protocol
It looks like the DMM uses RTS and DTR to power the serial port. DTR needs to be set to +12 volts and RTS must be set to -12 volts. The port should be configured for 7 data bits, no parity, and two stop bits (7,N,2) at 1200 baud. Take a reading by sending a "D" character to the DMM and then read characters from the serial port until a carriage return is found. The format of the returned data is a 13 character line terminated by a carriage return. Byte) 12345678901234 Ex.1) DC-1.9999 V CR Ex.2) 1.9999MohmCR
C Program
The following C program takes a reading every 60 seconds.
/* * Name: dvm * * Description: * A simple program to read a value from the Radio Shack * digital multimeter every 60 seconds. * * Example: * dvm /dev/tty02 > readings * */
#include <stdio.h> #include <termio.h> #include <sys/fcntl.h> #include <unistd.h> #include <sys/ioctl.h>
int main (int argc, char *argv[]) { int m; /* modem control lines */ int fd_dev; /* FD for the open serial port */ char c; /* char received from the DMM */ struct termios tbuf; /* serial line settings */
if (argc != 2) { printf("Usage: %s [tty port]\n", argv[0]); exit(1); }
if (( fd_dev = open(argv[1], O_RDWR, 0)) < 0 ) { printf("Unable to open tty port specified\n"); exit(1); }
/* set up the line parameters : 7,2,N */ tbuf.c_cflag = CS7|CREAD|CSTOPB|B1200|CLOCAL; tbuf.c_iflag = IGNBRK; tbuf.c_oflag = 0; tbuf.c_lflag = 0; tbuf.c_cc[VMIN] = 1; /* character-by-character input */ tbuf.c_cc[VTIME]= 0; /* no delay waiting for characters */ if (tcsetattr(fd_dev, TCSANOW, &tbuf) < 0) { printf("%s: Unable to set device '%s' parameters\n",argv[0], argv[1]); exit(1); }
/* Set DTR (to +12 volts) */ m = TIOCM_DTR; if (ioctl(fd_dev, TIOCMSET, &m) < 0) { printf("%s: Unable to set '%s' modem status\n",argv[0], argv[1]); exit(1); }
while (1) { write(fd_dev,"D", 1); do { read(fd_dev, &c, 1); write(1, &c, 1); } while (c != '\r'); write(1, "\n", 1); sleep(60); } /* This program is rude in that it does not restore the */ /* serial line parameters on exit. */
exit(0); }
An Application
Renewal Discharge Curve We use the Radio Shack DMM and the above program to measure the discharge curves for several AAA batteries. We tested two batteries in series with a load of 33 ohms. The batteries tested include Energizer, Duracell, Radio Shack, and Renewal. We use various Linux tools to format the data and we use gnuplot to build the actual plot images. Click Energizer or Duracell ? for the full report.
|
|
|
Post by Rod on Mar 25, 2023 4:39:39 GMT -5
I dug out my serial tests set and fired it up, never been used on my current Win 11 PC but it opened the port without issue. I am using a USB to Serial converter. I set up for loop back and the code sent and received "Hello". If I break the loopback I don't get any message back. Loopback does not care about DTR or RTS. I did add a close statement in case that is causing an issue.
I will repeat this, if you just Run this program it will not work. You must use the ladybug icon and then the single arrow to step through the program. This gives the necessary time delays for the serial port to establish, send the message and read the receive buffer once it has actually been filled.
open "com3:9600,n,8,1,ds0,cs0,rs" for random as #commHandle print #commHandle, "Hello" dataRead$ = input$(#commHandle, 7) print dataRead$ close #commHandle
I doubt my USB to serial converter is outputting + and - 12Volts. It is probably running at + and - 5 Volts which is the USB voltage. That is ok for short cable runs but may be an issue for your voltmeter if it needs + and - 12 volts to function. If that is an issue you could just supply those voltages separately to the units DTR and RTS lines.
|
|
|
Post by arsk3bpp on Mar 25, 2023 7:02:54 GMT -5
Hi Rod Thanks so much for all of the attention. I am familer with the C program for the RS 22-168. I would love to get a LB program to do the same. I have Dev C++ on my machine and am about ready to try the C prog. The loopback, I hard wied the dtr to dsr line so now dtr goes high when prog is run. I put in a delay so as to have more time to watch the led's. The rts stays off. Have not figured out how to get negative voltage to rts. Program does not make it to print #commHandle, "Hello".
open "com4:1200,n,7,1,ds0,cs0,rs" for random as #commHandle for w=1 to 10000 print w next w print #commHandle, "Hello" dataRead$ = input$(#commHandle, 7) print dataRead$ close #commHandle Short of sending rts negative , I am wondering if I might have a corupt LB 4.5.1 Best Regards K#BPP Walt
|
|
|
Post by Rod on Mar 25, 2023 9:41:16 GMT -5
Ok if we are focused on loop back it should be really simple. First of remove all the DTR, RTS cables and just link pins 2 and 3 , Tx and Rx directly on PC side usb Serial db9 socket. Nothing else needs connected. They share a common ground. Run this code and tell me how you get on. You can run the following code but be sure you have the com port number set to the correct number for your PC. Use windowsKey+x then device manager then com ports to see what number Windows has assigned the usb serial interface.
print "attempting to open com port" open "com3:1200,n,7,1,ds0,cs0,rs" for random as #commHandle call pause 2000 print "Port open, sending hello message to output buffer" print #commHandle, "Hello" print "hello message sent" call pause 1000 print "attempting to read input buffer" dataRead$ = input$(#commHandle, 7) print "input buffer contains ";dataRead$ print "closing port" close #commHandle print "program ends" wait
sub pause ms timer ms,[pause] wait
[pause] timer 0 end sub
Loopback does not need DTR or RTS or any other handshaking line connected. The switches that we use in the open statement ensure no handshaking is required. So you should have one wire linking pins 2 and 3.
If this works and we move on to the meter the RTS -12v is obtained by setting RTS low. Low means -12v and high means +12v, actually + and - 15 volts by the rs232 spec. If your meter is working with these other languages we should not have any issues getting Liberty to speak to it.
|
|
|
Post by arsk3bpp on Mar 31, 2023 11:36:59 GMT -5
Hi Rod I have not bothered you in a few days but wondering if any one has got the basic program in the RS 22-168 manual (7 line basic prog ) to work. I have had no luck. On a positive note I discovered a working program for the RS 22-168 which produces a digital display of of multimeter reading and a long time base graph. www.uwe-sieber.de/english.html look for MSCOPE This worked a few time then got error 5 on com 4. something in the software does not close when it is supposed to. Closing all related files in task manage does not help. Best Regards Walt K3BPP
|
|
|
Post by Rod on Mar 31, 2023 11:58:30 GMT -5
We need to start a new thread. You need to tell us what works and what does not. So you have a voltmeter make,model, number. You have a usb to serial module, make, model, number. The usb serial module plugs in and provides a serial port usually numbered com?
When you plug in the voltmeter lead what happens, nothing?
We need to set RTS low and DTR high, still nothing?
If you send a message does it go or does it stay on the output buffer? txcount()
Does the input buffer ever contain anything lof(#comport)
|
|