Wednesday, November 18, 2015

Remote control over LAN using Pyvisa

1. Getting the IP address of the instruments
a. Setting the IP addresses yourself: Most instruments will come with a pre-set IP address. You will need to change it for security reasons, or if you have multiple instruments of the same type, or if you want your own intranet. If you are setting up the intranet, use ipconfig command/ network properties menu on Windows to get the Gateway and Subnet mask. While each device on intranet will have a different IP address, they will share the Gateway and subnet masks. If you will be assigning the IP address to the instruments, you want DHCP = OFF.
b. Read from the instrument
c. Using NI MAX
NI MAX --> My System --> Network Devices --> right click to see Create new VISA TCP/IP resource --> Auto detect of LAN instrument

I used a Chroma DC electronic load, assigned IP address etc. While I could ping it, it did not show up on the NI MAX autodetect. Turns out I needed raw socket (the instrument uses fixed port number).
NI MAX --> My System --> Network Devices --> cright click to see Create new VISA TCP/IP resource --> Manual entry of raw socket --> enter hostname==IP address, port number.

2. Creating a handle for the resource
A. Instruments that do not need a port number
Once NI MAX detected the resources, I could see them on rm.list_resources(). The address is of the type  TCPIP0::<ip_addr>::inst0::INSTR

Open the resource using:
import visa
rm = visa.ResourceManager()
 <handle_name> = rm.open_resource('TCPIP::<ip_addr>::INSTR)
Use <handle_name>.write(<command_string>) and <handle_name>.ask(<command_string>).

B. Instruments that need a fixed port number for Ethernet connection
For the Chroma Load, the address is of the type TCPIP0::<ip_addr>::<port_number>::SOCKET.
Method1: Using NI MAX
Open visa test panel
Configuration --> I/O settings  --> select termination character as per instrument requirements (else you will get timeout on read)
The user manual for Chroma asked to set the termination character to '\n' before reading/ writing to the instrument.
Next go to Input/ Output tab, and write commands. Then send read command and read returned value.
If you do not set the read termination character in NI MAX, then you can still visually read the returned data in its window, but the read operation will timeout.

Method2: Using visa
import visa
rm = visa.ResourceManager()
<handle_name> = rm.open_resource('TCPIP0::<ip_addr>::<port_number>::SOCKET)
<handle_name>.read_termination = '\n'
<handle_name>.ask('*IDN?')
u'CHROMA,63600-5,636005001078,1.61'

If you do not set the read_termination character, then you will get the following errors:
>>> ld1.ask('*IDN?')
Traceback (most recent call last):
VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

Method3: Using socket
import socket as sock
<handle_name> = sock.socket(sock.AF_INET, sock.SOCK_STREAM)
<handle_name>.connect((<ip_addr>, <port_number>))
To send command: <handle_name>.send(<string_command_ending_with_\n>)
To read data: <handle_name>.recv(<give_a_buffer_size>)

Example:
import socket as sock
self.load = sock.socket(sock.AF_INET, sock.SOCK_STREAM)
self.load_addr = str(load_addr)
self.load.connect((self.load_addr, port_number))
self.load.send('*IDN?\n')
self.load.recv(256)

I prefer Method 2, because once read_termination is set, you can use write and ask commands normally.

References:
1. pyvisa tutorial
2.  read termination
3. socket code
4. Another socket code, with telnet (I havent tried this) 

Monday, November 16, 2015

स-ला-ते, स-ला-ना-ते

माझ्या मित्राने माझ्या घरचा दूरध्वनी क्रमांक "दीपिकेची आजी" या नावाने लिहिला होता. त्यावरून आमचे "दीपिकेची" शब्दप्रयोग बरोबर की "दीपिकाची" शब्दप्रयोग योग्य यावर चर्चा झाली. त्याच्या मताप्रमाणे आपण "सीतेचे", "कौसल्येचा", "राधेच्या" असे शब्द वापरतो तर दीपिकेची असं का म्हणू नये. त्यावर मी म्हटले की या सर्व स्त्रिया देवी  अथवा पूजनीय स्त्रिया आहेत, तर कदाचित त्यांची नावे वेगळ्या रीतीने घेतली जात असावीत. खरं तर संस्कृत ही मराठीची जननी आणि संस्कृत मध्ये देवी आणि सामान्य स्त्रियांमध्ये व्याकरणाच्या दृष्टीने भेदभाव केला जात नाही. मग मराठीत असे काही आहे का याचा शोध चालू आहे. संदर्भ म्हणून आरत्या अथवा जुनी गाणी (म्हणजे गीतकार मराठीचा/च्या खंदा माहितगार असतील असे मानून) ग्राह्य धरली जातील. लगेच मनात "मायेच्या हळव्या" गाणे आले, पण येथे माया हे मुलीचे नाव या अर्थी नसून abstract noun आहे. देवी नसलेल्या मुलीचे नाव असलेले गाणे म्हणून चटकन "अश्विनी ये ना" च आठवतंय. एरव्ही गाण्यांत प्रिये, सखे असे आपुलकीचे शब्द असलेली बरीच गाणी आढळून येतात.

बरं सारख्या अर्थाच्या शब्दांमध्ये पण दोन्ही प्रयोग दिसतात, "गंगाजल" Vs "कऱ्हेचे पाणी" म्हणजे संधी झाली तरी प्रयोग बदलतोय. "गंगेकाठी" Vs "कृष्णाकाठ" यात निव्वळ ज्या शब्दाशी संधी झाली त्या शब्दाची case बदलली तरी प्रयोग बदलतोय.

विचार करता करता लक्षात आलं की ही सापत्न वागणूक देव्यांनाच नाही तर देवांना आणि संतांना देखील लागू होते. "कबीराचे" शेले, "रामाच्या" राज्यात, "राधा कृष्णावरी भाळली".. देवांचं नाव "अ"कारांत असलं तरी त्यांना प्रत्यय लावताना त्यांच्या नावाचा "आ"कारांत होतो.

त्याहून पुढे जायचं तर हीच प्रथा आपण निर्जीव गोष्टींना देखील लागू केली आहे. दारची तुळस, मात्र दाराची कडी. एखादी गोष्ट सोपी असली की ती जणू "हातचा मळ", पण गप्प बसताना मात्र "हाताची घडी" तोंडावर बोट. थोडक्यात काय तर मनात आपुलकी असली की ती भाषेत उतरते. मग असं असेल तर मित्राने "दीपिकेची आजी" म्हणलं तर मी त्याच्या व्याकरणाच्या चुका न काढता त्याचा जिव्हाळा समजून घ्यावा हेच श्रेयस्कर.

 वाचकांनी देखील ह्या कार्यात सहाय्य करावे… मंडळ आभारी आहे :)

References:
१. स्वयंवर झाले सीतेचे, गीतरामायण
२. कबीराचे विणतो शेले कौसल्येचा राम
३. "राधा अंजिरी साडी ल्याली, रंग गुलाबी राधेच्या गाली" ही आजी गाते त्या गाण्यातली एक ओळ
४. "कऱ्हेचे पाणी", प्र.के. अत्रे
५. "गंगेकाठी घर हे अपुले", कल्पवृक्ष कन्येसाठी गाण्यातली ओळ
६. "कृष्णाकाठ", यशवंतराव चव्हाण

दीपिका विद्याधर रानडे
title (वि)भक्ती द्यावं असा मानस आहे

Saturday, November 14, 2015

Random ramblings

Some thoughts too lengthy for Facebook post and too short for their own blog entry:

A few observations about the things I like in other blogs/ articles.
1. Don't have too many pictures: These days I almost exclusively use smartphone, and something with a lot of pictures takes forever to load. And most of the times the pictures aren't even original, just something from stockpile. Yahoo is a major culprit here. I have to scroll through 10 slides to read 10 lines: Its a  major time waste.
A good article is concise, and doesn't beat around the bush.
Antithesis of the above: If its a DIY article, I like the ones which really go down to the basics. I went to a woodworking studio recently, and to put it in their words: The instruction is targeted for: "Haven't touched wood before" audience. Most of the times the readers don't know a thing about it. That's why we are reading the article in the 1st place.


An important lesson learnt - do not use Flouride based mouth rinse in the morning.. it messes up your taste buds the whole day!
A typical weekend started with waking up at Noon, and then attempts to find a restaurant close by for the brunch. I settled with a Middle eastern cuisine one and chose a grape-leaf thingy on the menu. Remember those grocery-store-wallahs who used to give a chocolate instead of returning the 25 paise? Small shops here take it to a new level - pay only cash unless the bill is > 10$. Good way to get people to eat a dessert or 2 to make it to 10$. Anyway, so this mid-day sunny walk left me n my roomy tired so it was time for a homemade limbu sarbat. Btw my roomy has never heard of a limbu sarbat before!!! So it was up to me to advertise the oh-so-great concoction. But thanks to the FMR, I could not even guess whether the white powder in that glass बरणी is sugar or not, nor could I tell whether the lemon tastes sour or not.



The founding fathers of the Indian Constitutions were aware that the American constitution asked that the head of government be native-born, yet such a clause doesn't exist in the Indian constitution.
Lol 1. Native born americans were American Indians, and none has been the US President.
Lol 2. who knows if when the US constitution was written, masses were already flowing into the US, and then it would make sense to add the clause.
Lol 3. Indian constitution can be ammended to reflect the changing times. At the time of writing the constitution, the winds of "swa-raj" were blowing, and the constitution-makers might have thought that the Indians would never again accept a foreign ruler. Possibly they under-estimated the Indian attraction for "gori chamdi", or dynasty trends.



As an active gator, I had heard of OAR, but never took it seriously till a few other Indian kids went on an OAR trip to the Carribs. I went to an OAR meeting and the next trip they were planning was to meet the rainbow people in Ocala National forest. I googled the rainbow people after returning home, and that sounded highly hippie-ish to me, plus the website "proudly" proclaimed that they have no regard for laws. (I had recently seen Martha Mary Marcy Marlene movie that time, and the commune concept freaked me out!!).  Two years later, while searching for "Things to do in Florida", I stumble upon a community that stays in tree houses. People can rent those tree houses and stay with the community for a few days to learn their way of sustainable life. While this sounds interesting, and I dream of staying in a tree house, staying with a commune and having my car parked a mile away from me scared me, and I decide to give it a pass. Fast forward two more years later, my colleague is going to the Burning Man festival and I am piqued enough to consider giving it a try in the future.

Review of Hemalkasa movie

Baba Amte is my hero. Swar Sudha shows marathi movies in California, and one of the movies I saw was Hemalkasa (Hindi version of Dr Prakash Baba Amte).

The movie starts with Nana Patekar emerging out of the river with a very CGI tiger. This might have worked if there were no other animals in the movie. But since there were 2 leopards, multiple monkeys, a bear, multiple snakes, one wonders why couldnt they have used a real leopard instead of the CGI tiger. The movie plot is Nana reminiscing about his life while he is at an award function in the US. Right from the start, the character of Mandatai Apte is portrayed as a weak-spirited, almost stupid woman. To innumerate a few instances:
1. She is checking out the hotel suite and accidently turns on a shower. While this scene is apparently in place for a romantic moment, it comes off as very misogynist. While there is a small possibility that such a thing might actually have happened in their lives, what was the point of involving it in a movie? Did they want to portray that the Amtes have been so dedicated to grassroots that they are unaware of western conveniences? If so, there were better opportunities to do that.
(Also, the hotels that I have been to, there is no way that your hand touches the shower faucet accidentally and it spurts all over you. Maybe the Amtes were put up in a ultra-futuristic hotel with highly touch-sensitive faucets?)

2. Mandatai is shown to be a Anesthesia resident when Dr Amte meets Mandatai. Infact she is so skilled in surgery that while Dr Amte is the surgery resident, Mandatai performs the surgery. Later in the movie, Mandatai asks Dr Amte to touch a child and confirm that it has fever. Then she asks him what should she do, and Dr Amte says to give the child paracetamol. Really director? Did you know that a MBBS doctor is academically trained in almost all fields of medicine?  Not only that, but the MBBS course also involves clinical residency rotations? Did you bother to fact check?

3. Dr Amtes beloved leopard is dying of snakebite and Mandatai informs Dr Amte that she injected the antivenin but the leopard is not responding to the anti-venin. Dr Amte then has to verify the quantity of anti-venin that she has injected. Sure this is something that must be regularly happening when one doctor takes over from another, but going with the overall chauvinism elsewhere in the movie, this scene did not sit well. 

In reality, the altruistic task of Dr Amtes would not have even started, let alone bear fruition without Mandatai.

4. Also talking about fact checking, in the movie they say that Dr Amte was in his last year of MBBS when Baba Amte took the younger Amtes to Hemalkasa during their medical school break. Later he gets married, and then he moves to Hemalkasa. I assumed that he had completed the last year of his MBBS in the meantime. Later in the movie, Dr Amte says government sent him a "love letter" because he is performing surgeries. Again, just for the information, the full form of MBBS is Bachelor of Medicine and bachelor of Surgery. If he indeed completed his MBBS, not only is he qualified to practise, he is also qualified to perform surgeries. It was not clear in the movie why was the government not happy about him practising.

5. In the scene when Dr Amte performs eye surgery on an old woman, he says he is required to perform the surgery because opthalmologists wont come to Hemalkasa and the woman cannot afford to go to Nagpur. Few scenes later, they show that they had atleast an occasional medical Ambulance ferrying patients between Hemalkasa and the better equipped Anandvan.

6. After a course of some years, only Dr Amte and no one else from his team can decipher the Adivasi language.

7. One of Dr Amte's accomplices starts teaching the kids. His alphabet and the words that he uses are foreign to the kids. (When, as kids, we were taught English == a language that was not our mother tongue, the inital objects were identified by pictures.) The camera pans over kids doing kiddy stuff like being unruly or picking their nose. Instead of acknowledging his incompetency at teaching, the accomplice makes a comment that the kids have no brains. Crass humour.

Nana Patekar shines in his portrayal of Dr Amte. Few scenes here and there do show that the director might be talented. For instance, after Dr Amte's beloved leopard Negal dies, the Amtes plant a tree at the spot where the leopard is buried. Nana later walks past the tree and nuzzles the tree. Another scene thoroughly enjoyed by the movie-goers in California was when Dr Amte cooks for his brother when his wife is not at home.

To summarize, the task undertaken by the Amtes is beyond doubt unparallelled. The movie could have done better justice to the Amtes.