It had been so long since I got serious with awk that I forgot about the rather odd semantics of writing to files. This works with the Twilight-Logic GPIB board on Debian 9.3. I spent a long time chasing my tail before I remembered the weird bit about needing to close files so that they get reopened. Otherwise you get the same value every time even though it has changed. A pipe has the same semantics.
#!/usr/bin/nawk -f
BEGIN{
system( "stty 9600 </dev/ttyUSB0" );
system( "stty 115200 </dev/ttyUSB1" );
for(;;){
system( "/bin/date +%s >/tmp/a");
system( "/usr/bin/head -1 /dev/ttyUSB0 >>/tmp/a");
getline sec <"/tmp/a";
getline th <"/tmp/a";
sub(/\r/ ,"" ,th );
close("/tmp/a");
print "++addr 10" > "/dev/ttyUSB1";
print "read?" > "/dev/ttyUSB1";
getline dmm10 < "/dev/ttyUSB1" ;
print "++addr 22" > "/dev/ttyUSB1";
print "read?" > "/dev/ttyUSB1";
getline dmm22 < "/dev/ttyUSB1" ;
printf( "%s,%s," ,sec ,th);
printf( "%s,%s\n" ,dmm10 ,dmm22);
}
}
the output looks like this:
rhb@Debian-9:~/wrk/cal-club/34401A$ ./tst2
1563661854,24.691,48.824,+1.00001120E+01,+9.99993960E+00
1563661858,24.722,48.824,+1.00001160E+01,+9.99993840E+00
1563661862,24.735,48.811,+1.00001110E+01,+9.99994090E+00
1563661866,24.722,48.827,+1.00001140E+01,+9.99994460E+00
1563661870,24.717,48.849,+1.00001160E+01,+9.99994090E+00
1563661873,24.699,48.853,+1.00001170E+01,+9.99994330E+00
1563661877,24.685,48.859,+1.00001170E+01,+9.99994090E+00
1563661881,24.662,48.863,+1.00001170E+01,+9.99994210E+00
The first value is the time in seconds from the start of the Unix epoch. I'm using the Uno I hacked rather than the one that came with the kit. I've been careful not to modify it.
I need to get a bunch of FTDI USB-Serial adapters for reading data from DMMs and save the GPIB for other instruments.
I notice that the GPIB-USB interface is returning 8 digits. Can anyone shed light on that? It appears to be the string returned by the 34401A.
Many thanks to all, but especially to cellularmitosis, vindoline and TiN for making this possible.
After 4 straight hours of tearing my hair out I'm going to take a break. But with modest luck I should be able to test my 4 DMMs, do differential tests with the references from Doug Malone and get the kit back in the mail on Wednesday.
Once it's in the post I'll write up the scripts and stuff. My sister is very proficient at making booklets on the computer, so I'm going to sit down with her and show her what to include from bitseekers links. I'm sure we can do better, but it will be a start.
Reg