Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Read multi channel using XML processing

xml multichannel labjackUE9

  • Please log in to reply
13 replies to this topic

#1 Lingue

Lingue
  • Members
  • 27 posts

Posted 10 March 2014 - 02:24 AM

hi i want to read multi channel in labjack UE9 using XML processing...

how to i do first step using this process?

for example: i want read channel AIN0,AIN1,and AIN2. can anyone help this case?thankyou



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 March 2014 - 05:14 PM

On the UE9 end, the ue9Feedback and ue9allio C/C++ examples demonstrate multichannel reading:

 

https://github.com/l...er/examples/UE9

 

Using LabJackPython, you can use Modbus to read each channel as demonstrated in the Modbus quickstart (Note the tutorial works for the UE9 as well if you import the ue9 module and use the UE9 class, and AIN addresses are AIN0 = 0, AIN1 = 2, AIN2 = 4, etc.):

 

http://labjack.com/s...ckpython/modbus

 

Alternatively, you can use the feedback method from the UE9 class to read multiple AIN readings in one call.

 

XML-wise you can store reading data to an XML file and then get the data out of the XML later. For getting started with XML in general here is a tutorial:

 

http://www.w3schools.com/xml/

 

If using Python with XML look here:

 

https://wiki.python.org/moin/PythonXml

 

For other languages do a web search as there are many libraries for interacting with XML.

 

So basically you can get the readings from your UE9, save them to an XML file and read the readings from the XML file later. Is this what you had in mind? In other posts you mentioned storing reading data in a database, so a MySQL database could be an alternate solution. Also, you can look into XML based databases.



#3 Lingue

Lingue
  • Members
  • 27 posts

Posted 13 March 2014 - 04:12 AM

 

 

If using Python with XML look here:

 

https://wiki.python.org/moin/PythonXml

 

For other languages do a web search as there are many libraries for interacting with XML.

 

So basically you can get the readings from your UE9, save them to an XML file and read the readings from the XML file later. Is this what you had in mind? In other posts you mentioned storing reading data in a database, so a MySQL database could be an alternate solution. Also, you can look into XML based databases.

how to save them to an XML file?  and i can read the readings from xml file?   



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 13 March 2014 - 01:11 PM

Refer to the XML libraries documentation which should provide examples as well. Also, a web search relating to Python and XML can help as well. Here are two XML libraries documentation that were in the link's list:

 

http://docs.python.o...lementtree.html

http://docs.python.o...om.minidom.html

 

You will need to figure out how you want to structure your XML file, and then add an entry with the UE9's readings.



#5 Lingue

Lingue
  • Members
  • 27 posts

Posted 16 March 2014 - 09:13 PM

Refer to the XML libraries documentation which should provide examples as well. Also, a web search relating to Python and XML can help as well. Here are two XML libraries documentation that were in the link's list:

 

http://docs.python.o...lementtree.html

http://docs.python.o...om.minidom.html

 

You will need to figure out how you want to structure your XML file, and then add an entry with the UE9's readings.

i want to configure about reading multiple channel on ue9 and the control only on xml python . for example . i have a condition if on xml 3 i will process only 3 channel on output . if on xml 2  on output only reading 2 channel . can give me example program xml and python? i very beginner for xml processing  



#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 17 March 2014 - 12:39 PM

Here's a quick example on writing 2 channels of readings and a times tamp to an XML file:

import ue9
import time
from xml.etree import ElementTree

d = ue9.UE9()

#Using Modbus for readings. Address 0 is AIN0, 2 is AIN1, 4 is AIN2, etc..
#In this call we are are reading AIN0-1, so setting the starting address to
#0 and number of registers to 4 (AIN readings are 2 registers). For 3
#channels, set the number of registers to 6.
ain0, ain1 = d.readRegister(0, 4)
timestamp = time.time()

#XML section
readE = ElementTree.Element("readings")
dataSE = ElementTree.SubElement(readE, "data")
tsSE = ElementTree.SubElement(dataSE, "timestamp")
tsSE.text = str(timestamp)
ain0SE = ElementTree.SubElement(dataSE, "ain0")
ain0SE.text = str(ain0)
ain1SE = ElementTree.SubElement(dataSE, "ain1")
ain1SE.text = str(ain1)
tree = ElementTree.ElementTree(readE)
tree.write("file.xml", encoding='utf-8', xml_declaration=True)

