How to use PyVISA on Ubuntu to interact with a vector network analyzer? - pyvisa

Using PyVISA on an Ubuntu-operating computer (Ubuntu 20.04.5 LTS), I would like to interact with a VNA machine (E8361A, Agilent technologies) in the following way,
1- Connect to the VNA through a port.
2- Send a signal to VNA to start S-parameter measurements within a specified frequency range at specified number of points.
3- Send a signal to VNA to stop S-parameter measurement, fetch the S-parameter data, transfer the data to the PC and save the data.
Q1: Which VNA port do you recommend to use (GPIB, Ethernet or USB), and why?
Q2: Depending on the VNA port, what hardware is required to connect the PC to the VNA?
Q3: Is there a way to adjust the power level of the VNA stimulus signal? If yes, how to inquire the maximum and minimum power levels? Can the power level be adjusted continuously or only discrete power levels are avilable? (Basically, how to control VNA's internal amplifiers/attenuators?
Q4: Can you please share a sample Python code which uses PyVISA to save S-paramater data in the fashion described in steps 1--3?
Q5: Does trigger port have to do anything with sending signals to the VNA to start and stop measurements?

Since I am not working on ubuntu, nor I have the machine you have I can't say much. I am also rather new to pyVISA so my knowledge there is also limited, but since no one else answered:
Q1. I use a usb port since it is the only one I have, but the faster the better i would assume. There seems to me to be more GPIB examples found on the internet so maybe it is an easier starting point.
Q2. As with others (like mine) I would assume only a cable.
Q3. Yes, see the [write][1] function. It may look something like this:
# Connect PNA to computer using resource_manager etc., it is well documented
PNA.Write(f':SOUR{channel_num}:POW:LEV:IMM:AMPL {source_level},"{source_name}"')
For the maximum and minimum values see the documentation of your hardware.
Q4. Your 'Send a signal' I don't know how to do. But you could just while-loop and send-and-recieve in each instance until you want it to stop. Here is an example from keysight:
https://edadocs.software.keysight.com/kkbopen/a-python-programming-example-for-the-pna-family-vnas-sweep-time-various-point-counts-no-error-correction-577935568.html
Q5. I don't know.
EDIT: On Q4: I found this [link][2] , which would what I believe result in
PNA.write('SENS:SWE:MODE CONT') for continous sweeping and
PNA.write('SENS:SWE:MODE SING') for single sweeping.
In this case change from CONT to SING when appropriate and it should stop sweeping.
[1]: https://pyvisa.readthedocs.io/en/latest/_modules/pyvisa/resources/messagebased.html#MessageBasedResource.write
[2]: https://rfmw.em.keysight.com/wireless/helpfiles/89600b/webhelp/Subsystems/gui/content/mnu_control_sweep.htm

Related

Is it possible to communicate with vending machines (that uses MDB) using UART directly without using hardware adapter?

I'm building a linux-based cashless device and trying to achieve communication with VMC in vending machines over UART directly without needing additional hardware adapter to convert between 8-bit and 9-bit frame data.
I'm only using the cashless device, no intention to connect any other peripheral to the VMC.
I read questions asked about this before, some of them stressed on the need to an adapter, others suggested possible hacks to achieve the 9-bit to 8-bit conversion, but still can't find a confirmed working and stable solution.
My question is, Is it possible (and reliable) to achieve this using a pure software solution? and how?
Thanks
Yes.
The 9th bit is a control bit. It will show if the data is to be interpreted as an address or as data. If you are communicating with one device and sending only data you want to strip the 9th bit out and only look at data frames. Check and see if it's always zero:
If controlBit = 0:
ProcessData(byte)
Else:
print("This is an address: " + byte)
EDIT:
Many people have reported that your connection will not be stable without special hardware due to timing problems.
Instead of reinventing the wheel you can use opensource code as a starting point.
https://github.com/mhaqs/vendiverse/wiki/Programming-the-VMC
This way you don't have to make the same mistakes over and over again.

Measuring Multiple Voltages in LabView w/USB 6001

I'm trying to set up my LabView VI + my USB 6001 I/O box to be able to read multiple independent voltages at once, while also outputting a single constant voltage.
I've successfully gotten my USB box to output the voltage I want while reading back a single voltage, but so far I've been unable to read back more than one voltage (and if I do, the two voltages seem to be co-dependent on one another in some way).
Here's a screenshot of my VI:
Everything to the right of the screenshot window should be unimportant to the question.
If anyone is curious, this is to drive multiple LVDT's and read back their respective voltages.
Thank you all for your help!
Look at your DAQ's manual, especially the pages I noted below.
http://www.ni.com/pdf/manuals/374259a.pdf
Page 11
All the AI channels get multiplexed, and the low-side reference can be switched (RSE vs. differential). So the two channels you're sampling require both of those to switch. It might be a settling issue where the ADC is taking a sample before the input value is stable.
To verify this, try using using the same low side (differential or RSE) on both channels. Also try slowing down your sample rate (but your 1 kHz should already be slow enough...).
Page 14
Check this to make sure you have everything connected and grounded correctly.
Page 18
Check this for more details about switching between 2 sources quickly.
Perhaps you could try it using the Daqmx express VIs:
http://www.ni.com/tutorial/2744/en/

What are the general properties of a common wireless sensor node while designing a MAC protocol?

What are the properties of a wireless sensor node ?
From Omnet++ manual i came to know that
simple wirelessnode
{
gates:
input radioIn;
parameters:
...........
}
Though the node have only input gate , how it sending data to other node?
if the node is wireless how the sensor node connected ?
How to define a region around a wireless sensor node for reach another node in range?
Thanks
For sending, you can think with a DODAG : take a tree, put the root as the gate. The gate gathers the data of its children, each of those children gathring themselves the data of their children ... the leaves are the nodes that need the more hops to be reached from the root.
Here you would need, among others : the power of the transmitting, the power of the receiving chip (so that if the sending node is too far away then the receiving node won't catch its frame for example, as pointed by user4786271), a protocol to route them (so that if a node has 2 other nodes in range of rank n-1, to know which one it will use).
Try to dig into some open source WSN simulators implementing protocols, you could get a lot of info. For example : https://bitbucket.org/6tisch/simulator/src
To answer your exact question, there is no such thing like "general properties" for a given module when designing a protocol.
Usually the decision of the module properties that you are going to use, is strongly related to what that node is supposed to do as part of your protocol.
If your node is never going to communicate, there is no point in adding a gate to it.
Though the node have only input gate , how it sending data to other
node?
You don't have to strictly adhere to the design that you have seen. Maybe in that case the nodes only need to receive messages. In your case you might want to define an output gate.
if the node is wireless how the sensor node connected ?
Do not view the gates as physical entities, but rather as interfaces which are capable of communicating through links. Do you see a cable link between your mobile phone and the basestation? Probably not, because they are connected through a wireless link. So your mobile phone has an interface for wireless link. See where I am going? In your case you will need a gate with wireless link.
How to define a region around a wireless sensor node for reach another
node in range?
Hmm, based on your propagation model the received signal power will depend on the distance, right? You can check the received power for the MAC frame and dismiss it if it is below a given threshold.
Or, if you work on the application layer -- which you don't -- you can embed location information in your packets and then perform pairwise distance comparison to decide packets from which sender to consider or drop.

how to prove working of RS 232 full modem,RS 422 working PC to PC and LOOP BACK

Hello there I am a newbie trying to prove the working of RS 232 Full modem and also one RS 422( RX,TX,RTS,CTS)
These 2 ports are on a custom designed board and I need to prove they are working.
I am able to confirm the working at register level but I need to prove the working using softwares like Minicom or any other custom program.
How can I prove the working of these ports from one PC to a different PC using DB 9 connections and LOOP BACK too
Can someone help me with this? Do I need to use any extra hardware to prove the working of this in Linux?
The most common type of serial port test is probably a loopback test. Create a test fixture that connects output pins of the port to the input pins (TX->RX, RTS->CTS, etc). If you do not have matching input pins for every output pin, you will need to do a three-way connection.
After you create the loopback, you will need to write software that exercises the pins. If TX and RX are connected, you can send a byte and verify that it was echoed back. For the control pins, toggle them and make sure the other side of the connection saw the transition. Make sure you exercise every pin of the serial port.
Note that you should run a TX->RX data loopback at multiple baud rates. It is possible for there to be a signal integrity issue in the design that only shows up at higher bauds rates. It is also possible for there to be a bad signal connection on the board that is masked by inductance and capacitance at higher baud rates. Therefore, it is a good idea to run a data loopback at the slowest baud rate, the fastest baud rate, and 1-2 in the middle.
Another thing you should do is a baud rate accuracy test. This will prove the clock driving the UART is running at the right frequency, and being divided properly. Transmit X amount of bytes at a certain baud rate and verify they arrived in the expected amount of time. To get an accurate number, you will need to bypass any buffering in the OS serial port driver (e.g. use direct register I/O), and make sure to accommodate for any start/stop bit overhead (see comments below).
However, a loopback test is not exhaustive. It only proves the device can talk to itself. The device may still have some flaw (e.g. voltage levels) that cannot be detected locally. So, you should also run some tests with external hardware. Cable your board to another system and run a test (e.g. with minicom). Make sure they can talk to each other.
Even an external communication test can miss something. You can still have poor signal quality from your board, but it happens to be good enough for the other device. To accurately verify the signal quality/timing, you need an oscilloscope.
While you are running communication tests, connect the scope probes to the various signals and verify the signal integrity. Make sure that voltage levels are valid, that you see clean low/high bit transitions, and that the timing of the data pin appears correct for the specified baud rate. (A scope can be a more accurate way to measure baud rate than the software-based method described earlier.)

What would be the simplest way to interface custom hardware with one input to have switch somewhere in /proc?

I have a device that takes low current 3-12v input signal to do it's magic and I would like to interface it to my linux box. What kind of options do I have on this? It would be great to have some low-cost possibly user-space solution.
If I understand right, you need to control your box by changing 3-12v input signals to it. Here's the choices I can think of from the top of my head:-
a: Using RS232 serial handshake lines. RTS/CTS can usually controlled programatically as "on/off" signals without driver development using IOCTL calls.
b: Use a "GPI dongle" such as the Advantech ADAM range. These typically take serial or TCP/IP inputs and convert them to suitable output signals.
c: You may be able to do something with a parallel printer port if your PC stil has such a thing.
As shodanex says, be aware that RS232 levels are NOT directly compatible with TTL/CMOS inputs so you may need some minor level shifting/clamping electronics to fix this.

Resources