Note that the above is a simple example for one set of readings, and you can format your XML data structure differently for your requirements. Beyond the above we do not provide documentation, software or examples on the XML side. If you are new to XML please look at the links I provided earlier as one is an XML tutorial and one documents ElementTree. Also, online you can find plenty of XML documentation, libraries and examples. We can help more on the UE9 and LabJackPython side of questions.



#7 Lingue

Lingue
  • Members
  • 27 posts

Posted 18 March 2014 - 02:33 AM

Here's a quick example on writing 2 channels of readings and a times tamp to an XML file:

import ue9
import time
from xml.etree import ElementTree

d = ue9.UE9()

#Using Modbus for readings. Address 0 is AIN0, 2 is AIN1, 4 is AIN2, etc..
#In this call we are are reading AIN0-1, so setting the starting address to
#0 and number of registers to 4 (AIN readings are 2 registers). For 3
#channels, set the number of registers to 6.
ain0, ain1 = d.readRegister(0, 4)
timestamp = time.time()

#XML section
readE = ElementTree.Element("readings")
dataSE = ElementTree.SubElement(readE, "data")
tsSE = ElementTree.SubElement(dataSE, "timestamp")
tsSE.text = str(timestamp)
ain0SE = ElementTree.SubElement(dataSE, "ain0")
ain0SE.text = str(ain0)
ain1SE = ElementTree.SubElement(dataSE, "ain1")
ain1SE.text = str(ain1)
tree = ElementTree.ElementTree(readE)
tree.write("file.xml", encoding='utf-8', xml_declaration=True)

Note that the above is a simple example for one set of readings, and you can format your XML data structure differently for your requirements. Beyond the above we do not provide documentation, software or examples on the XML side. If you are new to XML please look at the links I provided earlier as one is an XML tutorial and one documents ElementTree. Also, online you can find plenty of XML documentation, libraries and examples. We can help more on the UE9 and LabJackPython side of questions.

 

what a structure  xml u are using ? i can't call that program . i have nothing to show that output



#8 Lingue

Lingue
  • Members
  • 27 posts

Posted 18 March 2014 - 03:02 AM

i have the output 

<?xml version='1.0' encoding='utf-8'?>
<readings>
<data>
<timestamp>1395136534.49
</timestamp>
<ain0>4.07412481308</ain0>
<ain1>4.05905103683</ain1>
</data>
</readings>

but this is export data to xml maybe? but i mean i need to control reading channel using xml processing 

 

i mean for example 

 

suppose that i write definition variable of a = 3

then that xml can read 3 channels  . for example 3 = reading ain0,ain1,ain2

and then if i write definition variable of a = 2 

then that xml can read 2 channels . for example 2 = reading ain0 and ain1 ... and etc

 

thanks best regards



#9 Lingue

Lingue
  • Members
  • 27 posts

Posted 18 March 2014 - 03:10 AM

i have a program but this program only read . not in condition . 

import ue9
d = ue9.UE9()
from xml.dom.minidom import parse
import xml.dom.minidom
import datetime
import time


localtime = time.asctime(time.localtime(time.time()))

# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("test.xml")
collection = DOMTree.documentElement
if collection.hasAttribute("shelf"):
   print "Root element : %s" % collection.getAttribute("shelf")

# Get all the movies in the collection
channels = collection.getElementsByTagName("channel")



# Print detail of each channel.

for channel in channels:
   print "*****Labjack UE9*****"
   if channel.hasAttribute("title"):
      print "Title: %s" % channel.getAttribute("title")

   type1 = channel.getElementsByTagName('AIN0')[0]
   print "AIN0: %s " % type1.childNodes[0].data, d.readRegister(0)
   print "AIN1: %s " % type1.childNodes[0].data, d.readRegister(2)
   print "AIN2: %s " % type1.childNodes[0].data, d.readRegister(4)
   print "AIN3: %s " % type1.childNodes[0].data, d.readRegister(6)

and the xml : 

<kondisi shelf="Labjack UE9 Channel">
<channel title="Channel1">
        <AIN0>volt:</AIN0>
        <AIN1>volt:</AIN1>
        <AIN2>volt:</AIN2>
        <AIN3>volt:</AIN3>
</channel>
</kondisi>

 i have the output : 

*****Labjack UE9*****
Title: Channel1
AIN0: volt:  4.40198087692
AIN1: volt:  4.32943201065
AIN2: volt:  4.42837762833
AIN3: volt:  4.44498872757

but i need for conditioning this program . can u teach me how to conditioning this program . suppose that xml for control the program . if in this xml = 3 i can read 3channel of ain0,ain1,ain2 

if in this xml = 2 i can read 2channel of ain0,ain1 and etc...

how to do?

 

thanks best regards



#10 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 18 March 2014 - 02:54 PM

If I understand correctly, you want to specify the channels to read in the XML file, and parse that data out to perform the specific readings. Here's a modified version of your XML where the AIN elements use an "AIN" tag and the value is the channel number:

<kondisi shelf="Labjack UE9 Channel">
<channel title="Channel1">
<AIN>0</AIN>
<AIN>1</AIN>
<AIN>2</AIN>
<AIN>3</AIN>
</channel>
</kondisi>

You can parse that data and perform the specfic readings through loops:

# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("test.xml")

channels = DOMTree.getElementsByTagName("channel")

# Print detail of each channel.

for channel in channels:
    print "*****Labjack UE9*****"
    if channel.hasAttribute("title"):
        print "Title: %s" % channel.getAttribute("title")

    ains = channel.getElementsByTagName('AIN')
    for ain in ains:
        chan = int(ain.childNodes[0].data)
        print "AIN%s: %s volts" % (chan, d.readRegister(chan*2))

Alternatively here's a more simplified version where the channel element's value specifies the the number of channels to read, and the Python side reads that many channels starting at AIN0.

<kondisi shelf="Labjack UE9 Channel">
<channel title="Channel1">3</channel>
</kondisi>
# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("test.xml")

channels = DOMTree.getElementsByTagName("channel")

# Print detail of each channel.

for channel in channels:
    print "*****Labjack UE9*****"
    if channel.hasAttribute("title"):
        print "Title: %s" % channel.getAttribute("title")

    numChans = int(channels[0].childNodes[0].data)
    for chan in range(numChans):
        print "AIN%s: %s volts" % (chan, d.readRegister(chan*2))


#11 Lingue

Lingue
  • Members
  • 27 posts

Posted 19 March 2014 - 01:37 AM

 

If I understand correctly, you want to specify the channels to read in the XML file, and parse that data out to perform the specific readings. Here's a modified version of your XML where the AIN elements use an "AIN" tag and the value is the channel number:

<kondisi shelf="Labjack UE9 Channel">
<channel title="Channel1">
<AIN>0</AIN>
<AIN>1</AIN>
<AIN>2</AIN>
<AIN>3</AIN>
</channel>
</kondisi>

You can parse that data and perform the specfic readings through loops:

# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("test.xml")

channels = DOMTree.getElementsByTagName("channel")

# Print detail of each channel.

for channel in channels:
    print "*****Labjack UE9*****"
    if channel.hasAttribute("title"):
        print "Title: %s" % channel.getAttribute("title")

    ains = channel.getElementsByTagName('AIN')
    for ain in ains:
        chan = int(ain.childNodes[0].data)
        print "AIN%s: %s volts" % (chan, d.readRegister(chan*2))

Alternatively here's a more simplified version where the channel element's value specifies the the number of channels to read, and the Python side reads that many channels starting at AIN0.

<kondisi shelf="Labjack UE9 Channel">
<channel title="Channel1">3</channel>
</kondisi>
# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("test.xml")

channels = DOMTree.getElementsByTagName("channel")

# Print detail of each channel.

for channel in channels:
    print "*****Labjack UE9*****"
    if channel.hasAttribute("title"):
        print "Title: %s" % channel.getAttribute("title")

    numChans = int(channels[0].childNodes[0].data)
    for chan in range(numChans):
        print "AIN%s: %s volts" % (chan, d.readRegister(chan*2))

finnaly i got that answer thankyou lj support 



#12 Lingue

Lingue
  • Members
  • 27 posts

Posted 19 March 2014 - 02:05 AM

 

If I understand correctly, you want to specify the channels to read in the XML file, and parse that data out to perform the specific readings. Here's a modified version of your XML where the AIN elements use an "AIN" tag and the value is the channel number:

<kondisi shelf="Labjack UE9 Channel">
<channel title="Channel1">
<AIN>0</AIN>
<AIN>1</AIN>
<AIN>2</AIN>
<AIN>3</AIN>
</channel>
</kondisi>

You can parse that data and perform the specfic readings through loops:

# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("test.xml")

channels = DOMTree.getElementsByTagName("channel")

# Print detail of each channel.

for channel in channels:
    print "*****Labjack UE9*****"
    if channel.hasAttribute("title"):
        print "Title: %s" % channel.getAttribute("title")

    ains = channel.getElementsByTagName('AIN')
    for ain in ains:
        chan = int(ain.childNodes[0].data)
        print "AIN%s: %s volts" % (chan, d.readRegister(chan*2))

Alternatively here's a more simplified version where the channel element's value specifies the the number of channels to read, and the Python side reads that many channels starting at AIN0.

<kondisi shelf="Labjack UE9 Channel">
<channel title="Channel1">3</channel>
</kondisi>
# Open XML document using minidom parser
DOMTree = xml.dom.minidom.parse("test.xml")

channels = DOMTree.getElementsByTagName("channel")

# Print detail of each channel.

for channel in channels:
    print "*****Labjack UE9*****"
    if channel.hasAttribute("title"):
        print "Title: %s" % channel.getAttribute("title")

    numChans = int(channels[0].childNodes[0].data)
    for chan in range(numChans):
        print "AIN%s: %s volts" % (chan, d.readRegister(chan*2))

 

i have code for print temperature into .txt file 

f=open('tempdata.txt','a')

       
        localtime = time.asctime(time.localtime(time.time()))

        
        outstring = str(localtime)
       
        f.write(outstring)
        f.close()

but i dont know how to print into .txt with that program 

for channel in channels:
    print "*****Labjack UE9*****"
    if channel.hasAttribute("title"):
        print "Title: %s" % channel.getAttribute("title")

    numChans = int(channels[0].childNodes[0].data)
    for chan in range(numChans):
        print "AIN%s: %s volts" % (chan, d.readRegister(chan*2))

need help thankyou best regards



#13 Lingue

Lingue
  • Members
  • 27 posts

Posted 19 March 2014 - 02:40 AM

if i want control datetime same like control channel .

how to i do?

 

for example i want control datetime same like control channel if now 18.00 in this xml i write 2 and then next time is 18.02 for next row for 2nd channel

 

like          18.00  == AIN0 = 5.1023volt

and then 18.02 == AIN1  = 4.9232volt

and etc...

 

how to do like this? 

sorry for my bad grammar . best regards 



#14 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 19 March 2014 - 04:34 PM

i have code for print temperature into .txt file 
f=open('tempdata.txt','a')

       
        localtime = time.asctime(time.localtime(time.time()))

        
        outstring = str(localtime)
       
        f.write(outstring)
        f.close()

but i dont know how to print into .txt with that program 

for channel in channels:
    print "*****Labjack UE9*****"
    if channel.hasAttribute("title"):
        print "Title: %s" % channel.getAttribute("title")

    numChans = int(channels[0].childNodes[0].data)
    for chan in range(numChans):
        print "AIN%s: %s volts" % (chan, d.readRegister(chan*2))

need help thankyou best regards

 

 

I'm a bit confused by this. Your code is is writing time, but you mention you are writing temperature. Do you need to write time, or temperature from the UE9 to a file?

 

For writing to a file, you basically have most of the code. Perform the file open before the channels loop and the file close call after the channels loop. Inside the loop perform your operations such as getting the time and readings, and do the write call when you want to add text to your file, similar to printing to the screen.

 

For getting temperature from the UE9 do an AIN reading from channel 133 or 141. So a "d.readRegister(266)" or "d.readRegister(282)" call, where readings are in Kelvin. AIN channel numbers (not Modbus register addresses) are documented here:

 

http://labjack.com/s...ers-guide/2.7.1

 

 

if i want control datetime same like control channel .

how to i do?

 

for example i want control datetime same like control channel if now 18.00 in this xml i write 2 and then next time is 18.02 for next row for 2nd channel

 

like          18.00  == AIN0 = 5.1023volt

and then 18.02 == AIN1  = 4.9232volt

and etc...

 

how to do like this? 

sorry for my bad grammar . best regards 

 

In your example case, are you talking about just a defined delay between readings? For example, the 18.00 and 18.02 readings are a AIN0 reading, 0.02 delay, and a AIN1 reading. That should be easy with an XML like this, where the "AIN" child elements are the time delay before the reading ("delay") and AIN channel ("ch"):

<kondisi shelf="Labjack UE9 Channel">
    <channel title="Channel1">
        <AIN>
            <delay>0</delay>
            <ch>0</ch>
        </AIN>
        <AIN>
            <delay>2</delay>
            <ch>1</ch>
        </AIN>
    </channel>
</kondisi>

After parsing out the settings, like in my previous post's "for ain in ains:" loop though now you need to parse "delay" and "ch" element values from the "AIN" parent elements, you can use the Python call time.sleep to perform a time delay and then call readRegister for the channel reading. Note that the delay value needs to be converted to seconds for time.sleep, and the time module needs to be imported.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users